dgollahon / rspectre

Exorcise the apparitions haunting your tests.
MIT License
74 stars 9 forks source link

Check for unused stubs #16

Open bquorning opened 7 years ago

bquorning commented 7 years ago

Today, I used rspectre to remove 250 unused lines from our spec suite. So: Thank you!

Quite a few of these removed lets were actually still being referenced in blocks in unused stubs, such as:

let(:baz) { "never used" }
before do
  allow(foo).to receive(:bar) { baz } # foo.bar is never called.
end

Would it be possible for rspectre to also check for unused stubs, or it that a job for another tool?

dgollahon commented 7 years ago

Today, I used rspectre to remove 250 unused lines from our spec suite. So: Thank you!

Awesome! Glad it was helpful. :D

Would it be possible for rspectre to also check for unused stubs, or it that a job for another tool?

Yeah, I think that's actually a really good idea. I think it'd be fairly manageable to support in at least a few cases if not all. The tricky part is that stubbing is chainable so it might be hard to determine if the whole expression is useless, but I imagine I can figure something out.

On a related note, I've always planned to handle this for doubles--it's common to make the same mistake there where you do something like instance_double(Foo, bar: unused_baz). I think I will probably start with fixing the double problem first, but I will definitely look into stubbing situations like you have here.

dgollahon commented 6 years ago

I think this is now roughly three categories of features I want:

I may break this into other issues later, but I think this suffices for now.

dgollahon commented 3 years ago

Remove unused stubs from expect, allow, receive_message_chain, etc.

This issue now just tracks this--I split out the other two.