Skip to content

Instantly share code, notes, and snippets.

@piotrze
Created July 6, 2012 08:57
Show Gist options
  • Save piotrze/3059044 to your computer and use it in GitHub Desktop.
Save piotrze/3059044 to your computer and use it in GitHub Desktop.
ApplicationController mock tryout with rspec-mock
#spec/support/prefork/request_helpers.rb
module RequestHelpers
def sign_in
controllers_to_mock.each do |controller|
controller.any_instance.stub(:current_user).and_return(user)
controller.any_instance.stub(:signed_in?).and_return(true)
end
ensure_signed_in
end
def sign_out
controllers_to_mock.each do |controller|
controller.any_instance.unstub(:current_user)
controller.any_instance.unstub(:signed_in?)
end
end
private
def controllers_to_mock
ApplicationController.subclasses[3..-1]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment