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

Problems when running specs with Zeus #384

Closed
gylaz opened this issue Nov 21, 2013 · 29 comments
Closed

Problems when running specs with Zeus #384

gylaz opened this issue Nov 21, 2013 · 29 comments

Comments

@gylaz
Copy link

gylaz commented Nov 21, 2013

I'm using [zeus](https://github.com/burke/zeus) to pre-load the code, for when I'm running specs. It appears that zeus isn't properly requiring shoulda-matchers library for some reason.

I see errors like this:

  1) User validations and associations
     Failure/Error: it { should belong_to(:account) }
     NoMethodError:
       undefined method `belong_to' for #<RSpec::Core::ExampleGroup::Nested_3:0x00000104b8d850>
     # ./spec/models/user_spec.rb:8:in `block (2 levels) in <top (required)>'
     # -e:1:in `<main>'

  2) User validations and associations
     Failure/Error: it { should accept_nested_attributes_for(:account) }
     NoMethodError:
       undefined method `accept_nested_attributes_for' for #<RSpec::Core::ExampleGroup::Nested_3:0x00000104b94f88>
     # ./spec/models/user_spec.rb:9:in `block (2 levels) in <top (required)>'
     # -e:1:in `<main>'

  3) User validations and associations
     Failure/Error: it { validate_presence_of(:account) }
     NoMethodError:
       undefined method `validate_presence_of' for #<RSpec::Core::ExampleGroup::Nested_3:0x00000104b9c800>
     # ./spec/models/user_spec.rb:10:in `block (2 levels) in <top (required)>'
     # -e:1:in `<main>'
@mcmire
Copy link
Collaborator

mcmire commented Nov 21, 2013

This is a bit of a known issue, see #333.

  1. Are the tests running twice, or once?
  2. How are you requiring RSpec in your spec_helper?

@gylaz
Copy link
Author

gylaz commented Nov 22, 2013

Aha, removing require 'rspec/autorun' fixed the issue.

Thanks @mcmire.

@gylaz gylaz closed this as completed Nov 22, 2013
@michaelglass
Copy link
Contributor

this broke when I upgraded from shoulda_matchers 2.5 to 2.6.0 / 2.6.1

@samnang
Copy link

samnang commented May 2, 2014

Same problem for me as well when I upgrade 1.5.4 to 2.6.0 / 2.6.1.

@timminkov
Copy link

This is also broken for me - No autorun in my spec helper, and the gem is pulled in after rails-rspec.

@hunterboerner
Copy link

same here

@mcmire
Copy link
Collaborator

mcmire commented May 5, 2014

I'll reopen this and take another look when I get a chance.

@mcmire mcmire reopened this May 5, 2014
@mrnugget
Copy link

I had the same problem with Zeus, without require 'rspec/autorun' anywhere. My first attempt at a fix was to add this to my spec_helper.rb, as described in the README here:

require 'rspec/rails'
require 'shoulda/matchers'

This didn't fix the problem and I still got undefined method errors.

What did fix the problem was following the README to the point and changing

group :test do
   gem 'shoulda-matchers'
end

in my Gemfile to this too:

group :test do
   gem 'shoulda-matchers', require: false
end

So, in the end following the fix described in the README step by step solved the issue for me.

@michaelglass
Copy link
Contributor

picard-facepalm2
wfm.
at least now this issue is more easily discoverable

@michaelglass
Copy link
Contributor

probably an unrelated issue, but following these directions has broken #should_not/#to_not. Rolling back again.

@mcmire
Copy link
Collaborator

mcmire commented May 22, 2014

@michaelglass Please file a new issue for this and let me know what error you're getting. Thanks.

@mcmire
Copy link
Collaborator

mcmire commented Aug 28, 2014

I'm going ahead and closing this issue due to inactivity. I'm fairly confident we've nailed this as I haven't seen any more reports from people around this, but I would suggest upgrading to 2.6.2 and seeing if that solves the problem.

@mcmire mcmire closed this as completed Aug 28, 2014
@grammakov
Copy link

same issue on 3.0.0 alpha, rolling back to 2.8.0 solves issue

@mcmire
Copy link
Collaborator

mcmire commented Mar 4, 2015

That's because shoulda-matchers no longer installs itself into your test framework automatically. You'll need to add this to your rails_helper:

Shoulda::Matchers.configure do |config|
  config.integrate do |with|
    with.test_framework :rspec
    with.library :rails
  end
end

@SergeyBukhman
Copy link

Still getting this when running with zeus:

NoMethodError: undefined method `belong_to' for #RSpec::ExampleGroups::Business::AssociationSpecs:0x007fba5722d580

I added require: false as suggested, it didn't help

@mcmire
Copy link
Collaborator

mcmire commented Mar 15, 2015

@SergeyBukhman Are you experiencing this on 2.8.0 or 3.0.0.alpha?

@SergeyBukhman
Copy link

2.8.0

@laptite
Copy link

laptite commented Mar 26, 2015

(using rails 4.2.1 and shoulda-matchers 2.8.0)

To get it to work, I added a support file with the following:

RSpec.configure do |config|
  config.include Shoulda::Matchers
end

@SergeyBukhman
Copy link

Works now. Added require 'shoulda/matchers' to rails_helper. Not even sure how this worked before without this. Pretty confused about the whole thing, but it works with zeus.

@mcmire
Copy link
Collaborator

mcmire commented Mar 30, 2015

Zeus does the same thing that Spring does: it preloads your gems (as well as your Rails env). You need to prevent shoulda-matchers from preloading b/c otherwise it gets preloaded before RSpec does, so it doesn't automatically mix itself into your example groups. That's why there's a two-step process in the README. You shouldn't have to include anything extra in your rails_helper.rb

@jwgoh
Copy link

jwgoh commented Jul 22, 2015

group :test do
   gem 'shoulda-matchers', require: false
end

The above works for me. Funnily enough it has been working for other developers.

@kriskhaira
Copy link

Adding require: false to the Gemfile declaration and require 'shoulda/matchers to rails_helper.rb worked for me. I'm on shoulda-matchers 2.8.0, Rails 4.2.1, Ruby 2.1.2.

@usamanoman
Copy link

version 2.8.0 solved my problem.

1 similar comment
@sylvinho81
Copy link

version 2.8.0 solved my problem.

@nkchouhan
Copy link

It is working for me

Shoulda::Matchers.configure do |config|
  config.integrate do |with|
    with.test_framework :rspec
    with.library :rails
  end
end

@OtherCroissant
Copy link

Make sure you have type: :model as argument of the describe call in the model spec files.

@matrinox
Copy link

👍 Add require: false to gem 'shoulda-matchers', require: false worked for me

Moving the gems around didn't, same with the requires. Thanks!

@perryqh
Copy link

perryqh commented Feb 18, 2016

@cunknown suggestion of type: :model worked for me in an engine-gem.

@kdmcclin
Copy link

kdmcclin commented Mar 1, 2016

I'm on Rails 4.1.6 and shoulda-matchers 3.1.1 and I had to do the new configuration as described in the official documentation and the describe Category, type: :model do bit mentioned above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests