Skip to content

Commit

Permalink
Bump rspec to 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiob committed Jun 2, 2014
1 parent 008c5cb commit 51c404d
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 64 deletions.
20 changes: 12 additions & 8 deletions Gemfile.lock
Expand Up @@ -29,14 +29,18 @@ GEM
rake (10.3.1)
rest-client (1.6.7)
mime-types (>= 1.16)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.8)
rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6)
rspec (3.0.0)
rspec-core (~> 3.0.0)
rspec-expectations (~> 3.0.0)
rspec-mocks (~> 3.0.0)
rspec-core (3.0.0)
rspec-support (~> 3.0.0)
rspec-expectations (3.0.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.0.0)
rspec-mocks (3.0.0)
rspec-support (~> 3.0.0)
rspec-support (3.0.0)
simplecov (0.8.2)
docile (~> 1.1.0)
multi_json
Expand Down
2 changes: 1 addition & 1 deletion spec/associations/device_auth/playlist_items_spec.rb
Expand Up @@ -57,7 +57,7 @@
describe '#add_videos' do
context 'given one existing and one unknown video' do
let(:video_ids) { ['MESycYJytkU', 'not-a-video'] }
it { expect(@playlist.add_videos video_ids).to have(2).items }
it { expect(@playlist.add_videos(video_ids).length).to eq 2 }
it { expect{@playlist.add_videos video_ids}.to change{@playlist.playlist_items.count}.by(1) }
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/associations/device_auth/ratings_spec.rb
Expand Up @@ -9,19 +9,19 @@
context 'that I like' do
before { video.like }
it { expect(video).to be_liked }
it { expect(video.dislike).to be_true }
it { expect(video.dislike).to be true }
end

context 'that I dislike' do
before { video.dislike }
it { expect(video).not_to be_liked }
it { expect(video.like).to be_true }
it { expect(video.like).to be true }
end

context 'that I am indifferent to' do
before { video.unlike }
it { expect(video).not_to be_liked }
it { expect(video.like).to be_true }
it { expect(video.like).to be true }
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/associations/device_auth/subscriptions_spec.rb
Expand Up @@ -11,14 +11,14 @@

context 'that I am not subscribed to' do
before { channel.unsubscribe }
it { expect(channel.subscribed?).to be_false }
it { expect(channel.subscribe!).to be_true }
it { expect(channel.subscribed?).to be false }
it { expect(channel.subscribe!).to be_truthy }
end

context 'that I am subscribed to' do
before { channel.subscribe }
it { expect(channel.subscribed?).to be_true }
it { expect(channel.unsubscribe!).to be_true }
it { expect(channel.subscribed?).to be true }
it { expect(channel.unsubscribe!).to be_truthy }
end
end

Expand Down
24 changes: 11 additions & 13 deletions spec/collections/earnings_spec.rb
Expand Up @@ -4,36 +4,34 @@
describe Yt::Collections::Earnings do
subject(:collection) { Yt::Collections::Earnings.new parent: channel }
let(:channel) { Yt::Channel.new id: 'UCxO1tY8h1AhOz0T4ENwmpow' }
let(:message) { {response_body: {error: {errors: [error]}}}.to_json }
let(:msg) { {response_body: {error: {errors: [error]}}}.to_json }
let(:error) { {reason: 'badRequest', message: message} }
let(:message) { 'Invalid query. Query did not conform to the expectations.' }
let(:date) { 1.day.ago.to_date }
let(:dollars) { 10 }
before { expect(collection).to behave }

describe '#within' do
context 'given YouTube responds with a list of earnings' do
before { collection.stub(:flat_map).and_return [date, dollars] }
let(:behave) { receive(:flat_map).and_return [date, dollars] }

it { expect(collection.within(date..date)[date]).to eq dollars }
end

# NOTE: This test is just a reflection of YouTube irrational behavior
# of raising a 400 error once in a while when retrieving earnings.
# Hopefully this will get fixed and this code (and test) removed.
context 'given YouTube responds with "Invalid query" the first time' do
let(:msg) { 'Invalid query. Query did not conform to the expectations.' }
let(:error) { {reason: 'badRequest', message: msg} }
before do
collection.stub :flat_map do
collection.stub(:flat_map).and_return [date, dollars]
raise Yt::Error, message
end
end
let(:behave) { receive(:flat_map) do
expect(collection).to receive(:flat_map).and_return [date, dollars]
raise Yt::Error, msg
end}

it { expect(collection.within(date..date)[date]).to eq dollars }
end

context 'given YouTube responds with "Invalid query" the second time' do
let(:msg) { 'Invalid query. Query did not conform to the expectations.' }
let(:error) { {reason: 'badRequest', message: msg} }
before { collection.stub(:flat_map).and_raise Yt::Error, message }
let(:behave) { receive(:flat_map).twice.and_raise Yt::Error, msg }

it { expect{collection.within date..date}.to raise_error Yt::Error }
end
Expand Down
9 changes: 5 additions & 4 deletions spec/collections/playlist_items_spec.rb
Expand Up @@ -7,35 +7,36 @@
let(:playlist) { Yt::Playlist.new id: 'LLxO1tY8h1AhOz0T4ENwmpow' }
let(:attrs) { {id: 'MESycYJytkU', kind: :video} }
let(:msg) { {response_body: {error: {errors: [{reason: reason}]}}}.to_json }
before { expect(collection).to behave }

describe '#insert' do
let(:playlist_item) { Yt::PlaylistItem.new }

context 'given an existing video' do
before { collection.stub(:do_insert).and_return playlist_item }
let(:behave) { receive(:do_insert).and_return playlist_item }

it { expect(collection.insert attrs).to eq playlist_item }
end

context 'given an unknown video' do
let(:reason) { 'videoNotFound' }
before { collection.stub(:do_insert).and_raise Yt::Error, msg }
let(:behave) { receive(:do_insert).and_raise Yt::Error, msg }

it { expect{collection.insert attrs}.to fail.with 'videoNotFound' }
it { expect{collection.insert attrs, ignore_errors: true}.not_to fail }
end

context 'given a forbidden video' do
let(:reason) { 'forbidden' }
before { collection.stub(:do_insert).and_raise Yt::Error, msg }
let(:behave) { receive(:do_insert).and_raise Yt::Error, msg }

it { expect{collection.insert attrs}.to fail.with 'forbidden' }
it { expect{collection.insert attrs, ignore_errors: true}.not_to fail }
end
end

describe '#delete_all' do
before { collection.stub(:do_delete_all).and_return [true] }
let(:behave) { receive(:do_delete_all).and_return [true] }

it { expect(collection.delete_all).to eq [true] }
end
Expand Down
7 changes: 4 additions & 3 deletions spec/collections/playlists_spec.rb
Expand Up @@ -3,23 +3,24 @@

describe Yt::Collections::Playlists do
subject(:collection) { Yt::Collections::Playlists.new }
before { expect(collection).to behave }

describe '#insert' do
let(:playlist) { Yt::Playlist.new }
# TODO: separate stubs to show options translate into do_insert params
before { collection.stub(:do_insert).and_return playlist }
let(:behave) { receive(:do_insert).and_return playlist }

it { expect(collection.insert).to eq playlist }
end

describe '#delete_all' do
before { collection.stub(:do_delete_all).and_return [true] }
let(:behave) { receive(:do_delete_all).and_return [true] }

it { expect(collection.delete_all).to eq [true] }
end

describe '#delete_all' do
before { collection.stub(:do_delete_all).and_return [true] }
let(:behave) { receive(:do_delete_all).and_return [true] }

it { expect(collection.delete_all).to eq [true] }
end
Expand Down
9 changes: 5 additions & 4 deletions spec/collections/subscriptions_spec.rb
Expand Up @@ -3,28 +3,29 @@

describe Yt::Collections::Subscriptions do
subject(:collection) { Yt::Collections::Subscriptions.new }
before { collection.stub :throttle }
let(:msg) { {response_body: {error: {errors: [{reason: reason}]}}}.to_json }
before { expect(collection).to receive :throttle }
before { expect(collection).to behave }

describe '#insert' do
context 'given a new subscription' do
let(:subscription) { Yt::Subscription.new }
before { collection.stub(:do_insert).and_return subscription }
let(:behave) { receive(:do_insert).and_return subscription }

it { expect(collection.insert).to eq subscription }
end

context 'given a duplicate subscription' do
let(:reason) { 'subscriptionDuplicate' }
before { collection.stub(:do_insert).and_raise Yt::Error, msg }
let(:behave) { receive(:do_insert).and_raise Yt::Error, msg }

it { expect{collection.insert}.to fail.with 'subscriptionDuplicate' }
it { expect{collection.insert ignore_errors: true}.not_to fail }
end
end

describe '#delete_all' do
before { collection.stub(:do_delete_all).and_return [true] }
let(:behave) { receive(:do_delete_all).and_return [true] }

it { expect(collection.delete_all).to eq [true] }
end
Expand Down
20 changes: 10 additions & 10 deletions spec/models/annotation_spec.rb
Expand Up @@ -15,19 +15,19 @@
} }

context 'given an annotation located above N% of the video height' do
it { expect(annotation.above? 50).to be_true }
it { expect(annotation.below? 50).to be_false }
it { expect(annotation.above? 50).to be true }
it { expect(annotation.below? 50).to be_falsey }
end

context 'given an annotation located below N% of the video height' do
it { expect(annotation.above? 5).to be_false }
it { expect(annotation.below? 5).to be_true }
it { expect(annotation.above? 5).to be_falsey }
it { expect(annotation.below? 5).to be true }
end

