On Wed, Aug 26, 2009 at 2:39 PM, john<eagerwombat at gmail.com>
wrote:> Hi Rspec Community,
> I ran into an interesting problem yesterday.
> I''m using polymorphic_path for my controller, but I can''t
figure out how to
> test it.
> ################################################
> # routes.rb
> map.resources :schedules
> map.resources :meetings, :controller => ''schedules''
> # meetings_controller_spec.rb
> describe MeetingsController do
> ??before(:each) do
> ?? ?@current_user = mock_model(User, :id => 1)
> ?? ?controller.stub!(:current_user).and_return(@current_user)
> ?? ?controller.stub!(:login_required).and_return(:true)
> ??end
> ??it "should get ''new'' action successfully" do
> ?? ?get :new
> ?? ?response.should be_success
> ??end
> end
> # spec error output
>
/Users/john/.gem/ruby/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:443:in
> `load_missing_constant'': uninitialized constant MeetingsController
> (NameError)
> from
>
/Users/john/.gem/ruby/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:80:in
> `const_missing''
> from
>
/Users/john/.gem/ruby/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:92:in
> `const_missing''
> from ./spec/controllers/meetings_controller_spec.rb:3
> from
>
/Users/john/.gem/ruby/1.8/gems/rspec-1.2.8/lib/spec/runner/example_group_runner.rb:15:in
> `load''
> from
>
/Users/john/.gem/ruby/1.8/gems/rspec-1.2.8/lib/spec/runner/example_group_runner.rb:15:in
> `load_files''
> from
>
/Users/john/.gem/ruby/1.8/gems/rspec-1.2.8/lib/spec/runner/example_group_runner.rb:14:in
> `each''
> from
>
/Users/john/.gem/ruby/1.8/gems/rspec-1.2.8/lib/spec/runner/example_group_runner.rb:14:in
> `load_files''
> from
>
/Users/john/.gem/ruby/1.8/gems/rspec-1.2.8/lib/spec/runner/options.rb:107:in
> `run_examples''
> from
>
/Users/john/.gem/ruby/1.8/gems/rspec-1.2.8/lib/spec/runner/command_line.rb:9:in
> `run''
> from script/spec:5
> ##################################
Didn''t you mean SchedulesController instead of MeetingsController in
the spec.
>From the snippet from your routes.rb I wouldn''t expect you to have
a
MeetingsController.
And controller specs don''t use routes to find controller methods
anyway.
--
Rick DeNatale
Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale