Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for unused stubs #16

Open
bquorning opened this issue May 28, 2017 · 3 comments
Open

Check for unused stubs #16

bquorning opened this issue May 28, 2017 · 3 comments
Labels

Comments

@bquorning
Copy link
Contributor

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
Copy link
Owner

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 dgollahon changed the title Check also for unused stubs? Check for unused stubs Jun 9, 2017
@dgollahon
Copy link
Owner

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
Copy link
Owner

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants