Skip to content

Commit

Permalink
rspec 3 syntax changes
Browse files Browse the repository at this point in the history
* `allow().to receive`
* more `expect().to`s that I missed
  • Loading branch information
alxndr committed Dec 21, 2014
1 parent e074619 commit b72bf96
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion spec/controllers/lyrics_controller_spec.rb
Expand Up @@ -5,7 +5,7 @@
describe '#by_artist' do

before do
Artist.stub(:new) { mock_model(Artist, get_data: true, save: true, load_data: true, lyrem: true) }
allow(Artist).to receive(:new) { mock_model(Artist, get_data: true, save: true, load_data: true, lyrem: true) }
end

describe 'missing artist' do
Expand Down
2 changes: 1 addition & 1 deletion spec/features/lyrics_request_spec.rb
Expand Up @@ -9,7 +9,7 @@
end

it 'has a rel=canonical link' do
page.source.should match '<link rel="canonical" href="/text-from-lyrics-by/blind-faith" />'
expect(page.source).to match '<link rel="canonical" href="/text-from-lyrics-by/blind-faith" />'
end

describe 'analytics' do
Expand Down
6 changes: 3 additions & 3 deletions spec/features/static_request_spec.rb
Expand Up @@ -17,9 +17,9 @@

before do
fake_artist = FactoryGirl.build_stubbed :artist
fake_artist.stub(:name).and_return 'The Phish'
fake_artist.stub(:random_lyric).and_return "that's 119 to you and me"
Artist.stub(:find_or_create).and_return fake_artist
allow(fake_artist).to receive(:name).and_return 'The Phish'
allow(fake_artist).to receive(:random_lyric).and_return "that's 119 to you and me"
allow(Artist).to receive(:find_or_create).and_return fake_artist
end

it 'sends you to a new page' do
Expand Down
6 changes: 3 additions & 3 deletions spec/models/artist_spec.rb
Expand Up @@ -36,7 +36,7 @@
let(:phrases) { LYRICS }

before do
subject.stub(:fetch_new_song_lyrics).and_return(phrases)
allow(subject).to receive(:fetch_new_song_lyrics).and_return(phrases)
end

describe ':phrases' do
Expand Down Expand Up @@ -69,7 +69,7 @@
expect(sentence.class).to eq String
expect(sentence.split(' ').length).to be >= 2
%w(,, ., !, ?, ,. !. ?.).each do |punct_combo|
sentence.should_not include punct_combo
expect(sentence).not_to include punct_combo
end
end
end
Expand Down Expand Up @@ -180,7 +180,7 @@
describe 'when not already set' do

before do
subject.stub(:albums).and_return [
allow(subject).to receive(:albums).and_return [
{ 'songs' => ['foo', 'bar'] },
{ 'songs' => ['baz', 'Qux:Quux'] }
]
Expand Down
8 changes: 4 additions & 4 deletions spec/models/concerns/custom_array_spec.rb
Expand Up @@ -11,21 +11,21 @@ class TestCustomArray < Array
let(:test_array) { TestCustomArray.new(%w(foo bar baz qux)) }

it 'returns a string' do
test_array.join_after_regex(glue: ', ', regex: /a/).should be_a String
expect(test_array.join_after_regex(glue: ', ', regex: /a/)).to be_a String
end

describe 'matching regex' do
subject { test_array.join_after_regex(glue: ', ', regex: /o/) }
it 'inserts glue' do
subject.index('o,').should_not be nil
expect(subject.index('o,')).not_to be nil
end
end

describe 'not matching regex' do
subject { test_array.join_after_regex(glue: ', ', regex: /o/) }
it 'does not insert glue' do
subject.index('r,').should be nil
subject.index('z,').should be nil
expect(subject.index('r,')).to be nil
expect(subject.index('z,')).to be nil
end
end

Expand Down
28 changes: 14 additions & 14 deletions spec/models/concerns/custom_string_spec.rb
Expand Up @@ -8,14 +8,14 @@ class TestCustomString < String

describe '#capitalize_first_letter' do
it 'capitalizes the first letter' do
TestCustomString.new('þrettán').capitalize_first_letter.should == 'Þrettán'
TestCustomString.new('!!!1 bar').capitalize_first_letter.should == '!!!1 Bar'
TestCustomString.new('qux QUUX').capitalize_first_letter.should == 'Qux QUUX'
TestCustomString.new('QUX Quux').capitalize_first_letter.should == 'QUX Quux'
expect(TestCustomString.new('þrettán').capitalize_first_letter).to eq 'Þrettán'
expect(TestCustomString.new('!!!1 bar').capitalize_first_letter).to eq '!!!1 Bar'
expect(TestCustomString.new('qux QUUX').capitalize_first_letter).to eq 'Qux QUUX'
expect(TestCustomString.new('QUX Quux').capitalize_first_letter).to eq 'QUX Quux'
end

it 'does not double-capitalize' do
TestCustomString.new('Baz').capitalize_first_letter.should == 'Baz'
expect(TestCustomString.new('Baz').capitalize_first_letter).to eq 'Baz'
end
end

Expand Down Expand Up @@ -55,27 +55,27 @@ class TestCustomString < String
subject { test_string.to_slug }

it 'strips' do
subject[0].should_not == ' '
expect(subject[0]).not_to eq ' '
end
it 'downcases' do
subject['I'].should == nil
expect(subject['I']).to eq nil
end
it 'strips apostrophes' do
subject["'"].should == nil
expect(subject["'"]).to eq nil
end
it 'converts & -> and' do
subject['&'].should == nil
subject['and'].should_not == nil
expect(subject['&']).to eq nil
expect(subject['and']).not_to eq nil
end
it 'only comprises [a-z-]' do
subject.should match /^[a-z-]+$/
expect(subject).to match /^[a-z-]+$/
end
it 'does not have any double-hyphens' do
subject['--'].should == nil
expect(subject['--']).to eq nil
end
it 'starts and ends with a letter' do
subject.first.should match /[a-z]/
subject.last.should match /[a-z]/
expect(subject.first).to match /[a-z]/
expect(subject.last).to match /[a-z]/
end
end

Expand Down
8 changes: 4 additions & 4 deletions spec/models/musician_name_finder_spec.rb
Expand Up @@ -11,19 +11,19 @@

describe 'with a title' do
it 'should ask google' do
Google::Search::Web.should_receive(:new).and_return(results)
expect(Google::Search::Web).to receive(:new).and_return(results)
MusicianNameFinder.look_up('name')
end

it 'should trim title' do
Google::Search::Web.stub(:new).and_return(results)
MusicianNameFinder.look_up('name').should == "A Musician 'n stuff"
allow(Google::Search::Web).to receive(:new).and_return(results)
expect(MusicianNameFinder.look_up('name')).to eq "A Musician 'n stuff"
end
end

describe 'without a title' do
it 'should raise' do
Google::Search::Web.should_receive(:new).and_return([])
expect(Google::Search::Web).to receive(:new).and_return([])
expect { MusicianNameFinder.look_up('name') }.to raise_error
end
end
Expand Down

0 comments on commit b72bf96

Please sign in to comment.