Permalink
Browse files

Convert to the new RSpec expectation syntax

  • Loading branch information...
sferik committed Oct 10, 2012
1 parent cfd4152 commit 94772cfbfe664402ba1cb9dcf7e37906ad7ae712
View
2 .rspec
@@ -1,2 +1,2 @@
--color
---order random
+--order random
@@ -5,26 +5,26 @@ module Test
module StrategyMacros
def sets_an_auth_hash
- it 'should set an auth hash' do
- last_request.env['omniauth.auth'].should be_kind_of(Hash)
+ it "sets an auth hash" do
+ expect(last_request.env['omniauth.auth']).to be_kind_of(Hash)
end
end
def sets_provider_to(provider)
- it "should set the provider to #{provider}" do
- (last_request.env['omniauth.auth'] || {})['provider'].should == provider
+ it "sets the provider to #{provider}" do
+ expect((last_request.env['omniauth.auth'] || {})['provider']).to eq provider
end
end
def sets_uid_to(uid)
- it "should set the UID to #{uid}" do
- (last_request.env['omniauth.auth'] || {})['uid'].should == uid
+ it "sets the UID to #{uid}" do
+ expect((last_request.env['omniauth.auth'] || {})['uid']).to eq uid
end
end
def sets_user_info_to(user_info)
- it "should set the user_info to #{user_info}" do
- (last_request.env['omniauth.auth'] || {})['user_info'].should == user_info
+ it "sets the user_info to #{user_info}" do
+ expect((last_request.env['omniauth.auth'] || {})['user_info']).to eq user_info
end
end
end
@@ -2,36 +2,36 @@
describe OmniAuth::AuthHash do
subject{ OmniAuth::AuthHash.new }
- it 'should convert a supplied info key into an InfoHash object' do
+ it "converts a supplied info key into an InfoHash object" do
subject.info = {:first_name => 'Awesome'}
- subject.info.should be_kind_of(OmniAuth::AuthHash::InfoHash)
- subject.info.first_name.should == 'Awesome'
+ expect(subject.info).to be_kind_of(OmniAuth::AuthHash::InfoHash)
+ expect(subject.info.first_name).to eq('Awesome')
end
- describe '#valid?' do
+ describe "#valid?" do
subject{ OmniAuth::AuthHash.new(:uid => '123', :provider => 'example', :info => {:name => 'Steven'}) }
- it 'should be valid with the right parameters' do
- subject.should be_valid
+ it "is valid with the right parameters" do
+ expect(subject).to be_valid
end
- it 'should require a uid' do
+ it "requires a uid" do
subject.uid = nil
- subject.should_not be_valid
+ expect(subject).not_to be_valid
end
- it 'should require a provider' do
+ it "requires a provider" do
subject.provider = nil
- subject.should_not be_valid
+ expect(subject).not_to be_valid
end
- it 'should require a name in the user info hash' do
+ it "requires a name in the user info hash" do
subject.info.name = nil
- subject.should_not be_valid?
+ expect(subject).not_to be_valid?
end
end
- describe '#name' do
+ describe "#name" do
subject{ OmniAuth::AuthHash.new(
:info => {
:name => 'Phillip J. Fry',
@@ -41,67 +41,67 @@
:email => 'fry@planetexpress.com'
})}
- it 'should default to the name key' do
- subject.info.name.should == 'Phillip J. Fry'
+ it "defaults to the name key" do
+ expect(subject.info.name).to eq('Phillip J. Fry')
end
- it 'should fall back to go to first_name last_name concatenation' do
+ it "falls back to go to first_name last_name concatenation" do
subject.info.name = nil
- subject.info.name.should == 'Phillip Fry'
+ expect(subject.info.name).to eq('Phillip Fry')
end
- it 'should display only a first or last name if only that is available' do
+ it "displays only a first or last name if only that is available" do
subject.info.name = nil
subject.info.first_name = nil
- subject.info.name.should == 'Fry'
+ expect(subject.info.name).to eq('Fry')
end
- it 'should display the nickname if no name, first, or last is available' do
+ it "displays the nickname if no name, first, or last is available" do
subject.info.name = nil
%w(first_name last_name).each{|k| subject.info[k] = nil}
- subject.info.name.should == 'meatbag'
+ expect(subject.info.name).to eq('meatbag')
end
- it 'should display the email if no name, first, last, or nick is available' do
+ it "displays the email if no name, first, last, or nick is available" do
subject.info.name = nil
%w(first_name last_name nickname).each{|k| subject.info[k] = nil}
- subject.info.name.should == 'fry@planetexpress.com'
+ expect(subject.info.name).to eq('fry@planetexpress.com')
end
end
- describe '#to_hash' do
+ describe "#to_hash" do
subject{ OmniAuth::AuthHash.new(:uid => '123', :provider => 'test', :name => 'Bob Example')}
let(:hash){ subject.to_hash }
- it 'should be a plain old hash' do
- hash.class.should == ::Hash
+ it "is a plain old hash" do
+ expect(hash.class).to eq(::Hash)
end
- it 'should have string keys' do
- hash.keys.should be_include('uid')
+ it "has string keys" do
+ expect(hash.keys).to be_include('uid')
end
- it 'should convert an info hash as well' do
+ it "converts an info hash as well" do
subject.info = {:first_name => 'Bob', :last_name => 'Example'}
- subject.info.class.should == OmniAuth::AuthHash::InfoHash
- subject.to_hash['info'].class.should == ::Hash
+ expect(subject.info.class).to eq(OmniAuth::AuthHash::InfoHash)
+ expect(subject.to_hash['info'].class).to eq(::Hash)
end
- it 'should supply the calculated name in the converted hash' do
+ it "supplies the calculated name in the converted hash" do
subject.info = {:first_name => 'Bob', :last_name => 'Examplar'}
- hash['info']['name'].should == 'Bob Examplar'
+ expect(hash['info']['name']).to eq('Bob Examplar')
end
- it 'should not pollute the URL hash with "name" etc' do
+ it "does not pollute the URL hash with 'name' etc" do
subject.info = {'urls' => {'Homepage' => "http://homepage.com"}}
- subject.to_hash['info']['urls'].should == {'Homepage' => "http://homepage.com"}
+ expect(subject.to_hash['info']['urls']).to eq({'Homepage' => "http://homepage.com"})
end
end
describe OmniAuth::AuthHash::InfoHash do
- describe '#valid?' do
- it 'should be valid if there is a name' do
- OmniAuth::AuthHash::InfoHash.new(:name => 'Awesome').should be_valid
+ describe "#valid?" do
+ it "is valid if there is a name" do
+ expect(OmniAuth::AuthHash::InfoHash.new(:name => 'Awesome')).to be_valid
end
end
end
@@ -1,23 +1,25 @@
require File.expand_path('../../spec_helper', __FILE__)
describe OmniAuth::Builder do
- describe '#provider' do
- it 'should translate a symbol to a constant' do
+ describe "#provider" do
+ it "translates a symbol to a constant" do
OmniAuth::Strategies.should_receive(:const_get).with('MyStrategy').and_return(Class.new)
OmniAuth::Builder.new(nil) do
provider :my_strategy
end
end
- it 'should also just accept a class' do
+ it "accepts a class" do
class ::ExampleClass; end
- lambda{ OmniAuth::Builder.new(nil) do
- provider ::ExampleClass
- end }.should_not raise_error
+ expect{
+ OmniAuth::Builder.new(nil) do
+ provider ::ExampleClass
+ end
+ }.not_to raise_error
end
- it "should raise a helpful LoadError message if it can't find the class" do
+ it "raises a helpful LoadError message if it can't find the class" do
expect {
OmniAuth::Builder.new(nil) do
provider :lorax
@@ -26,8 +28,8 @@ class ::ExampleClass; end
end
end
- describe '#options' do
- it 'should merge provided options in' do
+ describe "#options" do
+ it "merges provided options in" do
k = Class.new
b = OmniAuth::Builder.new(nil)
b.should_receive(:use).with(k, :foo => 'bar', :baz => 'tik')
@@ -36,7 +38,7 @@ class ::ExampleClass; end
b.provider k, :baz => 'tik'
end
- it 'should add an argument if no options are provided' do
+ it "adds an argument if no options are provided" do
k = Class.new
b = OmniAuth::Builder.new(nil)
b.should_receive(:use).with(k, :foo => 'bar')
@@ -3,19 +3,19 @@
describe OmniAuth::FailureEndpoint do
subject{ OmniAuth::FailureEndpoint }
- context 'development' do
+ context "development" do
before do
@rack_env = ENV['RACK_ENV']
ENV['RACK_ENV'] = 'development'
end
- it 'should raise out the error' do
+ it "raises out the error" do
expect do
subject.call('omniauth.error' => StandardError.new("Blah"))
end.to raise_error(StandardError, "Blah")
end
- it 'should raise out an OmniAuth::Error if no omniauth.error is set' do
+ it "raises out an OmniAuth::Error if no omniauth.error is set" do
expect{ subject.call('omniauth.error.type' => 'example') }.to raise_error(OmniAuth::Error, "example")
end
@@ -24,30 +24,30 @@
end
end
- context 'non-development' do
+ context "non-development" do
let(:env){ {'omniauth.error.type' => 'invalid_request',
'omniauth.error.strategy' => ExampleStrategy.new({}) } }
- it 'should be a redirect' do
+ it "is a redirect" do
status, head, body = *subject.call(env)
- status.should == 302
+ expect(status).to eq(302)
end
- it 'should include the SCRIPT_NAME' do
+ it "includes the SCRIPT_NAME" do
status, head, body = *subject.call(env.merge('SCRIPT_NAME' => '/random'))
- head['Location'].should == '/random/auth/failure?message=invalid_request&strategy=test'
+ expect(head['Location']).to eq('/random/auth/failure?message=invalid_request&strategy=test')
end
- it 'should respect configured path prefix' do
+ it "respects the configured path prefix" do
OmniAuth.config.stub(:path_prefix => '/boo')
status, head, body = *subject.call(env)
- head["Location"].should == '/boo/failure?message=invalid_request&strategy=test'
+ expect(head["Location"]).to eq('/boo/failure?message=invalid_request&strategy=test')
end
- it 'should include the origin (escaped) if one is provided' do
+ it "includes the origin (escaped) if one is provided" do
env.merge! 'omniauth.origin' => '/origin-example'
status, head, body = *subject.call(env)
- head['Location'].should be_include('&origin=%2Forigin-example')
+ expect(head['Location']).to be_include('&origin=%2Forigin-example')
end
end
-end
+end
View
@@ -1,23 +1,23 @@
require 'spec_helper'
describe OmniAuth::Form do
- describe '.build' do
- it 'should yield the instance when called with a block and argument' do
- OmniAuth::Form.build{|f| f.should be_kind_of(OmniAuth::Form)}
+ describe ".build" do
+ it "yields the instance when called with a block and argument" do
+ OmniAuth::Form.build{|f| expect(f).to be_kind_of(OmniAuth::Form)}
end
- it 'should evaluate in the instance when called with a block and no argument' do
- OmniAuth::Form.build{ self.class.should == OmniAuth::Form }
+ it "evaluates in the instance when called with a block and no argument" do
+ OmniAuth::Form.build{|f| expect(f.class).to eq(OmniAuth::Form)}
end
end
- describe '#initialize' do
- it 'the :url option should supply to the form that is built' do
- OmniAuth::Form.new(:url => '/awesome').to_html.should be_include("action='/awesome'")
+ describe "#initialize" do
+ it "sets the form action to the passed :url option" do
+ expect(OmniAuth::Form.new(:url => '/awesome').to_html).to be_include("action='/awesome'")
end
- it 'the :title option should set an H1 tag' do
- OmniAuth::Form.new(:title => 'Something Cool').to_html.should be_include('<h1>Something Cool</h1>')
+ it "sets an H1 tag from the passed :title option" do
+ expect(OmniAuth::Form.new(:title => 'Something Cool').to_html).to be_include('<h1>Something Cool</h1>')
end
end
end
Oops, something went wrong.

0 comments on commit 94772cf

Please sign in to comment.