Skip to content

Commit

Permalink
update Rspec for 3.x version
Browse files Browse the repository at this point in the history
  • Loading branch information
Luciano Sousa committed Oct 25, 2015
1 parent 5b5c1f7 commit e33bd04
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 50 deletions.
2 changes: 1 addition & 1 deletion omniauth-foursquare.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |s|

s.add_dependency 'omniauth', '~> 1.0'
s.add_dependency 'omniauth-oauth2', '~> 1.0'
s.add_development_dependency 'rspec', '~> 2.7'
s.add_development_dependency 'rspec', '~> 3.3.0'
s.add_development_dependency 'rack-test'
s.add_development_dependency 'simplecov'
s.add_development_dependency 'webmock'
Expand Down
80 changes: 40 additions & 40 deletions spec/omniauth/strategies/foursquare_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
describe OmniAuth::Strategies::Foursquare do
before :each do
@request = double('Request')
@request.stub(:params) { {} }
allow(@request).to receive(:params) { {} }
end

subject do
OmniAuth::Strategies::Foursquare.new(nil, @options || {}).tap do |strategy|
strategy.stub(:request) { @request }
allow(strategy).to receive(:request) { @request }
end
end

it_should_behave_like 'an oauth2 strategy'

describe '#client' do
it 'has correct Foursquare site' do
subject.client.site.should eq('https://foursquare.com')
expect(subject.client.site).to eq('https://foursquare.com')
end

it 'has correct authorize url' do
subject.client.options[:authorize_url].should eq('/oauth2/authenticate')
expect(subject.client.options[:authorize_url]).to eq('/oauth2/authenticate')
end

it 'has correct token url' do
subject.client.options[:token_url].should eq('/oauth2/access_token')
expect(subject.client.options[:token_url]).to eq('/oauth2/access_token')
end
end

Expand All @@ -42,97 +42,97 @@
'homeCity' => 'Chicago',
'bio' => 'I am a guy from Chicago.'
}
subject.stub(:raw_info) { @raw_info }
allow(subject).to receive(:raw_info) { @raw_info }
end

context 'when data is present in raw info' do
it 'returns the combined name' do
subject.info[:name].should eq('Fred Smith')
expect(subject.info[:name]).to eq('Fred Smith')
end

it 'returns the first name' do
subject.info[:first_name].should eq('Fred')
expect(subject.info[:first_name]).to eq('Fred')
end

it 'returns the last name' do
subject.info[:last_name].should eq('Smith')
expect(subject.info[:last_name]).to eq('Smith')
end

it 'returns the email' do
subject.info[:email].should eq('fred@example.com')
expect(subject.info[:email]).to eq('fred@example.com')
end

it 'returns the phone number' do
subject.info[:phone].should eq('+1 555 555-5555')
expect(subject.info[:phone]).to eq('+1 555 555-5555')
end

it "sets the email blank if contact block is missing in raw_info" do
@raw_info.delete('contact')
subject.info[:email].should be_nil
expect(subject.info[:email]).to be_nil
end

it 'returns the user image' do
subject.info[:image].should eq('https://img-s.foursquare.com/userpix_thumbs/blank_boy.jpg')
expect(subject.info[:image]).to eq('https://img-s.foursquare.com/userpix_thumbs/blank_boy.jpg')
end

it 'returns the user location' do
subject.info[:location].should eq('Chicago')
expect(subject.info[:location]).to eq('Chicago')
end

it 'returns the user description' do
subject.info[:description].should eq('I am a guy from Chicago.')
expect(subject.info[:description]).to eq('I am a guy from Chicago.')
end
end
end

describe '#credentials' do
before :each do
@access_token = double('OAuth2::AccessToken')
@access_token.stub(:token)
@access_token.stub(:expires?)
@access_token.stub(:expires_at)
@access_token.stub(:refresh_token)
subject.stub(:access_token) { @access_token }
allow(@access_token).to receive(:token)
allow(@access_token).to receive(:expires?)
allow(@access_token).to receive(:expires_at)
allow(@access_token).to receive(:refresh_token)
allow(subject).to receive(:access_token) { @access_token }
end

it 'returns a Hash' do
subject.credentials.should be_a(Hash)
expect(subject.credentials).to be_a(Hash)
end

it 'returns the token' do
@access_token.stub(:token) { '123' }
subject.credentials['token'].should eq('123')
allow(@access_token).to receive(:token) { '123' }
expect(subject.credentials['token']).to eq('123')
end

it 'returns the expiry status' do
@access_token.stub(:expires?) { true }
subject.credentials['expires'].should eq(true)
allow(@access_token).to receive(:expires?) { true }
expect(subject.credentials['expires']).to eq(true)

@access_token.stub(:expires?) { false }
subject.credentials['expires'].should eq(false)
allow(@access_token).to receive(:expires?) { false }
expect(subject.credentials['expires']).to eq(false)
end

it 'returns the refresh token and expiry time when expiring' do
ten_mins_from_now = (Time.now + 360).to_i
@access_token.stub(:expires?) { true }
@access_token.stub(:refresh_token) { '321' }
@access_token.stub(:expires_at) { ten_mins_from_now }
subject.credentials['refresh_token'].should eq('321')
subject.credentials['expires_at'].should eq(ten_mins_from_now)
allow(@access_token).to receive(:expires?) { true }
allow(@access_token).to receive(:refresh_token) { '321' }
allow(@access_token).to receive(:expires_at) { ten_mins_from_now }
expect(subject.credentials['refresh_token']).to eq('321')
expect(subject.credentials['expires_at']).to eq(ten_mins_from_now)
end

it 'does not return the refresh token when it is nil and expiring' do
@access_token.stub(:expires?) { true }
@access_token.stub(:refresh_token) { nil }
subject.credentials['refresh_token'].should be_nil
subject.credentials.should_not have_key('refresh_token')
allow(@access_token).to receive(:expires?) { true }
allow(@access_token).to receive(:refresh_token) { nil }
expect(subject.credentials['refresh_token']).to be_nil
expect(subject.credentials).not_to have_key('refresh_token')
end

it 'does not return the refresh token when not expiring' do
@access_token.stub(:expires?) { false }
@access_token.stub(:refresh_token) { 'XXX' }
subject.credentials['refresh_token'].should be_nil
subject.credentials.should_not have_key('refresh_token')
allow(@access_token).to receive(:expires?) { false }
allow(@access_token).to receive(:refresh_token) { 'XXX' }
expect(subject.credentials['refresh_token']).to be_nil
expect(subject.credentials).not_to have_key('refresh_token')
end
end
end
18 changes: 9 additions & 9 deletions spec/support/shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@
describe '#client' do
it 'should be initialized with symbolized client_options' do
@options = { :client_options => { 'authorize_url' => 'https://example.com' } }
subject.client.options[:authorize_url].should == 'https://example.com'
expect(subject.client.options[:authorize_url]).to eq('https://example.com')
end
end

describe '#authorize_params' do
it 'should include any authorize params passed in the :authorize_params option' do
@options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
subject.authorize_params['foo'].should eq('bar')
subject.authorize_params['baz'].should eq('zip')
expect(subject.authorize_params['foo']).to eq('bar')
expect(subject.authorize_params['baz']).to eq('zip')
end

it 'should include top-level options that are marked as :authorize_options' do
@options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
subject.authorize_params['scope'].should eq('bar')
subject.authorize_params['foo'].should eq('baz')
expect(subject.authorize_params['scope']).to eq('bar')
expect(subject.authorize_params['foo']).to eq('baz')
end
end

describe '#token_params' do
it 'should include any authorize params passed in the :authorize_params option' do
@options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
subject.token_params['foo'].should eq('bar')
subject.token_params['baz'].should eq('zip')
expect(subject.token_params['foo']).to eq('bar')
expect(subject.token_params['baz']).to eq('zip')
end

it 'should include top-level options that are marked as :authorize_options' do
@options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
subject.token_params['scope'].should eq('bar')
subject.token_params['foo'].should eq('baz')
expect(subject.token_params['scope']).to eq('bar')
expect(subject.token_params['foo']).to eq('baz')
end
end
end

0 comments on commit e33bd04

Please sign in to comment.