From 51c404d0670c718271b3a5ae2838dd9d25211a5c Mon Sep 17 00:00:00 2001 From: claudiob Date: Mon, 2 Jun 2014 16:08:45 -0700 Subject: [PATCH] Bump rspec to 3.0 --- Gemfile.lock | 20 +++++++++------- .../device_auth/playlist_items_spec.rb | 2 +- spec/associations/device_auth/ratings_spec.rb | 6 ++--- .../device_auth/subscriptions_spec.rb | 8 +++---- spec/collections/earnings_spec.rb | 24 +++++++++---------- spec/collections/playlist_items_spec.rb | 9 +++---- spec/collections/playlists_spec.rb | 7 +++--- spec/collections/subscriptions_spec.rb | 9 +++---- spec/models/annotation_spec.rb | 20 ++++++++-------- spec/models/playlist_item_spec.rb | 4 ++-- spec/models/playlist_spec.rb | 8 +++---- spec/models/rating_spec.rb | 3 +-- spec/models/request_spec.rb | 4 ++-- spec/models/subscription_spec.rb | 7 +++--- spec/spec_helper.rb | 1 - spec/support/fail_matcher.rb | 1 + 16 files changed, 69 insertions(+), 64 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index d92bae72..f1b623cb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/spec/associations/device_auth/playlist_items_spec.rb b/spec/associations/device_auth/playlist_items_spec.rb index e4ca9811..7afda50b 100644 --- a/spec/associations/device_auth/playlist_items_spec.rb +++ b/spec/associations/device_auth/playlist_items_spec.rb @@ -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 diff --git a/spec/associations/device_auth/ratings_spec.rb b/spec/associations/device_auth/ratings_spec.rb index ee8803bd..10b9599f 100644 --- a/spec/associations/device_auth/ratings_spec.rb +++ b/spec/associations/device_auth/ratings_spec.rb @@ -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 diff --git a/spec/associations/device_auth/subscriptions_spec.rb b/spec/associations/device_auth/subscriptions_spec.rb index 1ce4c063..30a251e2 100644 --- a/spec/associations/device_auth/subscriptions_spec.rb +++ b/spec/associations/device_auth/subscriptions_spec.rb @@ -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 diff --git a/spec/collections/earnings_spec.rb b/spec/collections/earnings_spec.rb index 6ac14fad..9c823853 100644 --- a/spec/collections/earnings_spec.rb +++ b/spec/collections/earnings_spec.rb @@ -4,13 +4,17 @@ 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 @@ -18,22 +22,16 @@ # 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 diff --git a/spec/collections/playlist_items_spec.rb b/spec/collections/playlist_items_spec.rb index 4d4c00d7..6be674ef 100644 --- a/spec/collections/playlist_items_spec.rb +++ b/spec/collections/playlist_items_spec.rb @@ -7,19 +7,20 @@ 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 } @@ -27,7 +28,7 @@ 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 } @@ -35,7 +36,7 @@ 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 diff --git a/spec/collections/playlists_spec.rb b/spec/collections/playlists_spec.rb index a88a13b3..53a7d21b 100644 --- a/spec/collections/playlists_spec.rb +++ b/spec/collections/playlists_spec.rb @@ -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 diff --git a/spec/collections/subscriptions_spec.rb b/spec/collections/subscriptions_spec.rb index 25aae6b0..50cd03e6 100644 --- a/spec/collections/subscriptions_spec.rb +++ b/spec/collections/subscriptions_spec.rb @@ -3,20 +3,21 @@ 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 } @@ -24,7 +25,7 @@ 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 diff --git a/spec/models/annotation_spec.rb b/spec/models/annotation_spec.rb index 19922545..41c01a50 100644 --- a/spec/models/annotation_spec.rb +++ b/spec/models/annotation_spec.rb @@ -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) { '' } - 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 @@ -116,10 +116,10 @@ } } - 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 diff --git a/spec/models/playlist_item_spec.rb b/spec/models/playlist_item_spec.rb index 6885dddb..a112f0e6 100644 --- a/spec/models/playlist_item_spec.rb +++ b/spec/models/playlist_item_spec.rb @@ -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 diff --git a/spec/models/playlist_spec.rb b/spec/models/playlist_spec.rb index 0b2b6357..eaefa322 100644 --- a/spec/models/playlist_spec.rb +++ b/spec/models/playlist_spec.rb @@ -32,9 +32,9 @@ 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 @@ -42,9 +42,9 @@ 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 diff --git a/spec/models/rating_spec.rb b/spec/models/rating_spec.rb index 83d253af..fa3d9ae6 100644 --- a/spec/models/rating_spec.rb +++ b/spec/models/rating_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index 89ab5da5..f7967542 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -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 diff --git a/spec/models/subscription_spec.rb b/spec/models/subscription_spec.rb index 586a2b37..41321b13 100644 --- a/spec/models/subscription_spec.rb +++ b/spec/models/subscription_spec.rb @@ -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 } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9756c994..26bf3a47 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -11,5 +11,4 @@ RSpec.configure do |config| config.order = 'random' - config.treat_symbols_as_metadata_keys_with_true_values = true end \ No newline at end of file diff --git a/spec/support/fail_matcher.rb b/spec/support/fail_matcher.rb index e04f0d07..afefbd89 100644 --- a/spec/support/fail_matcher.rb +++ b/spec/support/fail_matcher.rb @@ -1,4 +1,5 @@ RSpec::Matchers.define :fail do + supports_block_expectations match do |block| begin block.call