Created
April 5, 2010 15:33
-
-
Save keeran/356471 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # in spec_helper.rb | |
| def mock_warden(scope) | |
| warden = mock('warden') | |
| warden.stub!("authenticate_#{scope}!").and_return(true) | |
| warden.stub!(:authenticate!).and_return(true) | |
| return warden | |
| end | |
| module ControllerExampleGroupBehaviour | |
| %w[get post put delete head].map do |method| | |
| alias_method "orig_#{method}", method | |
| eval <<-CODE | |
| def #{method}(*args) | |
| action = args.shift | |
| params = args.shift || {} | |
| args << {'warden' => @warden} | |
| orig_#{method} action, params, *args | |
| end | |
| CODE | |
| end | |
| end | |
| # in controller specs | |
| before(:each) do | |
| # log in as a subscriber | |
| @warden = mock_warden(:subscriber) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment