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

[BUG] undefined method define' for RSpec::Matchers:Module` #16

Closed
JustinAiken opened this issue Mar 10, 2014 · 9 comments
Closed

[BUG] undefined method define' for RSpec::Matchers:Module` #16

JustinAiken opened this issue Mar 10, 2014 · 9 comments
Labels

Comments

@JustinAiken
Copy link

Upon this line in my spec_helper:

require 'cancan/matchers'

I get this:

/Users/jaiken/.rvm/gems/ruby-2.0.0-p247@pws/gems/cancancan-1.7.0/lib/cancan/matchers.rb:2:in `<top (required)>': undefined method `define' for RSpec::Matchers:Module (NoMethodError)
    from /Users/jaiken/.rvm/gems/ruby-2.0.0-p247@pws/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `require'
    from /Users/jaiken/.rvm/gems/ruby-2.0.0-p247@pws/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/jaiken/.rvm/gems/ruby-2.0.0-p247@pws/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/jaiken/.rvm/gems/ruby-2.0.0-p247@pws/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:251:in `require'
    from /Users/jaiken/projects/phrg/pws/spec/spec_helper.rb:12:in `<top (required)>'
    from /Users/jaiken/projects/phrg/pws/spec/models/agent_originator_spec.rb:1:in `require'
    from /Users/jaiken/projects/phrg/pws/spec/models/agent_originator_spec.rb:1:in `<top (required)>'
    from /Users/jaiken/.rvm/gems/ruby-2.0.0-p247@pws/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `load'
    from /Users/jaiken/.rvm/gems/ruby-2.0.0-p247@pws/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
    from /Users/jaiken/.rvm/gems/ruby-2.0.0-p247@pws/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `each'
    from /Users/jaiken/.rvm/gems/ruby-2.0.0-p247@pws/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `load_spec_files'
    from /Users/jaiken/.rvm/gems/ruby-2.0.0-p247@pws/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:22:in `run'
    from /Users/jaiken/.rvm/gems/ruby-2.0.0-p247@pws/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:80:in `run'
    from /Users/jaiken/.rvm/gems/ruby-2.0.0-p247@pws/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:17:in `block in autorun'

cancancan 1.70
Rails 3.2.17
Rspec 2.14.1

@JustinAiken
Copy link
Author

This doesn't happen with Rspec 2.13 - something changed between 2.13 and 2.14 that changed this.

If I just add require 'rspec/expectations' to the top of lib/cancan/matchers.rb, it works okay. Not sure if that would break compatibility with other versions of rspec though. Also works if I add that line to my own spec_helper before I require cancan.

@bryanrite
Copy link
Member

This is on master or 1.7.0?

@bryanrite
Copy link
Member

bah.. obviously the 1.7.0... sorry... i'll check it out.

@bryanrite bryanrite added the bug label Mar 12, 2014
@bryanrite
Copy link
Member

Upon some investigation:

https://github.com/rspec/rspec/commit/15ef280ac74b03f612d6038f484d80226fb38e03

Removed explicitly requiring both expectations and mocks. So it should be fixable by:

Removing

require 'rspec'

and adding

require 'rspec/core'
require 'rspec/expectations'
require 'rspec/mocks'

I'll get this in asap as a patch release.

@bryanrite
Copy link
Member

@JustinAiken I haven't actually been able to duplicate your issue, no matter where I require cancan/matches ... Could you try running against:

https://github.com/CanCanCommunity/cancancan/tree/feature/fix_rspec

And let me know if that fixes it, either that or paste a minimal spec_helper. Super appreciated!

@bryanrite
Copy link
Member

@JustinAiken ping?

@JustinAiken
Copy link
Author

Oh, haha... I was bundleing up that ref as you pinged me :)

Yes confirmed - that fixes it :)

@bryanrite
Copy link
Member

hahaha... great thanks, I'll push a 1.7.1 release today.

@JustinAiken
Copy link
Author

Also, this probably isn't needed since that PR fixes it, but for future reference, in case anybody has issues in the future and googles this:

My spec_helper started with:

require File.dirname(__FILE__) + "/../config/environment" unless defined?(Rails.root)

require 'shoulda'
require 'cancan/matchers'
require 'rspec/rails'
require 'timecop'
require 'webmock/rspec'

...and before this PR, failed unless I added require 'rspec/expectations' right before requireing cancan's matchers - with this PR my spec_helper remains as is.

trotzig pushed a commit to sds/db-query-matchers that referenced this issue Aug 12, 2014
This fixes issue #2, where this error would be thrown:

  undefined method define' for RSpec::Matchers:Module (NoMethodError)`

From some googling, it looks like this commit in rspec might have caused
the issue:
https://github.com/rspec/rspec/commit/15ef280ac74b03f612d6038f484d80226fb38e03

That rspec commit was linked to from
CanCanCommunity/cancancan#16 , where a similar
fix seem to have helped.

Change-Id: I420a68d34cb4ae7b0ec24ec6dbe433ac40b0ff9e
Reviewed-on: http://gerrit.causes.com/41501
Tested-by: Henric Trotzig <henric.trotzig@brigade.com>
Reviewed-by: Flarnie Marchan <flarnie.marchan@brigade.com>
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