Forum: RSpec [Rspec] Trying to get rspec to test a controller in a namespace

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
60f6efe48c9e5eceaf16f2e2cf53f41a?d=identicon&s=25 Tim Booher (Guest)
on 2009-04-07 17:16
(Received via mailing list)
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

  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
E1e02debdc862e5e7d650ba0ea1964f1?d=identicon&s=25 TimBooher (Guest)
on 2009-04-08 23:47
(Received via mailing list)
any takers? am i asking a question that is too hard or too easy and
boring?

thanks,

tim
F86901feca747abbb5c6c020362ef2e7?d=identicon&s=25 Zach Dennis (zdennis)
on 2009-04-09 00:42
(Received via mailing list)
On Wed, Apr 8, 2009 at 5:18 PM, TimBooher <tbbooher@gmail.com> wrote:
> any takers? am i asking a question that is too hard or too easy and
> boring?

So your SponsorsController exists inside of a Admin module namespace?

If so update your spec:

   describe Admin::SponsorsController

If that's not the issue I'm not quite sure what you're using namespace
to refer to,



>>
>> 
/home/tim/.gem/ruby/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:77:in
>> /home/tim/.gem/ruby/1.8/gems/rspec-1.2.2/lib/spec/runner/example_group_runner.rb:15:in
>>     from
>> describe SponsorsController do
>>       assigns[:sponsors].should == [mock_sponsor]
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>



--
Zach Dennis
http://www.continuousthinking.com
http://www.mutuallyhuman.com
09477c358c5897d44121a248326e16d7?d=identicon&s=25 Jim Gay (Guest)
on 2009-04-09 00:50
(Received via mailing list)
Hey Tim,
I didn't see the first post.
If you've namespaced the controller, you'll need to make that change
in the spec.

My assumption is that
SponsorsController became Admin::SponsorsController
So you'll need to make sure that this is reflected in your spec.

-Jim
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2009-04-09 10:06
(Received via mailing list)
Beware of scaffolds - they stop you from thinking which is never good.

Anyway my guess at the answer is inline.

On 8 Apr 2009, at 22:18, TimBooher wrote:

>> first is how to get my rspec_scaffold tests to run. The problem is
>> ---------------------------------------------
>> /home/tim/.gem/ruby/1.8/gems/activesupport-2.2.2/lib/active_support/
>> /home/tim/.gem/ruby/1.8/gems/rspec-1.2.2/lib/spec/runner/
>>     from
>> sponsors_controller_spec.rb
>> ---------------------------------------------
>>
>> require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
>>
module Admin
>> Sponsor.should_receive(:find).with(:all).and_return([mock_sponsor])
>>       get :index
>>       assigns[:sponsors].should == [mock_sponsor]
>>     end
>>
>>    . . . .
>>
>> end
end
>>
>>
>> _______________________________________________
>> rspec-users mailing list
>> rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

Matt Wynne
http://blog.mattwynne.net
http://www.songkick.com
This topic is locked and can not be replied to.