[rspec-users] [Rspec] Trying to get rspec to test a controller in a namespace

Scott Taylor scott at railsnewbie.com
Tue Apr 7 11:45:08 EDT 2009


On Apr 7, 2009, at 7:47 AM, TimBooher wrote:

> I am trying to get my workflow down and am confused on several fronts.
> The first is how to get my rspec_scaffold tests to run. The problem is
> that i generated my scaffold, then moved my controller into a
> namespace named :admin.
>
> So I have the following familiar code. How can i change this to avoid:
>
> ---------------------------------------------
> my error on run
> ---------------------------------------------
>
> /home/tim/.gem/ruby/1.8/gems/activesupport-2.2.2/lib/active_support/
> dependencies.rb:445:in `load_missing_constant': uninitialized constant
> SponsorsController (NameError)
>    from /home/tim/.gem/ruby/1.8/gems/activesupport-2.2.2/lib/
> active_support/dependencies.rb:77:in `const_missing'
>    from /home/tim/.gem/ruby/1.8/gems/activesupport-2.2.2/lib/
> active_support/dependencies.rb:89:in `const_missing'
>    from /home/tim/web_apps/lovd_by_fitwit/spec/controllers/
> sponsors_controller_spec.rb:3
>    from /home/tim/.gem/ruby/1.8/gems/rspec-1.2.2/lib/spec/runner/
> example_group_runner.rb:15:in `load'
>    from /home/tim/.gem/ruby/1.8/gems/rspec-1.2.2/lib/spec/runner/
> example_group_runner.rb:15:in `load_files'
>    from /home/tim/.gem/ruby/1.8/gems/rspec-1.2.2/lib/spec/runner/
> example_group_runner.rb:14:in `each'
>    from /home/tim/.gem/ruby/1.8/gems/rspec-1.2.2/lib/spec/runner/
> example_group_runner.rb:14:in `load_files'
>    from /home/tim/.gem/ruby/1.8/gems/rspec-1.2.2/lib/spec/runner/
> options.rb:97:in `run_examples'
>    from /home/tim/.gem/ruby/1.8/gems/rspec-1.2.2/lib/spec/runner/
> command_line.rb:9:in `run'
>    from /home/tim/web_apps/lovd_by_fitwit/script/spec:5
>
> ---------------------------------------------
> sponsors_controller_spec.rb
> ---------------------------------------------
>
> require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
>
> describe SponsorsController do

Should the controller be named Admin::SponsoredController ?

Scott


>
>
>  def mock_sponsor(stubs={})
>    @mock_sponsor ||= mock_model(Sponsor, stubs)
>  end
>
>  describe "responding to GET index" do
>
>    it "should expose all sponsors as @sponsors" do
>      Sponsor.should_receive(:find).with(:all).and_return
> ([mock_sponsor])
>      get :index
>      assigns[:sponsors].should == [mock_sponsor]
>    end
>
>   . . . .
>
> end
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users



More information about the rspec-users mailing list