On Tue, Apr 29, 2008 at 9:48 AM, Matt McNeil <[EMAIL PROTECTED]> wrote:
>  describe ApplicationController do
>   class FooController < ApplicationController
>     def index; render :text => "foo"; end
>   end
>   controller_name :foo
>
>   it "should turn off session management for requests made by robot user
>  agent" do
>     request.stub!(:user_agent).and_return("Google Robot")
>     controller.should_receive(:session).with(:off)
>     get :index
>   end
>  end

Hi Matt,

The problem here is that it's actually the controller class that's
receiving the 'session' message, not a controller object.

In this case, mocking the call isn't going to do you much good.  The
:if block wouldn't get evaluated, forcing you to just duplicate the
method arguments.

The good news is you can test the desired behavior with a more
state-based approach:

  it "should turn the session off" do
    request.stub!(:user_agent).and_return("Google Robot")
    get :index
    controller.should_not be_session_enabled
  end

Pat
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to