spec/integration/integration_spec.rb in shutl_auth-0.8.5 vs spec/integration/integration_spec.rb in shutl_auth-0.9.0

- old
+ new

@@ -1,74 +1,62 @@ require 'spec_helper' describe "Integration" do - subject { Shutl::Auth } + subject { Shutl::Auth::AccessTokenRequest.new opts } + let(:client_id) { "QUOTE_SERVICE_CLIENT_ID" } + let(:url) { "http://localhost:3000" } - def set_auth - Shutl::Auth.config do |c| - c.url = "http://localhost:3000" - c.client_id = "QUOTE_SERVICE_CLIENT_ID" - c.client_secret = "QUOTE_SERVICE_CLIENT_SECRET" - end + let(:opts) do + { + client_id: client_id, + client_secret: "QUOTE_SERVICE_CLIENT_SECRET", + url: url + } end - before do - set_auth - end - context 'successful request to authentication service' do let(:token) { 's_CagcDP8PdsGb1B0iyLvNtanSxqZeQDQtGiIYtctKzyLzxAymhe-zGJwUrjxKQpO9EUdizDT3tqLt-iFeHapg' } specify do VCR.use_cassette 'get_token' do - Shutl::Auth.access_token!.should == token + subject.access_token.should == token end end - specify "with invalid auth service url" do - Shutl::Auth.url = '' + describe "with invalid auth service url" do + specify do + expect { Shutl::Auth::AccessTokenRequest.new(client_id: '', client_secret: '', url: '').access_token}.to raise_error Shutl::Auth::InvalidUrl + end - expect {Shutl::Auth.access_token!}.to raise_error Shutl::Auth::InvalidUrl - - Shutl::Auth.url = 'http://' - expect {Shutl::Auth.access_token!}.to raise_error Shutl::Auth::InvalidUrl - - Shutl::Auth.url = 'http://localhost:3000' - - VCR.use_cassette 'get_token' do - Shutl::Auth.access_token!.should == token + specify do + expect {Shutl::Auth::AccessTokenRequest.new(client_id: '', client_secret: '', url: 'http://').access_token}.to raise_error Shutl::Auth::InvalidUrl end end specify "with 500 from auth server" do - set_auth - - stub_request(:post, /.*#{Shutl::Auth.url}.*/).to_return( + stub_request(:post, /.*#{url}.*/).to_return( { body: '', status: 500, headers: {"CONTENT_TYPE" => 'application/json'}} ) Airbrake.should_receive(:notify) - expect{ Shutl::Auth.access_token!}.to raise_error Shutl::Auth::InternalServerError + expect{ subject.access_token}.to raise_error Shutl::Auth::InternalServerError end - specify "with invalid credentials" do - set_auth - Shutl::Auth.client_id = 'egg' + describe "with invalid credentials" do + let(:client_id) { 'egg' } - VCR.use_cassette 'invalid_credentials' do - expect { Shutl::Auth.access_token!}.to raise_error Shutl::Auth::InvalidCredentials - end + specify do + VCR.use_cassette 'invalid_credentials' do + expect { subject.access_token}.to raise_error Shutl::Auth::InvalidCredentials + end - set_auth - Shutl::Auth.client_id = 'egg' - - VCR.use_cassette 'invalid_credentials' do - expect { Shutl::Auth.access_token!}.to raise_error Shutl::Auth::InvalidCredentials + VCR.use_cassette 'invalid_credentials' do + expect { subject.access_token}.to raise_error Shutl::Auth::InvalidCredentials + end end - end end end