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

Small regression in shared examples between rspec 2.5.x and 2.6.0 #398

Closed
nel opened this issue Jun 3, 2011 · 4 comments
Closed

Small regression in shared examples between rspec 2.5.x and 2.6.0 #398

nel opened this issue Jun 3, 2011 · 4 comments

Comments

@nel
Copy link

nel commented Jun 3, 2011

From Rspec 1.x to RSpec-core 2.5.2 it was possible to have class as label for examples groups. From 2.6.x it leads to infinite loop with very little information about what's happening. An example is better than a long explanantion:

shared_examples_for Object do
   describe Object do
     it { subject.should respond_to(:hash) }
   end
end

describe Array do
  it_behaves_like Object
end

This spec will work under any version of rspec under 2.6.x and trigger a stack level too deep exception from 2.6.x

The fix to make it works under 2.6.x is super easy (once you know it), its to convert shared_examples_for Object and it_behaves_like Object to shared_examples_for "Object" it_behaves_like "Object"

@myronmarston
Copy link
Member

I've never been aware of RSpec supporting shared example group identifiers using classes instead of strings. It may have accidentally supported it, but I don't think I would consider this to be a valid use of RSpec's public API.

Still, the the stack overflow is obviously a bug. I'll let @dchelimsky weigh in about whether or not he wants RSpec to support this or raise an appropriate ArgumentError when you define the shared example group.

In the meantime, can you just use string identifiers for your shared example groups? What advantage do you see for using classes instead?

@nel
Copy link
Author

nel commented Jun 3, 2011

Thanks for the answer, I already fixed it in my projects by using string instead of class.

Actually I've used class for shared examples for two reasons:

  • This is consistent with the describe API accepting class
  • I am a heavy user of mixin, and mixin is the the typical usecase for shared examples. Therefore the mixin itself was a better candidate than any string you can choose as an identifier.

It's been working since as long as shared examples are supported by rspec, I don't necessarily ask for it to work again.

I am just informing you (and any people whose specs end up infinite looping) that it was working and now breaks heavily. To be exhaustive the infinite loop is due in my example to the describe using the same class again inside the shared example, without the describe reusing the class this is just a clean failure something like "can't find shared example".

@gunn
Copy link
Contributor

gunn commented Jun 15, 2011

Just ran into this problem too. It looked like rspec was running every shared example group for every other spec file.

I think @nel's reasons for using class names make a lot of sense.
As for where I got the idea that this was the correct approach: http://blog.davidchelimsky.net/2010/11/07/specifying-mixins-with-shared-example-groups-in-rspec-2/

@dchelimsky
Copy link
Contributor

@gunn - that's so 2010!

@myronmarston - I think this should work w/ Objects as long as there is no loss of functionality in supporting it.

gunn added a commit to gunn/rspec-core that referenced this issue Jun 20, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants