extracted some common Strategy specs into a new StrategyMacros; used them in Basecamp and Campfire specs

This commit is contained in:
James A. Rosen 2010-06-18 21:56:44 -04:00
Родитель 7d59543b1b
Коммит f15f6fbed1
5 изменённых файлов: 42 добавлений и 19 удалений

Просмотреть файл

@ -3,7 +3,8 @@ module OmniAuth
# Support for testing OmniAuth strategies.
module Test
autoload :PhonySession, 'omniauth/test/phony_session'
autoload :PhonySession, 'omniauth/test/phony_session'
autoload :StrategyMacros, 'omniauth/test/strategy_macros'
end

Просмотреть файл

@ -0,0 +1,29 @@
module OmniAuth
module Test
module StrategyMacros
def sets_an_auth_hash
it 'should set an auth hash' do
last_request['auth'].should be_kind_of(Hash)
end
end
def sets_provider_to(provider)
it "should set the provider to #{provider}" do
(last_request['auth'] || {})['provider'].should == provider
end
end
def sets_uid_to(uid)
it "should set the UID to #{uid}" do
(last_request['auth'] || {})['uid'].should == uid
end
end
end
end
end

Просмотреть файл

@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe OmniAuth::Strategies::Basecamp do
describe OmniAuth::Strategies::Basecamp, :type => :strategy do
def app
Rack::Builder.new {
@ -60,14 +60,10 @@ describe OmniAuth::Strategies::Basecamp do
to_return(:body => File.read(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'basecamp_200.xml')))
get '/auth/basecamp/callback?code=plums', {}, {'rack.session' => {:oauth => {:basecamp => {:subdomain => 'flugle'}}}}
end
it 'should set the provider to "basecamp"' do
last_request['auth']['provider'].should == 'basecamp'
end
it 'should set the UID to "1827370"' do
last_request['auth']['uid'].should == '1827370'
end
sets_an_auth_hash
sets_provider_to 'basecamp'
sets_uid_to '1827370'
it 'should exchange the request token for an access token' do
token = last_request['auth']['extra']['access_token']

Просмотреть файл

@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe OmniAuth::Strategies::Campfire do
describe OmniAuth::Strategies::Campfire, :type => :strategy do
def app
Rack::Builder.new {
@ -60,14 +60,10 @@ describe OmniAuth::Strategies::Campfire do
to_return(:body => File.read(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'campfire_200.json')))
get '/auth/campfire/callback?code=plums', {}, {'rack.session' => {:oauth => {:campfire => {:subdomain => 'flugle'}}}}
end
it 'should set the provider to "campfire"' do
last_request['auth']['provider'].should == 'campfire'
end
it 'should set the UID to "92718"' do
last_request['auth']['uid'].should == '92718'
end
sets_an_auth_hash
sets_provider_to 'campfire'
sets_uid_to '92718'
it 'should exchange the request token for an access token' do
token = last_request['auth']['extra']['access_token']

Просмотреть файл

@ -12,4 +12,5 @@ require 'omniauth/oauth'
Spec::Runner.configure do |config|
config.include WebMock
config.include Rack::Test::Methods
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
end