Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
aknuds1 opened this Issue · 7 comments

2 participants

@aknuds1

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 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

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
@myronmarston

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

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

@aknuds1 aknuds1 closed this
@myronmarston

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

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

@aknuds1

It works great, thanks!

@kchien kchien referenced this issue from a commit in kchien/rspec-expectations
@myronmarston myronmarston 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.
790a849
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.