Update specs to new rspec syntax

This commit is contained in:
Thibault Jouan 2014-04-01 18:15:44 +00:00
parent 99d106cf36
commit 4cef7aeab9
32 changed files with 173 additions and 179 deletions

View File

@ -23,14 +23,14 @@ describe API::ApplicationController do
it 'sets Access-Control-Allow-Methods header' do it 'sets Access-Control-Allow-Methods header' do
options :index options :index
response.headers['Access-Control-Allow-Methods'].should == expect(response.headers['Access-Control-Allow-Methods'])
'GET, POST, PUT, DELETE' .to eq 'GET, POST, PUT, DELETE'
end end
it 'sets Access-Control-Allow-Methods header' do it 'sets Access-Control-Allow-Methods header' do
options :index options :index
response.headers['Access-Control-Allow-Headers'].should == expect(response.headers['Access-Control-Allow-Headers'])
'Content-Type, Content-Length, X-Requested-With' .to eq 'Content-Type, Content-Length, X-Requested-With'
end end
end end
@ -43,8 +43,8 @@ describe API::ApplicationController do
it 'sets Access-Control-Allow-Origin header' do it 'sets Access-Control-Allow-Origin header' do
get :index get :index
response.headers['Access-Control-Allow-Origin'] expect(response.headers['Access-Control-Allow-Origin'])
.should == request.headers['Origin'] .to eq request.headers['Origin']
end end
end end
end end

View File

@ -21,15 +21,15 @@ describe API::PlaylistsController do
end end
it 'lists all playlists' do it 'lists all playlists' do
do_get.should have(2).items expect(do_get).to have(2).items
end end
it 'lists playlists with their id' do it 'lists playlists with their id' do
do_get.each { |t| t.keys.should include 'id' } do_get.each { |t| expect(t.keys).to include 'id' }
end end
it 'lists playlists with their name' do it 'lists playlists with their name' do
do_get.each { |t| t.keys.should include 'name' } do_get.each { |t| expect(t.keys).to include 'name' }
end end
end end
@ -48,7 +48,7 @@ describe API::PlaylistsController do
it 'assigns the playlist' do it 'assigns the playlist' do
do_create do_create
assigns[:playlist].should be_a Playlist expect(assigns[:playlist]).to be_a Playlist
end end
end end
end end

View File

@ -17,31 +17,31 @@ describe API::SessionsController do
end end
it 'signs the user in' do it 'signs the user in' do
controller.current_user.should == user expect(controller.current_user).to eq user
end end
it 'assigns the user' do it 'assigns the user' do
assigns[:user].should == user expect(assigns[:user]).to eq user
end end
end end
[:email, :password].each do |attr| [:email, :password].each do |attr|
context "with invalid credentials (#{attr})" do context "with invalid credentials (#{attr})" do
before do before do
user.stub(attr => user.send(attr) + '_INVALID') allow(user).to receive(attr).and_return(user.send(attr) + '_INVALID')
do_create do_create
end end
it 'returns a not found response' do it 'returns a not found response' do
response.should be_not_found expect(response).to be_not_found
end end
it 'returns an empty body' do it 'returns an empty body' do
response.body.should be_empty expect(response.body).to be_empty
end end
it 'assigns no user' do it 'assigns no user' do
assigns[:user].should be_nil expect(assigns[:user]).to be_nil
end end
end end
end end

View File

@ -21,19 +21,19 @@ describe API::TracksController do
end end
it 'lists all tracks' do it 'lists all tracks' do
do_get.should have(2).items expect(do_get).to have(2).items
end end
it 'lists tracks with their id' do it 'lists tracks with their id' do
do_get.each { |p| p.should include 'id' } do_get.each { |p| expect(p).to include 'id' }
end end
it 'lists tracks with their name' do it 'lists tracks with their name' do
do_get.each { |p| p.should include 'name' } do_get.each { |p| expect(p).to include 'name' }
end end
it 'lists tracks with sound URL' do it 'lists tracks with sound URL' do
do_get.each { |p| p.should include 'sound_url' } do_get.each { |p| expect(p).to include 'sound_url' }
end end
end end
end end

View File

