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

Overriding subject and using super in a nested example group fails #90

Closed
myronmarston opened this issue Jul 23, 2010 · 3 comments
Closed

Comments

@myronmarston
Copy link
Member

Given that I have RSpec 1.3.0 and 2.0.0.beta.17 installed
And this code is in rspec_example.rb:

require 'rubygems'

if ENV['RSPEC_VERSION'] == '2'
  require 'rspec'
elsif ENV['RSPEC_VERSION'] == '1'
  require 'spec'
  require 'spec/autorun'
end

describe Array do
  subject { [1, 'a'] }

  its(:last) { should == 'a' }

  describe '.first' do
    def subject; super.first; end

    its(:next) { should == 2 }
  end
end

When I run it with RSPEC_VERSION=1 ruby rspec_example.rb
Then I see:

..

Finished in 0.002495 seconds

2 examples, 0 failures

When I run it with RSPEC_VERSION=2 ruby rspec_example.rb
Then I see:

.F

Finished in 0.00171 seconds
2 examples, 1 failure

1) Array .first next
    Failure/Error: Unable to find matching line from backtrace
    undefined method `next' for [1, "a"]:Array
    # rspec_example.rb:16:in `subject'
    # rspec_example.rb:18
    # rspec_example.rb:10

Yes, this is a super contrived example. If you're interested in a real world example, see these specs.

This may not have been documented behavior of rspec 1.x, but it intuitively made sense to me--I understood subject { [1, 'a'] } to create a helper method called subject that returns the given array, and the nested example is a subclass, so I could override subject and super to the original definition.

I know I can use its('first.next') { should == 2 } now in rspec 2, but this seems like a backwards incompatibility with rspec 1.3 that should be either fixed or documented.

@dchelimsky
Copy link
Contributor

Restore original implementation of its(attribute) from rspec-1.

  • original implementation by Stephen Touset
  • Closed by 3025753.

@myronmarston
Copy link
Member Author

Thanks, David. I'm continually impressed at how quickly you address issues!

@dchelimsky
Copy link
Contributor

Don't be too impressed. Or rather, don't set future expectations too high :) I'm just trying to get rspec-2 ready for a production release right now, so this and the book get primary focus these days.

timcharper pushed a commit to timcharper/rspec-core that referenced this issue Aug 19, 2011
- original implementation by Stephen Touset
- Closes rspec#90.
This issue was closed.
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

2 participants