« Return to Thread: Spec'ing controller macros

Spec'ing controller macros

by Matt McNeil () :: Rate this Message:

Reply to Author | View in Thread

Hi,

(This is my first post after months of appreciative lurking...)

I'm trying to spec the following conditional controller macro:

class ApplicationController < ActionController::Base
  # turn off session management for robots
  session :off, :if => lambda {|req| req.user_agent =~ /(Google|Slurp)/i }
  # ...
end

My current attempt seems to be quite unsuccessful:
1) when I include the controller.should_receive(:session) statement, the index action no longer seems to be actually called (ie a breakpoint placed in the index method is not triggered)
2) I receive the following error:
Spec::Mocks::MockExpectationError in 'ApplicationController should turn off session management for requests made by robot user agent'
Mock 'FooController' expected :session with (:off) but received it with (no args)
./spec/controllers/application_spec.rb:19:

Any suggestions?

Thanks much,
Matt


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

 « Return to Thread: Spec'ing controller macros