@ -6,7 +6,7 @@ describe ApplicationController do
describe '#current_user=' do describe '#current_user=' do
it 'stores the user id in the session as :user_id' do it 'stores the user id in the session as :user_id' do
controller.current_user = user controller.current_user = user
session[:user_id].should == user.id expect(session[:user_id]).to eq user.id
end end
end end
@ -14,7 +14,7 @@ describe ApplicationController do
context 'when session[:user_id] is set' do context 'when session[:user_id] is set' do
it 'returns the User instance from the session' do it 'returns the User instance from the session' do
session[:user_id] = user.id session[:user_id] = user.id
controller.current_user.should == user expect(controller.current_user).to eq user
end end
end end
end end

View File

@ -11,14 +11,14 @@ describe HomeController do
it 'assigns all playlists as @playlists' do it 'assigns all playlists as @playlists' do
playlist = FactoryGirl.create(:playlist) playlist = FactoryGirl.create(:playlist)
get :index get :index
assigns[:playlists].should == [playlist] expect(assigns[:playlists]).to eq [playlist]
end end
it 'assigns latest tracks as @tracks' do it 'assigns latest tracks as @tracks' do
track1 = FactoryGirl.create(:track, created_at: '2011-07-27 19:13:42') track1 = FactoryGirl.create(:track, created_at: '2011-07-27 19:13:42')
track2 = FactoryGirl.create(:track, created_at: '2011-07-27 19:58:57') track2 = FactoryGirl.create(:track, created_at: '2011-07-27 19:58:57')
get :index get :index
assigns[:tracks].should == Track.latest expect(assigns[:tracks]).to eq Track.latest
end end
end end
end end

View File

@ -11,14 +11,14 @@ describe PlaylistsController do
it 'assigns all playlists as @playlists' do it 'assigns all playlists as @playlists' do
playlist = FactoryGirl.create(:playlist) playlist = FactoryGirl.create(:playlist)
get :index get :index
assigns[:playlists].should == [playlist] expect(assigns[:playlists]).to eq [playlist]
end end
end end
describe 'GET new' do describe 'GET new' do
it 'assigns a new playlist as @playlist' do it 'assigns a new playlist as @playlist' do
get :new get :new
assigns[:playlist].should be_a_new(Playlist) expect(assigns[:playlist]).to be_a_new Playlist
end end
end end
@ -26,7 +26,7 @@ describe PlaylistsController do
it 'assigns the requested playlist as @playlist' do it 'assigns the requested playlist as @playlist' do
playlist = FactoryGirl.create(:playlist) playlist = FactoryGirl.create(:playlist)
get :edit, id: playlist.id.to_s get :edit, id: playlist.id.to_s
assigns[:playlist].should == playlist expect(assigns[:playlist]).to eq playlist
end end
end end
@ -44,21 +44,21 @@ describe PlaylistsController do
it 'redirects to the playlists index' do it 'redirects to the playlists index' do
do_create do_create
response.should redirect_to(action: 'index') expect(response).to redirect_to action: 'index'
end end
end end
context 'whith invalid params' do context 'whith invalid params' do
before { Playlist.any_instance.stub(:save).and_return(false) } before { allow_any_instance_of(Playlist).to receive(:save) { false } }
it 'assigns the playlist as @playlist' do it 'assigns the playlist as @playlist' do
do_create do_create
assigns[:playlist].should be_a_new(Playlist) expect(assigns[:playlist]).to be_a_new Playlist
end end
it 'renders the new template' do it 'renders the new template' do
do_create do_create
response.should render_template('new') expect(response).to render_template 'new'
end end
end end
end end
@ -72,28 +72,28 @@ describe PlaylistsController do
context 'whith valid params' do context 'whith valid params' do
it 'updates the playlist' do it 'updates the playlist' do
Playlist.any_instance.should_receive(:update_attributes) expect_any_instance_of(Playlist)
.with({'name' => 'Rock'}) .to receive(:update_attributes).with({'name' => 'Rock'})
do_update do_update
end end
it 'redirects to the playlists index' do it 'redirects to the playlists index' do
do_update do_update
response.should redirect_to(action: 'index') expect(response).to redirect_to(action: 'index')
end end
end end
context 'with invalid params' do context 'with invalid params' do
before { Playlist.any_instance.stub(:save).and_return(false) } before { allow_any_instance_of(Playlist).to receive(:save) { false } }
it 'assigns the requested playlist as @playlist' do it 'assigns the requested playlist as @playlist' do
do_update do_update
assigns[:playlist].should == playlist expect(assigns[:playlist]).to eq playlist
end end
it 'renders the edit template' do it 'renders the edit template' do
do_update do_update
response.should render_template('edit') expect(response).to render_template 'edit'
end end
end end
end end

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe SessionsController do describe SessionsController do
describe 'GET new' do describe 'GET new' do
it 'responds successfully' do it 'responds successfully' do
response.should be_success expect(response).to be_success
end end
end end
@ -20,24 +20,24 @@ describe SessionsController do
context 'with valid credentials' do context 'with valid credentials' do
it 'signs the user in' do it 'signs the user in' do
do_create do_create
controller.current_user.should == user expect(controller.current_user).to eq user
end end
it 'redirects to the home page' do it 'redirects to the home page' do
do_create do_create
response.should redirect_to(:root) expect(response).to redirect_to :root
end end
end end
[:email, :password].each do |attr| [:email, :password].each do |attr|
context "with invalid credentials (#{attr})" do context "with invalid credentials (#{attr})" do
before do before do
user.stub(attr => user.send(attr) + '_INVALID') allow(user).to receive(attr).and_return(user.send(attr) + '_INVALID')
end end
it 'renders the new template' do it 'renders the new template' do
do_create do_create
response.should render_template('new') expect(response).to render_template 'new'
end end
end end
end end

