Skip to content

Commit

Permalink
Push spec and lib onto the
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed May 29, 2011
1 parent 58d7687 commit 415c05b
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -9,7 +9,7 @@ RSpec::Core::RakeTask.new(:spec)
task :default => :spec
task :test => :spec

require 'rake/rdoctask'
require 'rdoc/task'
Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = "oauth2 #{OAuth2::VERSION}"
Expand Down
6 changes: 2 additions & 4 deletions spec/spec_helper.rb → spec/helper.rb
@@ -1,7 +1,5 @@
require "rubygems"
require "bundler"
Bundler.setup

$:.unshift File.expand_path('..', __FILE__)
$:.unshift File.expand_path('../../lib', __FILE__)
require 'simplecov'
SimpleCov.start
require 'oauth2'
Expand Down
2 changes: 1 addition & 1 deletion spec/oauth2/access_token_spec.rb
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'helper'

VERBS = [:get, :post, :put, :delete]

Expand Down
20 changes: 10 additions & 10 deletions spec/oauth2/client_spec.rb
@@ -1,9 +1,9 @@
require 'spec_helper'
require 'helper'

describe OAuth2::Client do
let!(:error_value) {'invalid_token'}
let!(:error_description_value) {'bad bad token'}

subject do
OAuth2::Client.new('abc', 'def', :site => 'https://api.example.com') do |builder|
builder.adapter :test do |stub|
Expand Down Expand Up @@ -81,7 +81,7 @@
subject.options[:"#{url_type}_url"] = '/oauth/custom'
subject.send("#{url_type}_url").should == 'https://api.example.com/oauth/custom'
end

it "allows a different host than the site" do
subject.options[:"#{url_type}_url"] = 'https://api.foo.com/oauth/custom'
subject.send("#{url_type}_url").should == 'https://api.foo.com/oauth/custom'
Expand All @@ -93,32 +93,32 @@
it "works with a null response body" do
subject.request(:get, 'empty_get').body.should == ''
end

it "returns on a successful response" do
response = subject.request(:get, '/success')
response.body.should == 'yay'
response.status.should == 200
response.headers.should == {'Content-Type' => 'text/awesome'}
end

it "posts a body" do
response = subject.request(:post, '/reflect', :body => 'foo=bar')
response.body.should == 'foo=bar'
end

it "follows redirects properly" do
response = subject.request(:get, '/redirect')
response.body.should == 'yay'
response.status.should == 200
response.headers.should == {'Content-Type' => 'text/awesome'}
end

it "redirects using GET on a 303" do
response = subject.request(:post, '/redirect', :body => 'foo=bar')
response.body.should be_empty
response.status.should == 200
end

it "obeys the :max_redirects option" do
max_redirects = subject.options[:max_redirects]
subject.options[:max_redirects] = 0
Expand All @@ -135,13 +135,13 @@
response.headers.should == {'Content-Type' => 'text/plain'}
response.error.should_not be_nil
end

%w(/unauthorized /conflict /error).each do |error_path|
it "raises OAuth2::Error on error response to path #{error_path}" do
lambda {subject.request(:get, error_path)}.should raise_error(OAuth2::Error)
end
end

it 'parses OAuth2 standard error response' do
begin
subject.request(:get, '/unauthorized')
Expand Down
8 changes: 4 additions & 4 deletions spec/oauth2/response_spec.rb
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'helper'

describe OAuth2::Response do

Expand Down Expand Up @@ -40,12 +40,12 @@
subject.parsed['answer'].should == 42
end
end
it 'returns original body it cannot be parsed' do

it 'returns original body it cannot be parsed' do
body = 'blah'
response = double('response', :body => body, :headers => {}, :status => 400)
subject = Response.new(response)
subject.parsed.should == body
end
end
end
end
22 changes: 11 additions & 11 deletions spec/oauth2/strategy/auth_code_spec.rb
@@ -1,11 +1,11 @@
require 'spec_helper'
require 'helper'

describe OAuth2::Strategy::AuthCode do
let(:code) { 'sushi' }
let(:kvform_token) { 'expires_in=600&access_token=salmon&refresh_token=trout&extra_param=steve' }
let(:facebook_token) { kvform_token.gsub('_in', '') }
let(:json_token) { MultiJson.encode(:expires_in => 600, :access_token => 'salmon', :refresh_token => 'trout', :extra_param => 'steve') }

let(:client) do
OAuth2::Client.new('abc', 'def', :site => 'http://api.example.com') do |builder|
builder.adapter :test do |stub|
Expand Down Expand Up @@ -39,17 +39,17 @@
it 'should include the client_id' do
subject.authorize_url.should be_include('client_id=abc')
end

it 'should include the type' do
subject.authorize_url.should be_include('response_type=code')
end

it 'should include passed in options' do
cb = 'http://myserver.local/oauth/callback'
subject.authorize_url(:redirect_uri => cb).should be_include("redirect_uri=#{Rack::Utils.escape(cb)}")
end
end

%w(json formencoded from_facebook).each do |mode|
[:get, :post].each do |verb|
describe "#get_token (#{mode}, access_token_method=#{verb}" do
Expand All @@ -58,27 +58,27 @@
client.options[:token_method] = verb
@access = subject.get_token(code)
end

it 'returns AccessToken with same Client' do
@access.client.should == client
end

it 'returns AccessToken with #token' do
@access.token.should == 'salmon'
end

it 'returns AccessToken with #refresh_token' do
@access.refresh_token.should == 'trout'
end

it 'returns AccessToken with #expires_in' do
@access.expires_in.should == 600
end

it 'returns AccessToken with #expires_at' do
@access.expires_at.should be_kind_of(Fixnum)
end

it 'returns AccessToken with params accessible via []' do
@access['extra_param'].should == 'steve'
end
Expand Down
2 changes: 1 addition & 1 deletion spec/oauth2/strategy/base_spec.rb
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'helper'

describe OAuth2::Strategy::Base do
it 'should initialize with a Client' do
Expand Down
2 changes: 1 addition & 1 deletion spec/oauth2/strategy/password_spec.rb
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'helper'

describe OAuth2::Strategy::Password do
let(:client) do
Expand Down

0 comments on commit 415c05b

Please sign in to comment.