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
On 6/27/07, Ashley Moran <work at ashleymoran.me.uk> wrote:> 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" > > # ... > endTry this instead: describe "All XHR POSTs to /gap/calculate_quote", :shared => true do # ... end describe GapController, "XHR POST /gap/calculate_quote with valid details" do it_should_behave_like "All XHR POSTs to /gap/calculate_quote" # ... end The idea of shared behaviours is that multiple things that are being described have similar behaviour. The specific things, however, should never be created in the shared behaviour - they are the responsibility of the behaviours that should_behave_like them. Make sense?> > 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 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On 27 Jun 2007, at 12:31, David Chelimsky wrote:> Try this instead: > > describe "All XHR POSTs to /gap/calculate_quote", :shared => true do > # ... > endAha yeah - it was the controller_name here that was making it fail> > describe GapController, "XHR POST /gap/calculate_quote with valid > details" do > it_should_behave_like "All XHR POSTs to /gap/calculate_quote" > > # ... > end > > The idea of shared behaviours is that multiple things that are being > described have similar behaviour. The specific things, however, should > never be created in the shared behaviour - they are the responsibility > of the behaviours that should_behave_like them. > > Make sense?Yep it does now. I was thinking of shared behaviours as like an inheritance hierarchy but actually they''re more like mixins, if I understand correctly. ( They are ruby not java :D ) Thanks for the quick reply... can get on coding again now! Ashley