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

method not found with Rails 3.1.0RC1 #171

Closed
davidsf opened this issue May 22, 2011 · 9 comments
Closed

method not found with Rails 3.1.0RC1 #171

davidsf opened this issue May 22, 2011 · 9 comments

Comments

@davidsf
Copy link

davidsf commented May 22, 2011

I have updated an app to Rails 3.1.0RC1 and the tests now give the error:

undefined method `have_many' for UserTest:Class (NoMethodError)

with all the shoulda matchers. Is like doesn't load shoulda but I have require 'shoulda' in test_helper.rb and require 'test_helper.rb' in the test file (the same test works with Rails 3.0.x).

Rails 3.1.0.rc1 with shoulda 2.11.3

@AndreasWurm
Copy link

I also use rails 3.1 rc1 and I experience no problems

group :test do
  gem "rspec-rails", "~> 2.6.1.beta1"
  gem 'shoulda', "~> 2.11.3"
end
require 'spec_helper'

describe User do
  it { should have_many(:folders) }
end

@davidsf
Copy link
Author

davidsf commented May 23, 2011

I'm using test/unit without rspec.

group :test do
  gem 'shoulda'
end

test_helper:

require 'shoulda'

test/unit/stop_test.rb

require 'test_helper'

class StopTest < ActiveSupport::TestCase
  should belong_to :trip
end
#ruby -Itest test/unit/stop_test.rb 
test/unit/stop_test.rb:4:in `<class:StopTest>': undefined method `belong_to' for StopTest:Class (NoMethodError)
    from test/unit/stop_test.rb:3:in `<main>'

@rmm5t
Copy link
Collaborator

rmm5t commented May 23, 2011

Hi David, I think this is caused because the current stable version of shoulda looks for RAILS_ROOT to determine what to automatically load, but it's no longer available in Rails 3.1.

As a temporary workaround (and before Shoulda 3.0 is stable), add this to your test_helper.rb:

# Shoulda looks for RAILS_ROOT before loading shoulda/rails, and Rails 3.1
# doesn't have that anymore.
require 'shoulda/rails'

@davidsf
Copy link
Author

davidsf commented May 23, 2011

Thanks Ryan, with the workaround works great.

@davidsf davidsf closed this as completed May 23, 2011
@rmm5t rmm5t reopened this May 23, 2011
@rmm5t
Copy link
Collaborator

rmm5t commented May 23, 2011

I'm going to leave this open, just to make sure we have everything resolved in Shoulda 3.0 beta. I think it might already be handled, but I don't want to lose track of it.

@lucassus
Copy link

For me
require 'shoulda/matchers'
fixed this problem, see: https://github.com/lucassus/cse/commit/a78cf7585cb9e7f2489472ef70d21564103e7975#L3R7

@weeksie
Copy link

weeksie commented Sep 30, 2011

This still isn't working for me. I get an undefined method validates_presence_of with Rails 3.1 and shoulda 2.11.3, even when explicitly requiring 'shoulda/rails' I'm using Test::Unit.

@gtd
Copy link

gtd commented Oct 18, 2011

The require 'shoulda/rails' hack works for 2.11.3, but that is full of deprecation warnings as described #173. Updating to 3.0.0.beta renders the require 'shoulda/rails' hack ineffective.

Rails 3.1 has been out for almost 2 months now, can we expect a definitive fix soon? Or is test/unit deprecated permanently?

@gabebw
Copy link

gabebw commented Mar 9, 2012

Hi all, does using shoulda-context 3.0.0 work? If not, please open an issue on shoulda-context.

@gabebw gabebw closed this as completed Mar 9, 2012
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

7 participants