Replace cucumber features by rails integration specs
This commit is contained in:
32
spec/integration/home_spec.rb
Normal file
32
spec/integration/home_spec.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature 'Home page' do
|
||||
include UserIntegrationHelpers
|
||||
|
||||
background do
|
||||
sign_in
|
||||
end
|
||||
|
||||
scenario 'displays playlists' do
|
||||
playlist = Factory.create(:playlist, :name => 'Electro')
|
||||
|
||||
visit root_path
|
||||
|
||||
page.should have_content('Electro')
|
||||
end
|
||||
|
||||
scenario 'displays last track added' do
|
||||
Factory.create(:track,
|
||||
:name => 'Mega song 1',
|
||||
:created_at => '2011-07-27 19:13:42'
|
||||
)
|
||||
Factory.create(:track,
|
||||
:name => 'Mega song 2',
|
||||
:created_at => '2011-07-27 19:58:57'
|
||||
)
|
||||
|
||||
visit root_path
|
||||
|
||||
page.body.should match(/Mega song 2.+Mega song 1/m)
|
||||
end
|
||||
end
|
41
spec/integration/playlists_spec.rb
Normal file
41
spec/integration/playlists_spec.rb
Normal file
@@ -0,0 +1,41 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature 'Playlists' do
|
||||
include UserIntegrationHelpers
|
||||
|
||||
background do
|
||||
sign_in
|
||||
end
|
||||
|
||||
scenario 'lists playlists' do
|
||||
Factory.create(:playlist, :name => 'Electro')
|
||||
Factory.create(:playlist, :name => 'Reggae')
|
||||
|
||||
visit playlists_path
|
||||
|
||||
page.body.should match(/Electro.+Reggae/m)
|
||||
end
|
||||
|
||||
scenario 'creates playlist' do
|
||||
visit playlists_path
|
||||
|
||||
click_link 'Create playlist'
|
||||
fill_in 'Name', :with => 'Electro'
|
||||
click_button 'Create'
|
||||
|
||||
current_path.should == playlists_path
|
||||
page.should have_content('Electro')
|
||||
end
|
||||
|
||||
scenario 'edits playlist' do
|
||||
Factory.create(:playlist, :name => 'Electro')
|
||||
visit playlists_path
|
||||
|
||||
click_link 'Electro'
|
||||
fill_in 'Name', :with => 'Rock'
|
||||
click_button 'Save'
|
||||
|
||||
current_path.should == playlists_path
|
||||
page.should have_content('Rock')
|
||||
end
|
||||
end
|
44
spec/integration/tracks_spec.rb
Normal file
44
spec/integration/tracks_spec.rb
Normal file
@@ -0,0 +1,44 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature 'Tracks' do
|
||||
include UserIntegrationHelpers
|
||||
|
||||
background do
|
||||
sign_in
|
||||
end
|
||||
|
||||
scenario 'shows track' do
|
||||
track = Factory.create(:track, :name => 'Mega song')
|
||||
|
||||
visit track_path(track)
|
||||
|
||||
page.should have_content('Mega song')
|
||||
end
|
||||
|
||||
scenario 'creates track' do
|
||||
visit root_path
|
||||
|
||||
click_link 'Add a track'
|
||||
fill_in 'Name', :with => 'Mega song'
|
||||
attach_file 'File', File.expand_path('spec/fixtures/test.mp3')
|
||||
click_button 'Upload'
|
||||
|
||||
current_path.should == track_path(Track.find(:first))
|
||||
page.should have_content('Mega song')
|
||||
end
|
||||
|
||||
scenario 'plays track' do
|
||||
track = Factory.create(:track, :name => 'Mega song')
|
||||
file = File.new("#{Rails.root}/spec/fixtures/test.mp3")
|
||||
track.save_with_file(file, 'audio/mpeg')
|
||||
|
||||
visit track_path(track)
|
||||
|
||||
page.should have_xpath "//audio[@src='#{stream_track_path(track)}']"
|
||||
visit find('audio')[:src]
|
||||
end
|
||||
|
||||
after do
|
||||
`rm -f #{Rails.root}/data/tracks/*`
|
||||
end
|
||||
end
|
20
spec/integration/user_sign_in_spec.rb
Normal file
20
spec/integration/user_sign_in_spec.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature 'User sign in' do
|
||||
scenario 'redirects to the home page when not signed in' do
|
||||
visit root_path
|
||||
|
||||
current_path.should == new_session_path
|
||||
end
|
||||
|
||||
scenario 'signs the user in' do
|
||||
user = Factory.create(:user)
|
||||
|
||||
visit new_session_path
|
||||
fill_in 'Email', :with => user.email
|
||||
fill_in 'Password', :with => user.password
|
||||
click_button 'Sign in'
|
||||
|
||||
current_path.should == root_path
|
||||
end
|
||||
end
|
24
spec/integration/user_sign_up_spec.rb
Normal file
24
spec/integration/user_sign_up_spec.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature 'User sign up' do
|
||||
let(:user) { Factory.build(:user) }
|
||||
|
||||
background do
|
||||
visit new_user_path
|
||||
fill_in 'Email', :with => user.email
|
||||
fill_in 'Password', :with => user.password
|
||||
fill_in 'Password confirmation', :with => user.password
|
||||
end
|
||||
|
||||
scenario 'creates the user' do
|
||||
expect {
|
||||
click_button 'Sign up'
|
||||
}.to change(User, :count).by(1)
|
||||
end
|
||||
|
||||
scenario 'redirects to the home page' do
|
||||
click_button 'Sign up'
|
||||
|
||||
current_path.should == root_path
|
||||
end
|
||||
end
|
9
spec/support/user_integration_helpers.rb
Normal file
9
spec/support/user_integration_helpers.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
module UserIntegrationHelpers
|
||||
def sign_in
|
||||
user = Factory.create(:user)
|
||||
visit new_session_path
|
||||
fill_in 'Email', :with => user.email
|
||||
fill_in 'Password', :with => user.password
|
||||
click_button('Sign in')
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user