macros don't work: undefined method `should_assign_to' for FoodEntryControllerTest::Subclass_1:Class (NoMethodError)

41 views
Skip to first unread message

oren

unread,
Dec 24, 2009, 2:38:20 AM12/24/09
to shoulda
ruby 1.9.1p243, rails 2.3.5, thoughtbot-shoulda 2.10.2.

my spec, using macros:
class FoodEntryControllerTest < ActionController::TestCase
context "on GET new" do
setup do
@food_entry = FoodEntry.new
get :new
end

should_assign_to :food_entry
end
end

the error:
/home/oren/weighmyplate/spec/controllers/food_entry_controller_spec.rb:
27:in `block in <class:FoodEntryControllerTest>': undefined method
`should_assign_to' for FoodEntryControllerTest::Subclass_1:Class
(NoMethodError)
from /opt/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/rspec-1.2.9/
lib/spec/example/example_group_methods.rb:183:in `module_eval'
from /opt/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/rspec-1.2.9/
lib/spec/example/example_group_methods.rb:183:in `subclass'
from /opt/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/rspec-1.2.9/
lib/spec/example/example_group_methods.rb:55:in `describe'
from /home/oren/weighmyplate/spec/controllers/
food_entry_controller_spec.rb:21:in `<class:FoodEntryControllerTest>'
from /home/oren/weighmyplate/spec/controllers/
food_entry_controller_spec.rb:20:in `<top (required)>'
from /opt/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/rspec-1.2.9/
lib/spec/runner/example_group_runner.rb:15:in `load'
from /opt/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/rspec-1.2.9/
lib/spec/runner/example_group_runner.rb:15:in `block in load_files'
from /opt/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/rspec-1.2.9/
lib/spec/runner/example_group_runner.rb:14:in `each'
from /opt/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/rspec-1.2.9/
lib/spec/runner/example_group_runner.rb:14:in `load_files'
from /opt/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/rspec-1.2.9/
lib/spec/runner/options.rb:132:in `run_examples'
from /opt/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/rspec-1.2.9/
lib/spec/runner/command_line.rb:9:in `run'
from /opt/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/rspec-1.2.9/
bin/spec:5:in `<top (required)>'
from /opt/ruby/bin/spec:19:in `load'
from /opt/ruby/bin/spec:19:in `<main>'

btw, machers works:
describe FoodEntryController, "GET new" do
before(:each) do
get :new
@food_entry = FoodEntry.new
end

it { should assign_to( :food_entry ) }
end

thanks!

Michael Breen

unread,
Dec 24, 2009, 9:15:06 AM12/24/09
to sho...@googlegroups.com
I'm pretty sure that Shoulda won't load the rails macros if Spec is defined. Check out rails/init.rb:

if RAILS_ENV == 'test'
if defined? Spec
require 'shoulda/rspec'
else
require 'shoulda/rails'
end
end

so it looks like it's one or the other.

Best.
Mike

> --
> Individuals over processes. Interactions over tools.
>
> Agile Rails training from thoughtbot, the makers of Clearance, Shoulda, & Factory Girl:
> http://thoughtbot.com/services/training
>
> The Shoulda group:
> http://groups.google.com/group/shoulda
>
> To post to this group, send email to
> sho...@googlegroups.com
>
> To unsubscribe from this group, send email to
> shoulda+u...@googlegroups.com

Reply all
Reply to author
Forward
0 new messages