Thanks David.
I changed to using get :render_403 and it worked. Well, worked after
I added in those routes to my routes.rb file.
I dont have the default routes for /:controller/:action/:id so it was
failing and I dont want custom routes for these two methods because
they will be called from other controllers directly and don't need a
named route.
What is the proper way to test application controller methods that get
called from other controllers? I will never manually go to /
application/render_403 but it seems I had to pretend this would happen
to spec it out properly.
- Craig
On Sep 6, 9:55 am, Craig Jolicoeur <[EMAIL PROTECTED]> wrote:
> >>First off - should_receive *is* a test - why would you write a test in
>
> the setup?
>
> Not sure what you mean by that. I'm not writing a test in the setup
> routine.
>
> Also, I'm not setting an expectation on a method call. should
> render_file is in the right place.
>
> On Sep 5, 11:48 pm, Scott Taylor <[EMAIL PROTECTED]>
> wrote:
>
> > On Sep 5, 2008, at 10:18 PM, Craig P Jolicoeur wrote:
>
> > > I'm having some trouble trying to spec some methods in my Rails
> > > application controller.
>
> > > I'm new to rspec converting over from straight test::unit.
>
> > > Here is the method in my application.rb controller that I'm trying
> > > to spec
>
> > > def render_403
> > > logger.debug "Returned 403: #{request.request_uri}"
> > > render :file => "#{RAILS_ROOT}/public/403.html", :status => '403'
> > > end
>
> > > Here is my *current* spec
>
> > > describe "handling render 403" do
>
> > > before(:each) do
>
> > > controller.request.should_receive(:request_uri).and_return('response
> > > request_uri')
> > > end
>
> > First off - should_receive *is* a test - why would you write a test in
> > the setup?
>
> > > it "should render the 403 error page" do
> > > controller.render_403
> > > response.should render_file("#{RAILS_ROOT}/public/403.html")
> > > end
>
> > Two issues with this test:
>
> > 1. Normally, if you are going to write a test checking that a method
> > is called on an object (should_receive), you'd write that assertion
> > before you perform any action. For example:
>
> > an_object.should_receive(:a_method_call)
> > an_object.a_method_call
>
> > would pass
>
> > but
>
> > an_object.a_method_call
> > an_object.should_receive(:a_method_call)
>
> > would fail
>
> > 2. Usually, you make a request in controller specs, like
> > "get :render_404". See the controller docs on the rspec site.
>
> > Hope that helps,
>
> > Scott
>
> > _______________________________________________
> > rspec-users mailing list
> > [EMAIL PROTECTED]://rubyforge.org/mailman/listinfo/rspec-users
>
> _______________________________________________
> rspec-users mailing list
> [EMAIL PROTECTED]://rubyforge.org/mailman/listinfo/rspec-users
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users