Undefined variable in Cucumber step definition triggers SystemStackError in rspec #67

Closed
aknuds1 opened this Issue Mar 26, 2011 · 7 comments

Comments

Projects
None yet
2 participants
@aknuds1

aknuds1 commented Mar 26, 2011

In a Rails 3.0.5 application with Ruby 1.9.2p180, rspec-expectations 2.5.0 and Cucumber 0.10.2, I am experiencing that SystemStackError is raised from within RSpec. The trigger is to refer to an undefined variable within a Cucumber step definition, like so:

Given /^I am logged in as "([^"]+)"$/ do |username|
  define_me
end

This results in SystemStackError from line 7 of /usr/local/rvm/gems/ruby-1.9.2-p180/gems/rspec-expectations-2.5.0/lib/rspec/matchers/method_missing.rb.

See my IRC conversation with Aslak Hellesøy for reference.

@myronmarston

This comment has been minimized.

Show comment Hide comment
@myronmarston

myronmarston Mar 27, 2011

Member

This is caused by a bug in ruby 1.9.

I've already worked around this in rspec-core, but there hasn't been a release since that commit.

If you want to get this fix now, you can use rspec-core from git.

Member

myronmarston commented Mar 27, 2011

This is caused by a bug in ruby 1.9.

I've already worked around this in rspec-core, but there hasn't been a release since that commit.

If you want to get this fix now, you can use rspec-core from git.

@aknuds1

This comment has been minimized.

Show comment Hide comment
@aknuds1

aknuds1 Mar 27, 2011

I tried to install the latest git revision, by adding this line to my Gemfile (and running bundle install):
gem 'rspec-core', :git=>'https://github.com/rspec/rspec-core.git'.

However, the bug still occurs. Should I be doing something else?

aknuds1 commented Mar 27, 2011

I tried to install the latest git revision, by adding this line to my Gemfile (and running bundle install):
gem 'rspec-core', :git=>'https://github.com/rspec/rspec-core.git'.

However, the bug still occurs. Should I be doing something else?

@myronmarston myronmarston reopened this Mar 27, 2011

@myronmarston

This comment has been minimized.

Show comment Hide comment
@myronmarston

myronmarston Mar 27, 2011

Member

No, that's the correct way to use the latest rspec-core from git.

So here's the deal...this is a bug in ruby 1.9. Any module that includes a method that calls super will potentially have this problem. It's not actually a bug in RSpec::Matchers. The bug is triggered when the module is included in both a subclass and a superclass, and is included in the superclass after it was included in the subclass.

We fixed this in rspec-core (see the commit I referenced above) by changing the point in time we include RSpec::Matchers so that it is included in RSpec::Core::ExampleGroup before RSpec::Core::ExampleGroup is subclassed. I don't know much about how cucumber uses rspec-expectations, but my guess is that it is using it on its own (without using RSpec::Core::ExampleGroup), so it makes sense that my fix above wouldn't affect cucumber. I think we're going to need to fix this in cucumber itself by changing the way it includes RSpec::Matchers (just like we did in rspec-core).

Can you come up with a minimal failing case? Just a bit of code that uses cucumber and demonstrates this bug will suffice. Based on that, I'll take a look at coming up with a fix in cucumber and see if i can submit it as a pull request.

Thanks!

Member

myronmarston commented Mar 27, 2011

No, that's the correct way to use the latest rspec-core from git.

So here's the deal...this is a bug in ruby 1.9. Any module that includes a method that calls super will potentially have this problem. It's not actually a bug in RSpec::Matchers. The bug is triggered when the module is included in both a subclass and a superclass, and is included in the superclass after it was included in the subclass.

We fixed this in rspec-core (see the commit I referenced above) by changing the point in time we include RSpec::Matchers so that it is included in RSpec::Core::ExampleGroup before RSpec::Core::ExampleGroup is subclassed. I don't know much about how cucumber uses rspec-expectations, but my guess is that it is using it on its own (without using RSpec::Core::ExampleGroup), so it makes sense that my fix above wouldn't affect cucumber. I think we're going to need to fix this in cucumber itself by changing the way it includes RSpec::Matchers (just like we did in rspec-core).

Can you come up with a minimal failing case? Just a bit of code that uses cucumber and demonstrates this bug will suffice. Based on that, I'll take a look at coming up with a fix in cucumber and see if i can submit it as a pull request.

Thanks!

@aknuds1

This comment has been minimized.

Show comment Hide comment
@aknuds1

aknuds1 Mar 27, 2011

I have a minimal failing Rails app. How do you suggest I share it?

aknuds1 commented Mar 27, 2011

I have a minimal failing Rails app. How do you suggest I share it?

@aknuds1 aknuds1 closed this Mar 27, 2011

@myronmarston

This comment has been minimized.

Show comment Hide comment
@myronmarston

myronmarston Mar 27, 2011

Member

If it's ok to make it public, you can just put it on github, and post the link. If you do this, it'd be good to make a branch for this so you can continue developing on your master branch and I have a point to work off that is known to demonstrate the bug.

If you can't make it public, but are ok with me having access to it to troubleshoot this, feel free to make a zip or tar archive file of the whole project, and send me an email with it attached.

Also, instructions of how to get a dev enviroment and how to repro the bug would be helpful.

Member

myronmarston commented Mar 27, 2011

If it's ok to make it public, you can just put it on github, and post the link. If you do this, it'd be good to make a branch for this so you can continue developing on your master branch and I have a point to work off that is known to demonstrate the bug.

If you can't make it public, but are ok with me having access to it to troubleshoot this, feel free to make a zip or tar archive file of the whole project, and send me an email with it attached.

Also, instructions of how to get a dev enviroment and how to repro the bug would be helpful.

@myronmarston

This comment has been minimized.

Show comment Hide comment
@myronmarston

myronmarston Mar 28, 2011

Member

I just pushed a fix to rspec-expectations. Try using rspec-expectations from git and it should work now.

Member

myronmarston commented Mar 28, 2011

I just pushed a fix to rspec-expectations. Try using rspec-expectations from git and it should work now.

@aknuds1

This comment has been minimized.

Show comment Hide comment
@aknuds1

aknuds1 Mar 28, 2011

It works great, thanks!

aknuds1 commented Mar 28, 2011

It works great, thanks!

kchien pushed a commit to kchien/rspec-expectations that referenced this issue Mar 7, 2014

Fix inclusion order of RSpec::Matchers in Test::Unit and MiniTest.
Due to a bug in ruby 1.9, RSpec::Matchers must be included in the superclass (MiniTest::Unit::TestCase) before it is included in a subclass (Test::Unit::TestCase) or we may get infinite recursion and a SystemStackError from our `super` call in our method_missing hook.  See this gist for more info about the ruby 1.9 bug:

https://gist.github.com/845896

Closes #67.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment