Replace cucumber features by rails integration specs

This commit is contained in:
Thibault Jouan
2011-09-13 23:47:59 +00:00
parent 638d379ec6
commit 639293e4ca
26 changed files with 170 additions and 615 deletions

View 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

View 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

View 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

View 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

View 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

View 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