context 'given an annotation without explicit location' do
let(:xml) { '<segment></segment>' }
it { expect(annotation.above? 50).to be_false }
it { expect(annotation.below? 50).to be_false }
it { expect(annotation.above? 50).to be_falsey }
it { expect(annotation.below? 50).to be_falsey }
end
end

Expand Down Expand Up @@ -116,10 +116,10 @@
</movingRegion>
</segment>
} }
it { expect(annotation.starts_after? 3600).to be_true }
it { expect(annotation.starts_after? 3610).to be_false }
it { expect(annotation.starts_before? 3600).to be_false }
it { expect(annotation.starts_before? 3610).to be_true }
it { expect(annotation.starts_after? 3600).to be true }
it { expect(annotation.starts_after? 3610).to be_falsey }
it { expect(annotation.starts_before? 3600).to be_falsey }
it { expect(annotation.starts_before? 3610).to be true }
end

context 'given an annotation without timestamps' do
Expand Down
4 changes: 2 additions & 2 deletions spec/models/playlist_item_spec.rb
Expand Up @@ -23,9 +23,9 @@
let(:attrs) { {id: 'playlist-item-id'} }

context 'given an existing playlist item' do
before { playlist_item.stub(:do_delete).and_yield }
before { expect(playlist_item).to receive(:do_delete).and_yield }

it { expect(playlist_item.delete).to be_true }
it { expect(playlist_item.delete).to be true }
it { expect{playlist_item.delete}.to change{playlist_item.exists?} }
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/models/playlist_spec.rb
Expand Up @@ -32,19 +32,19 @@

describe '#update' do
let(:attrs) { {id: 'PLSWYkYzOr', snippet: {'title'=>'old'}, status: {"privacyStatus"=>"public"}} }
before { playlist.stub(:do_update).and_yield 'snippet'=>{'title'=>'new'} }
before { expect(playlist).to receive(:do_update).and_yield 'snippet'=>{'title'=>'new'} }

it { expect(playlist.update title: 'new').to be_true }
it { expect(playlist.update title: 'new').to be true }
it { expect{playlist.update title: 'new'}.to change{playlist.title} }
end

describe '#delete' do
let(:attrs) { {id: 'PLSWYkYzOr'} }

context 'given an existing playlist' do
before { playlist.stub(:do_delete).and_yield }
before { expect(playlist).to receive(:do_delete).and_yield }

it { expect(playlist.delete).to be_true }
it { expect(playlist.delete).to be true }
it { expect{playlist.delete}.to change{playlist.exists?} }
end
end
Expand Down
3 changes: 1 addition & 2 deletions spec/models/rating_spec.rb
Expand Up @@ -5,9 +5,8 @@
subject(:rating) { Yt::Rating.new }

describe '#update' do
before { rating.stub(:do_update).and_yield }
before { expect(rating).to receive(:do_update).and_yield }

it { expect(rating.update :like).to be_true }
it { expect{rating.update :like}.to change{rating.rating} }
end
end
4 changes: 2 additions & 2 deletions spec/models/request_spec.rb
Expand Up @@ -4,8 +4,8 @@
describe Yt::Request do
subject(:request) { Yt::Request.new attrs }
let(:attrs) { {host: 'example.com'} }
before { Net::HTTP.stub(:start).and_return response }
before { response.stub(:body) }
before { expect(Net::HTTP).to receive(:start).and_return response }
before { allow(response).to receive(:body) }

describe '#run' do
context 'given a request that returns a 500 code' do
Expand Down
7 changes: 4 additions & 3 deletions spec/models/subscription_spec.rb
Expand Up @@ -19,17 +19,18 @@

describe '#delete' do
let(:id) { 'CBl6OoF0BpiV' }
before { expect(subscription).to behave }

context 'given an existing subscription' do
before { subscription.stub(:do_delete).and_yield }
let(:behave) { receive(:do_delete).and_yield }

it { expect(subscription.delete).to be_true }
it { expect(subscription.delete).to be true }
it { expect{subscription.delete}.to change{subscription.exists?} }
end

context 'given an unknown subscription' do
let(:reason) { 'subscriptionNotFound' }
before { subscription.stub(:do_delete).and_raise Yt::Error, msg }
let(:behave) { receive(:do_delete).and_raise Yt::Error, msg }

it { expect{subscription.delete}.to fail.with 'subscriptionNotFound' }
it { expect{subscription.delete ignore_errors: true}.not_to fail }
Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -11,5 +11,4 @@

RSpec.configure do |config|
config.order = 'random'
config.treat_symbols_as_metadata_keys_with_true_values = true
end
1 change: 1 addition & 0 deletions spec/support/fail_matcher.rb
@@ -1,4 +1,5 @@
RSpec::Matchers.define :fail do
supports_block_expectations
match do |block|
begin
block.call
Expand Down

0 comments on commit 51c404d

Please sign in to comment.