View File

@ -16,12 +16,12 @@ describe SoundsController do
it 'sets the sound file content as the response body' do it 'sets the sound file content as the response body' do
do_show do_show
response.body.should == File.read(sound.path, encoding: 'BINARY') expect(response.body).to eq File.read(sound.path, encoding: 'BINARY')
end end
it 'sets the sound mime-type as the response content-type' do it 'sets the sound mime-type as the response content-type' do
do_show do_show
response.content_type.should == sound.mime_type expect(response.content_type).to eq sound.mime_type
end end
end end
end end

View File

@ -11,14 +11,14 @@ describe TracksController do
it 'assigns the requested track as @track' do it 'assigns the requested track as @track' do
track = FactoryGirl.create(:track) track = FactoryGirl.create(:track)
get :show, id: track.id.to_s get :show, id: track.id.to_s
assigns[:track].should == track expect(assigns[:track]).to eq track
end end
end end
describe 'GET new' do describe 'GET new' do
it 'assigns a new track as @track' do it 'assigns a new track as @track' do
get :new get :new
assigns[:track].should be_a_new(Track) expect(assigns[:track]).to be_a_new Track
end end
end end
@ -41,23 +41,23 @@ describe TracksController do
it 'redirects to the track page' do it 'redirects to the track page' do
do_create do_create
response.should redirect_to(Track.last) expect(response).to redirect_to Track.last
end end
end end
context 'whith invalid params' do context 'whith invalid params' do
before do before do
Track.any_instance.stub(:save).and_return(false) allow_any_instance_of(Track).to receive(:save) { false }
end end
it 'assigns the track as @track' do it 'assigns the track as @track' do
do_create do_create
assigns[:track].should be_a_new(Track) expect(assigns[:track]).to be_a_new Track
end end
it 'renders the new template' do it 'renders the new template' do
do_create do_create
response.should render_template('new') expect(response).to render_template 'new'
end end
end end
end end

View File

@ -4,7 +4,7 @@ describe UsersController do
describe 'GET new' do describe 'GET new' do
it 'assigns a new user as @user' do it 'assigns a new user as @user' do
get :new get :new
assigns[:user].should be_a_new(User) expect(assigns[:user]).to be_a_new(User)
end end
end end
@ -18,26 +18,26 @@ describe UsersController do
it 'signs the user in' do it 'signs the user in' do
post :create, user: FactoryGirl.attributes_for(:user) post :create, user: FactoryGirl.attributes_for(:user)
controller.current_user.should_not be_nil expect(controller.current_user).not_to be_nil
end end
it 'redirects to the home page' do it 'redirects to the home page' do
post :create, user: FactoryGirl.attributes_for(:user) post :create, user: FactoryGirl.attributes_for(:user)
response.should redirect_to(:root) expect(response).to redirect_to :root
end end
end end
context 'whith invalid params' do context 'whith invalid params' do
before { User.any_instance.stub(:save).and_return(false) } before { allow_any_instance_of(User).to receive(:save) { false } }
it 'assigns the user as @user' do it 'assigns the user as @user' do
post :create, user: {} post :create, user: {}
assigns[:user].should be_a_new(User) expect(assigns[:user]).to be_a_new User
end end
it 'renders the new template' do it 'renders the new template' do
post :create, user: {} post :create, user: {}
response.should render_template('new') expect(response).to render_template 'new'
end end
end end
end end

View File

@ -12,7 +12,7 @@ feature 'Home page' do
visit root_path visit root_path
page.should have_content('Electro') expect(page).to have_content 'Electro'
end end
scenario 'displays last track added' do scenario 'displays last track added' do
@ -27,6 +27,6 @@ feature 'Home page' do
visit root_path visit root_path
page.body.should match(/Mega song 2.+Mega song 1/m) expect(page.body).to match /Mega song 2.+Mega song 1/m
end end
end end

View File

@ -13,7 +13,7 @@ feature 'Playlists' do
visit playlists_path visit playlists_path
page.body.should match(/Electro.+Reggae/m) expect(page.body).to match /Electro.+Reggae/m
end end
scenario 'creates playlist' do scenario 'creates playlist' do
@ -23,8 +23,8 @@ feature 'Playlists' do
fill_in 'Name', with: 'Electro' fill_in 'Name', with: 'Electro'
click_button 'Create' click_button 'Create'
current_path.should == playlists_path expect(current_path).to eq playlists_path
page.should have_content('Electro') expect(page).to have_content 'Electro'
end end
scenario 'edits playlist' do scenario 'edits playlist' do
@ -35,7 +35,7 @@ feature 'Playlists' do
fill_in 'Name', with: 'Rock' fill_in 'Name', with: 'Rock'
click_button 'Save' click_button 'Save'
current_path.should == playlists_path expect(current_path).to eq playlists_path
page.should have_content('Rock') expect(page).to have_content 'Rock'
end end
end end

View File

@ -12,7 +12,7 @@ feature 'Tracks' do
visit track_path(track) visit track_path(track)
page.should have_content('Mega song') expect(page).to have_content 'Mega song'
end end
scenario 'creates track' do scenario 'creates track' do
@ -23,8 +23,8 @@ feature 'Tracks' do
attach_file 'File', File.expand_path('spec/fixtures/test.mp3') attach_file 'File', File.expand_path('spec/fixtures/test.mp3')
click_button 'Upload' click_button 'Upload'
current_path.should == track_path(Track.first) expect(current_path).to eq track_path Track.first
page.should have_content('Mega song') expect(page).to have_content 'Mega song'
end end
scenario 'plays track' do scenario 'plays track' do
@ -32,7 +32,7 @@ feature 'Tracks' do
visit track_path(track) visit track_path(track)
page.should have_xpath "//audio[@src='#{sound_path(track.sound)}']" expect(page).to have_xpath "//audio[@src='#{sound_path track.sound}']"
visit find('audio')[:src] visit find('audio')[:src]
end end
end end

View File

@ -4,7 +4,7 @@ feature 'User sign in' do
scenario 'redirects to the home page when not signed in' do scenario 'redirects to the home page when not signed in' do
visit root_path visit root_path
current_path.should == new_session_path expect(current_path).to eq new_session_path
end end
scenario 'signs the user in' do scenario 'signs the user in' do
@ -15,6 +15,6 @@ feature 'User sign in' do
fill_in 'Password', with: user.password fill_in 'Password', with: user.password
click_button 'Sign in' click_button 'Sign in'
current_path.should == root_path expect(current_path).to eq root_path
end end
end end

View File

@ -19,6 +19,6 @@ feature 'User sign up' do
scenario 'redirects to the home page' do scenario 'redirects to the home page' do
click_button 'Sign up' click_button 'Sign up'
current_path.should == root_path expect(current_path).to eq root_path
end end
end end

View File

@ -13,17 +13,17 @@ feature 'API sign in' do
scenario 'signs the user in with valid credentials' do scenario 'signs the user in with valid credentials' do
do_create do_create
response.should be_success expect(response).to be_success
(JSON response.body).should include 'id' expect(JSON response.body).to include 'id'
end end
[:email, :password].each do |attr| [:email, :password].each do |attr|
scenario "rejects authentication with invalid credentials (#{attr})" do scenario "rejects authentication with invalid credentials (#{attr})" do
user.stub(attr => user.send(attr) + '_INVALID') allow(user).to receive(attr).and_return(user.send(attr) + '_INVALID')
do_create do_create
response.should be_not_found expect(response).to be_not_found
response.body.should be_empty expect(response.body).to be_empty
end end
end end
end end

View File

@ -22,12 +22,12 @@ feature 'API cross origin request' do
{ 'Origin' => origin } { 'Origin' => origin }
) )
response.headers['Access-Control-Allow-Origin'].should == origin expect(response.headers['Access-Control-Allow-Origin']).to eq origin
response.headers['Access-Control-Allow-Credentials'].should == 'true' expect(response.headers['Access-Control-Allow-Credentials']).to eq 'true'
response.headers['Access-Control-Allow-Methods'].should == expect(response.headers['Access-Control-Allow-Methods'])
'GET, POST, PUT, DELETE' .to eq 'GET, POST, PUT, DELETE'
response.headers['Access-Control-Allow-Headers'].should == expect(response.headers['Access-Control-Allow-Headers'])
'Content-Type, Content-Length, X-Requested-With' .to eq 'Content-Type, Content-Length, X-Requested-With'
end end
scenario 'basic request' do scenario 'basic request' do
@ -36,15 +36,16 @@ feature 'API cross origin request' do
'Origin' => origin 'Origin' => origin
} }
response.headers['Access-Control-Allow-Origin'].should == origin expect(response.headers['Access-Control-Allow-Origin']).to eq origin
response.headers['Access-Control-Allow-Credentials'].should == 'true' expect(response.headers['Access-Control-Allow-Credentials']).to eq 'true'
response.headers['Access-Control-Expose-Headers'].should == 'Content-Length' expect(response.headers['Access-Control-Expose-Headers'])
.to eq 'Content-Length'
end end
scenario 'request without origin' do scenario 'request without origin' do
# FIXME: replace with a more stable/generic action # FIXME: replace with a more stable/generic action
get api_playlists_path(format: :json) get api_playlists_path(format: :json)
response.headers['Access-Control-Allow-Origin'].should == '' expect(response.headers['Access-Control-Allow-Origin']).to eq ''
end end
end end

View File

@ -16,7 +16,7 @@ feature 'API playlists' do
json = JSON response.body json = JSON response.body
json['id'].should be_a Fixnum expect(json['id']).to be_a Fixnum
json['name'].should == playlist[:name] expect(json['name']).to eq playlist[:name]
end end
end end

View File

