Fix coding standards in specs

This commit is contained in:
Thibault Jouan 2015-05-01 15:57:26 +00:00
parent c1393b8f8f
commit cbacdd9fc1
8 changed files with 25 additions and 30 deletions

View File

@ -6,7 +6,7 @@ end
FactoryGirl.define do FactoryGirl.define do
factory :playlist do factory :playlist do
name 'Electro' name 'Some playlist'
user user
end end
@ -15,7 +15,7 @@ FactoryGirl.define do
end end
factory :track do factory :track do
name 'Mega song' name 'Some track'
factory :track_with_sound do factory :track_with_sound do
file { build_sound_file } file { build_sound_file }
@ -24,7 +24,7 @@ FactoryGirl.define do
factory :user do factory :user do
sequence :email do |n| sequence :email do |n|
"alice_#{n}@example.net" "bob_#{n}@example.net"
end end
password '733tP4s5' password '733tP4s5'
end end

View File

@ -8,10 +8,10 @@ feature 'Playlists CRUD' do
visit playlists_path visit playlists_path
click_link playlist[:name] click_link playlist[:name]
fill_in 'Name', with: 'Rock' fill_in 'Name', with: 'new playlist name'
click_button 'Save' click_button 'Save'
expect(current_path).to eq playlists_path expect(current_path).to eq playlists_path
expect(page).to have_content 'Rock' expect(page).to have_content 'new playlist name'
end end
end end

View File

@ -11,7 +11,7 @@ feature 'User sign up' do
scenario 'creates the user' do scenario 'creates the user' do
expect { expect {
click_button 'Sign up' click_button 'Sign up'
}.to change(User, :count).by(1) }.to change(User, :count).by 1
end end
scenario 'redirects to the home page' do scenario 'redirects to the home page' do

View File

@ -6,7 +6,7 @@ feature 'Tracks player' do
scenario 'includes a player in track page' do scenario 'includes a player in track page' do
track = create :track_with_sound track = create :track_with_sound
visit track_path(track) visit track_path track
expect(page).to have_xpath "//audio[@src='#{sound_path track.sound}']" expect(page).to have_xpath "//audio[@src='#{sound_path track.sound}']"
end end

View File

@ -1,6 +1,5 @@
describe Playlist do describe Playlist do
subject { playlist } subject(:playlist) { build :playlist }
let(:playlist) { build :playlist }
it { is_expected.to be_valid } it { is_expected.to be_valid }
it { is_expected.to belong_to :user } it { is_expected.to belong_to :user }

View File

@ -1,6 +1,5 @@
describe Sound do describe Sound do
subject { sound } subject(:sound) { build :sound }
let(:sound) { build :sound }
it { is_expected.to be_valid } it { is_expected.to be_valid }
it { is_expected.to belong_to :track } it { is_expected.to belong_to :track }

View File

@ -1,7 +1,6 @@
describe Track do 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 be_valid }
it { is_expected.to have_many :sounds } it { is_expected.to have_many :sounds }
@ -13,9 +12,15 @@ describe Track do
it { is_expected.to be_valid } it { is_expected.to be_valid }
it 'creates a sound for the track' do it 'creates a sound for the track' do
expect { expect { track.save }.to change(track.sounds, :count).by 1
track.save end
}.to change(track.sounds, :count).by(1) 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
end end
@ -23,7 +28,7 @@ describe Track do
it 'builds a new related sound with the file' do it 'builds a new related sound with the file' do
sounds = double 'sounds association proxy' sounds = double 'sounds association proxy'
allow(track).to receive(:sounds) { sounds } 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 track.file = file
end end
end end
@ -53,12 +58,4 @@ describe Track do
end end
end 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 end

View File

@ -11,7 +11,7 @@ describe User do
let(:old_user) { create :user, email: 'unique@example.net' } let(:old_user) { create :user, email: 'unique@example.net' }
subject(:user) { build :user, email: old_user.email } 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 it 'has an error on email attribute' do
user.valid? user.valid?
@ -22,7 +22,7 @@ describe User do
context 'when password_confirmation does not match password' do context 'when password_confirmation does not match password' do
before { user.password_confirmation = user.password + 'INVALID' } before { user.password_confirmation = user.password + 'INVALID' }
it { is_expected.to_not be_valid } it { is_expected.not_to be_valid }
end end
describe '#password=' do describe '#password=' do
@ -34,13 +34,13 @@ describe User do
describe '#authenticate?' do describe '#authenticate?' do
context 'with a valid password' do context 'with a valid password' do
it 'returns true' do it 'returns true' do
expect(user.authenticate?(user.password)).to be true expect(user.authenticate? user.password).to be true
end end
end end
context 'with an invalid password' do context 'with an invalid password' do
it 'returns false' 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 end
end end