From cbacdd9fc1d208c287a8383556aaed0ba17a3d27 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Fri, 1 May 2015 15:57:26 +0000 Subject: [PATCH] Fix coding standards in specs --- spec/factories.rb | 6 +++--- spec/features/playlists/crud_spec.rb | 4 ++-- spec/features/sessions/sign_up_spec.rb | 2 +- spec/features/tracks/player_spec.rb | 2 +- spec/models/playlist_spec.rb | 3 +-- spec/models/sound_spec.rb | 3 +-- spec/models/track_spec.rb | 27 ++++++++++++-------------- spec/models/user_spec.rb | 8 ++++---- 8 files changed, 25 insertions(+), 30 deletions(-) diff --git a/spec/factories.rb b/spec/factories.rb index 6a5c9ce..1169942 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -6,7 +6,7 @@ end FactoryGirl.define do factory :playlist do - name 'Electro' + name 'Some playlist' user end @@ -15,7 +15,7 @@ FactoryGirl.define do end factory :track do - name 'Mega song' + name 'Some track' factory :track_with_sound do file { build_sound_file } @@ -24,7 +24,7 @@ FactoryGirl.define do factory :user do sequence :email do |n| - "alice_#{n}@example.net" + "bob_#{n}@example.net" end password '733tP4s5' end diff --git a/spec/features/playlists/crud_spec.rb b/spec/features/playlists/crud_spec.rb index aa5d000..bc9bc03 100644 --- a/spec/features/playlists/crud_spec.rb +++ b/spec/features/playlists/crud_spec.rb @@ -8,10 +8,10 @@ feature 'Playlists CRUD' do visit playlists_path click_link playlist[:name] - fill_in 'Name', with: 'Rock' + fill_in 'Name', with: 'new playlist name' click_button 'Save' expect(current_path).to eq playlists_path - expect(page).to have_content 'Rock' + expect(page).to have_content 'new playlist name' end end diff --git a/spec/features/sessions/sign_up_spec.rb b/spec/features/sessions/sign_up_spec.rb index a7f2827..318bfb2 100644 --- a/spec/features/sessions/sign_up_spec.rb +++ b/spec/features/sessions/sign_up_spec.rb @@ -11,7 +11,7 @@ feature 'User sign up' do scenario 'creates the user' do expect { click_button 'Sign up' - }.to change(User, :count).by(1) + }.to change(User, :count).by 1 end scenario 'redirects to the home page' do diff --git a/spec/features/tracks/player_spec.rb b/spec/features/tracks/player_spec.rb index e59d9ab..b29f796 100644 --- a/spec/features/tracks/player_spec.rb +++ b/spec/features/tracks/player_spec.rb @@ -6,7 +6,7 @@ feature 'Tracks player' do scenario 'includes a player in track page' do track = create :track_with_sound - visit track_path(track) + visit track_path track expect(page).to have_xpath "//audio[@src='#{sound_path track.sound}']" end diff --git a/spec/models/playlist_spec.rb b/spec/models/playlist_spec.rb index 7cb7671..b9b1eac 100644 --- a/spec/models/playlist_spec.rb +++ b/spec/models/playlist_spec.rb @@ -1,6 +1,5 @@ describe Playlist do - subject { playlist } - let(:playlist) { build :playlist } + subject(:playlist) { build :playlist } it { is_expected.to be_valid } it { is_expected.to belong_to :user } diff --git a/spec/models/sound_spec.rb b/spec/models/sound_spec.rb index 02e0a14..1b84643 100644 --- a/spec/models/sound_spec.rb +++ b/spec/models/sound_spec.rb @@ -1,6 +1,5 @@ describe Sound do - subject { sound } - let(:sound) { build :sound } + subject(:sound) { build :sound } it { is_expected.to be_valid } it { is_expected.to belong_to :track } diff --git a/spec/models/track_spec.rb b/spec/models/track_spec.rb index 6e928ab..b4159cd 100644 --- a/spec/models/track_spec.rb +++ b/spec/models/track_spec.rb @@ -1,7 +1,6 @@ describe Track do - subject { track } - let(:track) { build :track } - let(:file) { attributes_for(:track_with_sound)[:file] } + let(:file) { attributes_for(:track_with_sound)[:file] } + subject(:track) { build :track } it { is_expected.to be_valid } it { is_expected.to have_many :sounds } @@ -13,9 +12,15 @@ describe Track do it { is_expected.to be_valid } it 'creates a sound for the track' do - expect { - track.save - }.to change(track.sounds, :count).by(1) + expect { track.save }.to change(track.sounds, :count).by 1 + end + end + + describe '.latest' do + it 'returns latest tracks in descending creation date order' do + track1 = create :track, created_at: '2011-07-27 19:13:42' + track2 = create :track, created_at: '2011-07-27 19:58:57' + expect(described_class.latest).to eq [track2, track1] end end @@ -23,7 +28,7 @@ describe Track do it 'builds a new related sound with the file' do sounds = double 'sounds association proxy' allow(track).to receive(:sounds) { sounds } - expect(sounds).to receive(:build).with(file: file) + expect(sounds).to receive(:build).with file: file track.file = file end end @@ -53,12 +58,4 @@ describe Track do end end end - - describe '.latest' do - it 'returns latest tracks in descending creation date order' do - track1 = create :track, created_at: '2011-07-27 19:13:42' - track2 = create :track, created_at: '2011-07-27 19:58:57' - expect(Track.latest).to eq [track2, track1] - end - end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 1601813..14c5eeb 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -11,7 +11,7 @@ describe User do let(:old_user) { create :user, email: 'unique@example.net' } subject(:user) { build :user, email: old_user.email } - it { is_expected.to_not be_valid } + it { is_expected.not_to be_valid } it 'has an error on email attribute' do user.valid? @@ -22,7 +22,7 @@ describe User do context 'when password_confirmation does not match password' do before { user.password_confirmation = user.password + 'INVALID' } - it { is_expected.to_not be_valid } + it { is_expected.not_to be_valid } end describe '#password=' do @@ -34,13 +34,13 @@ describe User do describe '#authenticate?' do context 'with a valid password' do it 'returns true' do - expect(user.authenticate?(user.password)).to be true + expect(user.authenticate? user.password).to be true end end context 'with an invalid password' do it 'returns false' do - expect(user.authenticate?(user.password + '_INVALID')).to be false + expect(user.authenticate? user.password + '_INVALID').to be false end end end