@ -13,7 +13,7 @@ feature 'API tracks' do
get api_tracks_path, format: :json get api_tracks_path, format: :json
response.body.should == [ expect(response.body).to eq [
{ {
id: track_1.id, id: track_1.id,
name: 'Track 1', name: 'Track 1',

View File

@ -11,11 +11,12 @@ describe Sound do
describe '#path' do describe '#path' do
it 'starts by the path specified in Rails.configuration.sound_path' do it 'starts by the path specified in Rails.configuration.sound_path' do
sound.path.should match(/\A#{Rails.configuration.sounds_path}/) expect(sound.path).to match /\A#{Rails.configuration.sounds_path}/
end end
it 'returns the sound file path based on the SHA256 digest' do it 'returns the sound file path based on the SHA256 digest' do
sound.path.should == "#{Rails.configuration.sounds_path}/#{sound.sha256}" expect(sound.path)
.to eq "#{Rails.configuration.sounds_path}/#{sound.sha256}"
end end
end end
@ -23,15 +24,15 @@ describe Sound do
let (:file) { FactoryGirl.attributes_for(:sound)[:file] } let (:file) { FactoryGirl.attributes_for(:sound)[:file] }
it 'saves the file SHA256 digest' do it 'saves the file SHA256 digest' do
sound.sha256.should == Digest::SHA256.file(file.path).hexdigest expect(sound.sha256).to eq Digest::SHA256.file(file.path).hexdigest
end end
it 'copies the file to #path' do it 'copies the file to #path' do
File.read(sound.path).should == file.read expect(File.read(sound.path)).to eq file.read
end end
it 'saves the file MIME type' do it 'saves the file MIME type' do
sound.mime_type.should == 'audio/mpeg' expect(sound.mime_type).to eq 'audio/mpeg'
end end
end end
end end

View File

@ -27,8 +27,8 @@ describe Track do
describe '#file=' do describe '#file=' 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'
track.stub(sounds: sounds) allow(track).to receive(:sounds) { sounds }
sounds.should_receive(:build).with({file: file}) expect(sounds).to receive(:build).with({file: file})
track.file = file track.file = file
end end
end end
@ -40,7 +40,7 @@ describe Track do
end end
it 'returns a sound' do it 'returns a sound' do
track.sound.should be_a(Sound) expect(track.sound).to be_a Sound
end end
end end
end end
@ -48,7 +48,7 @@ describe Track do
describe '#sound?' do describe '#sound?' do
context 'without any sound' do context 'without any sound' do
it 'returns false' do it 'returns false' do
track.sound?.should be_false expect(track.sound?).to be false
end end
end end
@ -58,7 +58,7 @@ describe Track do
end end
it 'returns true' do it 'returns true' do
track.sound?.should be_true expect(track.sound?).to be true
end end
end end
end end
@ -67,7 +67,7 @@ describe Track do
it 'returns latest tracks in descending creation date order' do it 'returns latest tracks in descending creation date order' do
track1 = FactoryGirl.create(:track, created_at: '2011-07-27 19:13:42') track1 = FactoryGirl.create(:track, created_at: '2011-07-27 19:13:42')
track2 = FactoryGirl.create(:track, created_at: '2011-07-27 19:58:57') track2 = FactoryGirl.create(:track, created_at: '2011-07-27 19:58:57')
Track.latest.should == [track2, track1] expect(Track.latest).to eq [track2, track1]
end end
end end
end end

View File

@ -30,20 +30,20 @@ describe User do
describe '#password=' do describe '#password=' do
it 'stores a bcrypt hash of the password in password_hash' do it 'stores a bcrypt hash of the password in password_hash' do
BCrypt::Password.new(user.password_hash).should == user.password expect(BCrypt::Password.new(user.password_hash)).to eq user.password
end end
end end
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
user.authenticate?(user.password).should 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
user.authenticate?(user.password + '_INVALID').should be_false expect(user.authenticate?(user.password + '_INVALID')).to be false
end end
end end
end end

View File

@ -2,10 +2,11 @@ require 'spec_helper'
describe '/api OPTIONS requests routing' do describe '/api OPTIONS requests routing' do
it 'routes to API::ApplicationController#cor_preflight' do it 'routes to API::ApplicationController#cor_preflight' do
{ options: '/api/some_route' }.should route_to( expect({ options: '/api/some_route' })
controller: 'api/application', .to route_to(
action: 'cor_preflight', controller: 'api/application',
all: 'some_route' action: 'cor_preflight',
) all: 'some_route'
)
end end
end end

View File

@ -12,16 +12,16 @@ describe 'home/index' do
it 'displays a list of playlists' do it 'displays a list of playlists' do
render render
rendered.should have_selector('ul>li', text: 'Electro') expect(rendered).to have_selector 'ul>li', text: 'Electro'
end end
it 'displays a link to add a track' do it 'displays a link to add a track' do
render render
rendered.should have_selector('a', text: 'Add a track') expect(rendered).to have_selector 'a', text: 'Add a track'
end end
it 'displays a list of tracks' do it 'displays a list of tracks' do
render render
rendered.should have_selector('ul>li', text: 'Mega song') expect(rendered).to have_selector 'ul>li', text: 'Mega song'
end end
end end

View File

@ -11,16 +11,16 @@ describe 'playlists/edit' do
it 'renders a form to edit a playlist' do it 'renders a form to edit a playlist' do
render render
rendered.should have_selector("form[method=post][action='#{playlists_path}']") expect(rendered).to have_selector("form[method=post][action='#{playlists_path}']")
rendered.should have_selector('input[type=submit]') expect(rendered).to have_selector('input[type=submit]')
end end
it 'renders a text field with a label for the playlists name' do it 'renders a text field with a label for the playlists name' do
playlist.stub(name: 'Electro') allow(playlist).to receive(:name) { 'Electro' }
render render
rendered.should have_selector( expect(rendered)
"input[type=text][name='playlist[name]'][value=Electro]" .to have_selector "input[type=text][name='playlist[name]'][value=Electro]"
) expect(rendered)
rendered.should have_selector("label[for=playlist_name]", text: 'Name') .to have_selector 'label[for=playlist_name]', text: 'Name'
end end
end end

View File

@ -9,16 +9,16 @@ describe 'playlists/index' do
it 'displays a list of playlists' do it 'displays a list of playlists' do
render render
rendered.should have_selector('ul>li', text: 'Electro') expect(rendered).to have_selector 'ul>li', text: 'Electro'
end end
it 'displays a link to create a new playlist' do it 'displays a link to create a new playlist' do
render render
rendered.should have_selector('a', text: 'Create playlist') expect(rendered).to have_selector 'a', text: 'Create playlist'
end end
it 'displays playlists as links' do it 'displays playlists as links' do
render render
rendered.should have_selector('a', text: 'Electro') expect(rendered).to have_selector 'a', text: 'Electro'
end end
end end

View File

@ -11,18 +11,18 @@ describe 'playlists/new' do
it 'renders a form to create a playlist' do it 'renders a form to create a playlist' do
render render
rendered.should have_selector( expect(rendered)
"form[method=post][action='#{playlists_path}']" .to have_selector "form[method=post][action='#{playlists_path}']"
) expect(rendered)
rendered.should have_selector('input[type=submit]') .to have_selector 'input[type=submit]'
end end
it 'renders a text field with a label for the playlists name' do it 'renders a text field with a label for the playlists name' do
playlist.stub(name: 'Electro') allow(playlist).to receive(:name) { 'Electro' }
render render
rendered.should have_selector( expect(rendered)
"input[type=text][name='playlist[name]'][value=Electro]" .to have_selector "input[type=text][name='playlist[name]'][value=Electro]"
) expect(rendered)
rendered.should have_selector("label[for=playlist_name]", text: 'Name') .to have_selector 'label[for=playlist_name]', text: 'Name'
end end
end end

View File

@ -3,33 +3,28 @@ require 'spec_helper'
describe 'sessions/new' do describe 'sessions/new' do
it 'renders a form to sign in' do it 'renders a form to sign in' do
render render
rendered.should have_selector( expect(rendered)
"form[method=post][action='#{sessions_path}']" .to have_selector "form[method=post][action='#{sessions_path}']"
) expect(rendered).to have_selector 'input[type=submit]'
rendered.should have_selector('input[type=submit]')
end end
it 'renders a text field with a label for the mail address' do it 'renders a text field with a label for the mail address' do
render render
rendered.should have_selector("input[type=text][name='session[email]']") expect(rendered).to have_selector("input[type=text][name='session[email]']")
rendered.should have_selector('label[for=session_email]', text: 'Email') expect(rendered).to have_selector('label[for=session_email]', text: 'Email')
end end
it 'renders a password field with a label for the password' do it 'renders a password field with a label for the password' do
render render
rendered.should have_selector( expect(rendered)
"input[type=password][name='session[password]']" .to have_selector "input[type=password][name='session[password]']"
) expect(rendered)
rendered.should have_selector( .to have_selector 'label[for=session_password]', text: 'Password'
'label[for=session_password]', text: 'Password'
)
end end
it 'renders a link to the sign in page' do it 'renders a link to the sign in page' do
render render
rendered.should have_selector( expect(rendered)
"a[href='#{new_user_path}']", .to have_selector "a[href='#{new_user_path}']", text: 'Sign up'
text: 'Sign up'
)
end end
end end

View File

@ -11,23 +11,24 @@ describe 'tracks/new' do
it 'renders a form to create a track' do it 'renders a form to create a track' do
render render
rendered.should have_selector("form[method=post][action='#{tracks_path}']") expect(rendered)
rendered.should have_selector('input[type=submit]') .to have_selector "form[method=post][action='#{tracks_path}']"
expect(rendered).to have_selector 'input[type=submit]'
end end
it 'renders a text field with a label for the playlists name' do it 'renders a text field with a label for the playlists name' do
track.stub(name: 'Mega song') allow(track).to receive(:name) { 'Mega song' }
render render
rendered.should have_selector( expect(rendered)
"input[type=text][name='track[name]'][value='Mega song']" .to have_selector "input[type=text][name='track[name]'][value='Mega song']"
) expect(rendered)
rendered.should have_selector('label[for=track_name]', text: 'Name') .to have_selector('label[for=track_name]', text: 'Name')
end end
it 'renders a file field with a label for the tracks file' do it 'renders a file field with a label for the tracks file' do
render render
rendered.should have_selector("form[enctype='multipart/form-data']") expect(rendered).to have_selector("form[enctype='multipart/form-data']")
rendered.should have_selector("input[type=file][name='track[file]']") expect(rendered).to have_selector("input[type=file][name='track[file]']")
rendered.should have_selector('label[for=track_file]', text: 'File') expect(rendered).to have_selector('label[for=track_file]', text: 'File')
end end
end end

View File

@ -9,7 +9,7 @@ describe 'tracks/show' do
it 'displays the name of the track' do it 'displays the name of the track' do
render render
rendered.should have_selector('h1', text: 'Mega song') expect(rendered).to have_selector 'h1', text: 'Mega song'
end end
context 'when track has a sound' do context 'when track has a sound' do
@ -17,22 +17,22 @@ describe 'tracks/show' do
it 'provides an audio stream for the track' do it 'provides an audio stream for the track' do
render render
rendered.should have_selector('audio[src]') expect(rendered).to have_selector 'audio[src]'
end end
it 'provides controls' do it 'provides controls' do
render render
rendered.should have_selector('audio[controls]') expect(rendered).to have_selector 'audio[controls]'
end end
it 'has autoplay activated' do it 'has autoplay activated' do
render render
rendered.should have_selector('audio[autoplay]') expect(rendered).to have_selector 'audio[autoplay]'
end end
it 'displays a text fallback for UA without support' do it 'displays a text fallback for UA without support' do
render render
rendered.should have_selector( expect(rendered).to have_selector(
'audio', 'audio',
text: 'Your browser does not support the audio element' text: 'Your browser does not support the audio element'
) )

View File

@ -11,36 +11,31 @@ describe 'users/new' do
it 'renders a form to sign up' do it 'renders a form to sign up' do
render render
rendered.should have_selector("form[method=post][action='#{users_path}']") expect(rendered)
rendered.should have_selector('input[type=submit]') .to have_selector "form[method=post][action='#{users_path}']"
expect(rendered).to have_selector 'input[type=submit]'
end end
it 'renders a text field with a label for the mail address' do it 'renders a text field with a label for the mail address' do
render render
rendered.should have_selector( expect(rendered).to have_selector "input[type=text][name='user[email]']"
"input[type=text][name='user[email]']" expect(rendered)
) .to have_selector 'label[for=user_email]', text: 'Email'
rendered.should have_selector(
'label[for=user_email]', text: 'Email'
)
end end
it 'renders a password field with a label for the password' do it 'renders a password field with a label for the password' do
render render
rendered.should have_selector( expect(rendered)
"input[type=password][name='user[password]']" .to have_selector "input[type=password][name='user[password]']"
) expect(rendered)
rendered.should have_selector( .to have_selector 'label[for=user_password]', text: 'Password'
'label[for=user_password]', text: 'Password'
)
end end
it 'renders a password field with a label for the password confirmation' do it 'renders a password field with a label for the password confirmation' do
render render
rendered.should have_selector( expect(rendered)
"input[type=password][name='user[password_confirmation]']" .to have_selector "input[type=password][name='user[password_confirmation]']"
) expect(rendered).to have_selector(
rendered.should have_selector(
'label[for=user_password_confirmation]', 'label[for=user_password_confirmation]',
text: 'Password confirmation' text: 'Password confirmation'
) )
@ -53,7 +48,7 @@ describe 'users/new' do
new_user.save new_user.save
assign :user, new_user assign :user, new_user
render render
rendered.should have_content 'Email has already been taken' expect(rendered).to have_content 'Email has already been taken'
end end
end end
end end