[rspec-users] Controller specs not shareable?

Ashley Moran work at ashleymoran.me.uk
Wed Jun 27 06:23:06 EDT 2007


Hi

I just wondered if there was a reason why Rails controller specs are  
not shareable?  eg

   describe "All XHR POSTs to /gap/calculate_quote", :shared => true do
     controller_name :gap

     # ...
end

describe "XHR POST /gap/calculate_quote with valid details" do
   it_should_behave_like "All XHR POSTs to /gap/calculate_quote"

   # ...
end

blows up with the following error:

##########
/Users/ashleymoran/Documents/Development/YourMoney/trunk/src/vendor/ 
plugins/rspec/lib/spec/dsl/behaviour_eval.rb:137:in `method_missing':  
undefined method `controller_name' for # (NoMethodError) from ./spec/ 
controllers/gap_controller_spec.rb:165 from /Users/ashleymoran/ 
Documents/Development/YourMoney/trunk/src/vendor/plugins/rspec/lib/ 
spec/dsl/behaviour.rb:54:in `class_eval' from /Users/ashleymoran/ 
Documents/Development/YourMoney/trunk/src/vendor/plugins/rspec/lib/ 
spec/dsl/behaviour.rb:54:in `eval_behaviour' from /Users/ashleymoran/ 
Documents/Development/YourMoney/trunk/src/vendor/plugins/rspec/lib/ 
spec/dsl/behaviour.rb:31:in `original_initialize' from /Users/ 
ashleymoran/Documents/Development/YourMoney/trunk/src/spec/ 
spec_helper_additions.rb:25:in `initialize' from /Users/ashleymoran/ 
Documents/Development/YourMoney/trunk/src/vendor/plugins/rspec/lib/ 
spec/dsl/behaviour_factory.rb:36:in `new' from /Users/ashleymoran/ 
Documents/Development/YourMoney/trunk/src/vendor/plugins/rspec/lib/ 
spec/dsl/behaviour_factory.rb:36:in `create' from /Users/ashleymoran/ 
Documents/Development/YourMoney/trunk/src/vendor/plugins/rspec/lib/ 
spec/runner/extensions/kernel.rb:24:in `describe' ... 8 levels...  
from /Users/ashleymoran/Library/Application Support/TextMate/Pristine  
Copy/Bundles/RSpec.tmbundle/Support/lib/spec_mate.rb:46:in `chdir'  
from /Users/ashleymoran/Library/Application Support/TextMate/Pristine  
Copy/Bundles/RSpec.tmbundle/Support/lib/spec_mate.rb:46:in `run'  
from /Users/ashleymoran/Library/Application Support/TextMate/Pristine  
Copy/Bundles/RSpec.tmbundle/Support/lib/spec_mate.rb:25:in `run_file'  
from /tmp/temp_textmate.Ft0uGO:4
##########

I've had a quick look through the source and can sorta see why it  
doesn't work.  Is there an easy way to fix this or any plans to add  
it in?  The controller specs are where virtually all my duplication is.

Ashley



More information about the rspec-users mailing list