Replace cucumber features by rails integration specs
This commit is contained in:
parent
638d379ec6
commit
639293e4ca
1
Gemfile
1
Gemfile
@ -10,7 +10,6 @@ gem 'bcrypt-ruby'
|
||||
|
||||
group :development, :test do
|
||||
gem 'rspec-rails'
|
||||
gem 'cucumber-rails'
|
||||
gem 'capybara'
|
||||
gem 'database_cleaner'
|
||||
gem 'factory_girl_rails'
|
||||
|
15
Gemfile.lock
15
Gemfile.lock
@ -40,16 +40,6 @@ GEM
|
||||
xpath (~> 0.1.4)
|
||||
childprocess (0.1.9)
|
||||
ffi (~> 1.0.6)
|
||||
cucumber (1.0.0)
|
||||
builder (>= 2.1.2)
|
||||
diff-lcs (>= 1.1.2)
|
||||
gherkin (~> 2.4.1)
|
||||
json (>= 1.4.6)
|
||||
term-ansicolor (>= 1.0.5)
|
||||
cucumber-rails (1.0.2)
|
||||
capybara (>= 1.0.0)
|
||||
cucumber (~> 1.0.0)
|
||||
nokogiri (>= 1.4.6)
|
||||
database_cleaner (0.6.7)
|
||||
diff-lcs (1.1.2)
|
||||
erubis (2.6.6)
|
||||
@ -59,8 +49,6 @@ GEM
|
||||
factory_girl (~> 2.0.0)
|
||||
railties (>= 3.0.0)
|
||||
ffi (1.0.9)
|
||||
gherkin (2.4.1)
|
||||
json (>= 1.4.6)
|
||||
guard (0.6.3)
|
||||
thor (~> 0.14.6)
|
||||
guard-rspec (0.4.4)
|
||||
@ -70,7 +58,6 @@ GEM
|
||||
spork (>= 0.8.4)
|
||||
haml (3.1.2)
|
||||
i18n (0.5.0)
|
||||
json (1.5.3)
|
||||
json_pure (1.5.3)
|
||||
mail (2.2.19)
|
||||
activesupport (>= 2.3.6)
|
||||
@ -124,7 +111,6 @@ GEM
|
||||
json_pure
|
||||
rubyzip
|
||||
spork (0.9.0.rc9)
|
||||
term-ansicolor (1.0.5)
|
||||
thor (0.14.6)
|
||||
treetop (1.4.9)
|
||||
polyglot (>= 0.3.1)
|
||||
@ -138,7 +124,6 @@ PLATFORMS
|
||||
DEPENDENCIES
|
||||
bcrypt-ruby
|
||||
capybara
|
||||
cucumber-rails
|
||||
database_cleaner
|
||||
factory_girl_rails
|
||||
guard
|
||||
|
@ -1,8 +0,0 @@
|
||||
<%
|
||||
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
|
||||
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
|
||||
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
|
||||
%>
|
||||
default: <%= std_opts %> features
|
||||
wip: --tags @wip:3 --wip features
|
||||
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
|
@ -15,6 +15,3 @@ test: &test
|
||||
production:
|
||||
<<: *common
|
||||
database: scube_production
|
||||
|
||||
cucumber:
|
||||
<<: *test
|
||||
|
Binary file not shown.
@ -1,22 +0,0 @@
|
||||
Feature: Home
|
||||
|
||||
So that I can use scube efficiently
|
||||
As a listener
|
||||
I want to access the main features and valuable content from the homepage
|
||||
|
||||
Background:
|
||||
Given I am signed in
|
||||
|
||||
Scenario: Playlist access
|
||||
Given a playlist named "Electro"
|
||||
When I am on the home page
|
||||
Then I should see "Electro" within "ul>li"
|
||||
|
||||
Scenario: Last tracks added
|
||||
Given the following tracks:
|
||||
| name | created_at |
|
||||
| Mega song 1 | 2011-07-27 19:13:42 |
|
||||
| Mega song 2 | 2011-07-27 19:58:57 |
|
||||
When I am on the home page
|
||||
Then I should see "Mega song 2" within "ul>li:first-child"
|
||||
And I should see "Mega song 1" within "ul>li:first-child+li"
|
@ -1,29 +0,0 @@
|
||||
Feature: Playlists
|
||||
|
||||
So that tracks can be grouped in lists
|
||||
As a listener
|
||||
I want to manage some playlists
|
||||
|
||||
Background:
|
||||
Given I am signed in
|
||||
|
||||
Scenario: List playlists
|
||||
Given a playlist named "Electro"
|
||||
And a playlist named "Reggae"
|
||||
When I am on the playlists page
|
||||
Then I should see "Electro" and "Reggae" in a list
|
||||
|
||||
Scenario: Create playlist
|
||||
Given I am on the playlists page
|
||||
When I follow "Create playlist"
|
||||
And I fill in "Name" with "Electro"
|
||||
And I press "Create"
|
||||
Then I should see "Electro" in the list
|
||||
|
||||
Scenario: Edit playlist
|
||||
Given a playlist named "Electro"
|
||||
And I am on the playlists page
|
||||
When I follow "Electro"
|
||||
And I fill in "Name" with "Rock"
|
||||
And I press "Save"
|
||||
Then I should see "Rock" in the list
|
@ -1,17 +0,0 @@
|
||||
Feature: Session
|
||||
|
||||
So that I can manage my own content
|
||||
As a listener
|
||||
I want the application to require a valid authentication
|
||||
|
||||
Scenario: Unauthenticated user
|
||||
Given I am not signed in
|
||||
When I go to the home page
|
||||
Then I should be redirected to the sign in page
|
||||
|
||||
Scenario: User authentication
|
||||
Given I am not signed in
|
||||
When I go to the home page
|
||||
Then I should be redirected to the sign in page
|
||||
When I submit valid credentials
|
||||
Then I should be redirected to the home page
|
@ -1,12 +0,0 @@
|
||||
Given /^a playlist named "([^"]*)"$/ do |name|
|
||||
Factory.create(:playlist, :name => name)
|
||||
end
|
||||
|
||||
Then /^I should see "([^"]*)" and "([^"]*)" in a list$/ do |pl1, pl2|
|
||||
Then "I should see \"#{pl1}\" within \"ul>li:first-child\""
|
||||
Then "I should see \"#{pl2}\" within \"ul>li:first-child+li\""
|
||||
end
|
||||
|
||||
Then /^I should see "([^"]*)" in the list$/ do |playlist_name|
|
||||
Then "I should see \"#{playlist_name}\" within \"ul>li\""
|
||||
end
|
@ -1,35 +0,0 @@
|
||||
Given /^I am not signed in$/ do
|
||||
|
||||
end
|
||||
|
||||
Given /^I am signed in$/ do
|
||||
visit new_session_path
|
||||
When "I submit valid credentials"
|
||||
end
|
||||
|
||||
Then /^I should be redirected to the sign in page$/ do
|
||||
current_path.should == new_session_path
|
||||
end
|
||||
|
||||
Then /^I should be redirected to the home page$/ do
|
||||
current_path.should == root_path
|
||||
end
|
||||
|
||||
When /^I submit valid credentials$/ do
|
||||
user = Factory.create(:user)
|
||||
fill_in('Email', :with => user.email)
|
||||
fill_in('Password', :with => user.password)
|
||||
click_button('Sign in')
|
||||
end
|
||||
|
||||
When /^I follow the sign up link$/ do
|
||||
click_link('Sign up')
|
||||
end
|
||||
|
||||
When /^I fill in the sign up form$/ do
|
||||
@user = Factory.build(:user)
|
||||
fill_in('Email', :with => @user.email)
|
||||
fill_in('Password', :with => @user.password)
|
||||
fill_in('Password confirmation', :with => @user.password)
|
||||
click_button('Sign up')
|
||||
end
|
@ -1,20 +0,0 @@
|
||||
Given /^a track named "([^"]*)"$/ do |name|
|
||||
@track = Factory.create(:track, :name => name)
|
||||
file = File.new("#{Rails.root}/features/fixtures/test.mp3")
|
||||
@track.save_with_file(file, 'audio/mpeg')
|
||||
end
|
||||
|
||||
Given /^the following tracks:$/ do |table|
|
||||
table.hashes.each do |h|
|
||||
Factory.create(:track, h)
|
||||
end
|
||||
end
|
||||
|
||||
Then /^I should see an audio player$/ do
|
||||
page.should have_xpath '//audio'
|
||||
end
|
||||
|
||||
Then /^it should provide an audio stream for "([^"]*)"$/ do |name|
|
||||
page.should have_xpath "//audio[@src='#{stream_track_path(@track)}']"
|
||||
visit find('audio')[:src]
|
||||
end
|
@ -1,12 +0,0 @@
|
||||
Given /^a user with "([^"]*)" email address exists$/ do |email|
|
||||
Factory.create(:user, :email => email)
|
||||
end
|
||||
|
||||
When /^I register with "([^"]*)" email address$/ do |email|
|
||||
visit new_user_path
|
||||
user = Factory.build(:user)
|
||||
fill_in('Email', :with => email)
|
||||
fill_in('Password', :with => user.password)
|
||||
fill_in('Password confirmation', :with => user.password)
|
||||
click_button('Sign up')
|
||||
end
|
@ -1,211 +0,0 @@
|
||||
# TL;DR: YOU SHOULD DELETE THIS FILE
|
||||
#
|
||||
# This file was generated by Cucumber-Rails and is only here to get you a head start
|
||||
# These step definitions are thin wrappers around the Capybara/Webrat API that lets you
|
||||
# visit pages, interact with widgets and make assertions about page content.
|
||||
#
|
||||
# If you use these step definitions as basis for your features you will quickly end up
|
||||
# with features that are:
|
||||
#
|
||||
# * Hard to maintain
|
||||
# * Verbose to read
|
||||
#
|
||||
# A much better approach is to write your own higher level step definitions, following
|
||||
# the advice in the following blog posts:
|
||||
#
|
||||
# * http://benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories.html
|
||||
# * http://dannorth.net/2011/01/31/whose-domain-is-it-anyway/
|
||||
# * http://elabs.se/blog/15-you-re-cuking-it-wrong
|
||||
#
|
||||
|
||||
|
||||
require 'uri'
|
||||
require 'cgi'
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "selectors"))
|
||||
|
||||
module WithinHelpers
|
||||
def with_scope(locator)
|
||||
locator ? within(*selector_for(locator)) { yield } : yield
|
||||
end
|
||||
end
|
||||
World(WithinHelpers)
|
||||
|
||||
# Single-line step scoper
|
||||
When /^(.*) within (.*[^:])$/ do |step, parent|
|
||||
with_scope(parent) { When step }
|
||||
end
|
||||
|
||||
# Multi-line step scoper
|
||||
When /^(.*) within (.*[^:]):$/ do |step, parent, table_or_string|
|
||||
with_scope(parent) { When "#{step}:", table_or_string }
|
||||
end
|
||||
|
||||
Given /^(?:|I )am on (.+)$/ do |page_name|
|
||||
visit path_to(page_name)
|
||||
end
|
||||
|
||||
When /^(?:|I )go to (.+)$/ do |page_name|
|
||||
visit path_to(page_name)
|
||||
end
|
||||
|
||||
When /^(?:|I )press "([^"]*)"$/ do |button|
|
||||
click_button(button)
|
||||
end
|
||||
|
||||
When /^(?:|I )follow "([^"]*)"$/ do |link|
|
||||
click_link(link)
|
||||
end
|
||||
|
||||
When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
|
||||
fill_in(field, :with => value)
|
||||
end
|
||||
|
||||
When /^(?:|I )fill in "([^"]*)" for "([^"]*)"$/ do |value, field|
|
||||
fill_in(field, :with => value)
|
||||
end
|
||||
|
||||
# Use this to fill in an entire form with data from a table. Example:
|
||||
#
|
||||
# When I fill in the following:
|
||||
# | Account Number | 5002 |
|
||||
# | Expiry date | 2009-11-01 |
|
||||
# | Note | Nice guy |
|
||||
# | Wants Email? | |
|
||||
#
|
||||
# TODO: Add support for checkbox, select og option
|
||||
# based on naming conventions.
|
||||
#
|
||||
When /^(?:|I )fill in the following:$/ do |fields|
|
||||
fields.rows_hash.each do |name, value|
|
||||
When %{I fill in "#{name}" with "#{value}"}
|
||||
end
|
||||
end
|
||||
|
||||
When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
|
||||
select(value, :from => field)
|
||||
end
|
||||
|
||||
When /^(?:|I )check "([^"]*)"$/ do |field|
|
||||
check(field)
|
||||
end
|
||||
|
||||
When /^(?:|I )uncheck "([^"]*)"$/ do |field|
|
||||
uncheck(field)
|
||||
end
|
||||
|
||||
When /^(?:|I )choose "([^"]*)"$/ do |field|
|
||||
choose(field)
|
||||
end
|
||||
|
||||
When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
|
||||
attach_file(field, File.expand_path(path))
|
||||
end
|
||||
|
||||
Then /^(?:|I )should see "([^"]*)"$/ do |text|
|
||||
if page.respond_to? :should
|
||||
page.should have_content(text)
|
||||
else
|
||||
assert page.has_content?(text)
|
||||
end
|
||||
end
|
||||
|
||||
Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
|
||||
regexp = Regexp.new(regexp)
|
||||
|
||||
if page.respond_to? :should
|
||||
page.should have_xpath('//*', :text => regexp)
|
||||
else
|
||||
assert page.has_xpath?('//*', :text => regexp)
|
||||
end
|
||||
end
|
||||
|
||||
Then /^(?:|I )should not see "([^"]*)"$/ do |text|
|
||||
if page.respond_to? :should
|
||||
page.should have_no_content(text)
|
||||
else
|
||||
assert page.has_no_content?(text)
|
||||
end
|
||||
end
|
||||
|
||||
Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
|
||||
regexp = Regexp.new(regexp)
|
||||
|
||||
if page.respond_to? :should
|
||||
page.should have_no_xpath('//*', :text => regexp)
|
||||
else
|
||||
assert page.has_no_xpath?('//*', :text => regexp)
|
||||
end
|
||||
end
|
||||
|
||||
Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
|
||||
with_scope(parent) do
|
||||
field = find_field(field)
|
||||
field_value = (field.tag_name == 'textarea') ? field.text : field.value
|
||||
if field_value.respond_to? :should
|
||||
field_value.should =~ /#{value}/
|
||||
else
|
||||
assert_match(/#{value}/, field_value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
|
||||
with_scope(parent) do
|
||||
field = find_field(field)
|
||||
field_value = (field.tag_name == 'textarea') ? field.text : field.value
|
||||
if field_value.respond_to? :should_not
|
||||
field_value.should_not =~ /#{value}/
|
||||
else
|
||||
assert_no_match(/#{value}/, field_value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
|
||||
with_scope(parent) do
|
||||
field_checked = find_field(label)['checked']
|
||||
if field_checked.respond_to? :should
|
||||
field_checked.should be_true
|
||||
else
|
||||
assert field_checked
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
|
||||
with_scope(parent) do
|
||||
field_checked = find_field(label)['checked']
|
||||
if field_checked.respond_to? :should
|
||||
field_checked.should be_false
|
||||
else
|
||||
assert !field_checked
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Then /^(?:|I )should be on (.+)$/ do |page_name|
|
||||
current_path = URI.parse(current_url).path
|
||||
if current_path.respond_to? :should
|
||||
current_path.should == path_to(page_name)
|
||||
else
|
||||
assert_equal path_to(page_name), current_path
|
||||
end
|
||||
end
|
||||
|
||||
Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
|
||||
query = URI.parse(current_url).query
|
||||
actual_params = query ? CGI.parse(query) : {}
|
||||
expected_params = {}
|
||||
expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
|
||||
|
||||
if actual_params.respond_to? :should
|
||||
actual_params.should == expected_params
|
||||
else
|
||||
assert_equal expected_params, actual_params
|
||||
end
|
||||
end
|
||||
|
||||
Then /^show me the page$/ do
|
||||
save_and_open_page
|
||||
end
|
@ -1,52 +0,0 @@
|
||||
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
|
||||
# It is recommended to regenerate this file in the future when you upgrade to a
|
||||
# newer version of cucumber-rails. Consider adding your own code to a new file
|
||||
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
|
||||
# files.
|
||||
|
||||
require 'cucumber/rails'
|
||||
|
||||
# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
|
||||
# order to ease the transition to Capybara we set the default here. If you'd
|
||||
# prefer to use XPath just remove this line and adjust any selectors in your
|
||||
# steps to use the XPath syntax.
|
||||
Capybara.default_selector = :css
|
||||
|
||||
# By default, any exception happening in your Rails application will bubble up
|
||||
# to Cucumber so that your scenario will fail. This is a different from how
|
||||
# your application behaves in the production environment, where an error page will
|
||||
# be rendered instead.
|
||||
#
|
||||
# Sometimes we want to override this default behaviour and allow Rails to rescue
|
||||
# exceptions and display an error page (just like when the app is running in production).
|
||||
# Typical scenarios where you want to do this is when you test your error pages.
|
||||
# There are two ways to allow Rails to rescue exceptions:
|
||||
#
|
||||
# 1) Tag your scenario (or feature) with @allow-rescue
|
||||
#
|
||||
# 2) Set the value below to true. Beware that doing this globally is not
|
||||
# recommended as it will mask a lot of errors for you!
|
||||
#
|
||||
ActionController::Base.allow_rescue = false
|
||||
|
||||
# Remove/comment out the lines below if your app doesn't have a database.
|
||||
# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
|
||||
begin
|
||||
DatabaseCleaner.strategy = :transaction
|
||||
rescue NameError
|
||||
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
|
||||
end
|
||||
|
||||
# You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios.
|
||||
# See the DatabaseCleaner documentation for details. Example:
|
||||
#
|
||||
# Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
|
||||
# DatabaseCleaner.strategy = :truncation, {:except => %w[widgets]}
|
||||
# end
|
||||
#
|
||||
# Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
|
||||
# DatabaseCleaner.strategy = :transaction
|
||||
# end
|
||||
#
|
||||
|
||||
load "#{Rails.root.to_s}/db/schema.rb"
|
@ -1,21 +0,0 @@
|
||||
module NavigationHelpers
|
||||
def path_to(page_name)
|
||||
case page_name
|
||||
when /^the home\s?page$/
|
||||
'/'
|
||||
when /^the track page for "([^\"]*)"$/
|
||||
track_path Track.find_by_name($1)
|
||||
else
|
||||
begin
|
||||
page_name =~ /^the (.*) page$/
|
||||
path_components = $1.split(/\s+/)
|
||||
self.send(path_components.push('path').join('_').to_sym)
|
||||
rescue NoMethodError, ArgumentError
|
||||
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
|
||||
"Now, go and add a mapping in #{__FILE__}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
World(NavigationHelpers)
|
@ -1,39 +0,0 @@
|
||||
module HtmlSelectorsHelpers
|
||||
# Maps a name to a selector. Used primarily by the
|
||||
#
|
||||
# When /^(.+) within (.+)$/ do |step, scope|
|
||||
#
|
||||
# step definitions in web_steps.rb
|
||||
#
|
||||
def selector_for(locator)
|
||||
case locator
|
||||
|
||||
when "the page"
|
||||
"html > body"
|
||||
|
||||
# Add more mappings here.
|
||||
# Here is an example that pulls values out of the Regexp:
|
||||
#
|
||||
# when /^the (notice|error|info) flash$/
|
||||
# ".flash.#{$1}"
|
||||
|
||||
# You can also return an array to use a different selector
|
||||
# type, like:
|
||||
#
|
||||
# when /the header/
|
||||
# [:xpath, "//header"]
|
||||
|
||||
# This allows you to provide a quoted selector as the scope
|
||||
# for "within" steps as was previously the default for the
|
||||
# web steps:
|
||||
when /^"(.+)"$/
|
||||
$1
|
||||
|
||||
else
|
||||
raise "Can't find mapping from \"#{locator}\" to a selector.\n" +
|
||||
"Now, go and add a mapping in #{__FILE__}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
World(HtmlSelectorsHelpers)
|
@ -1,27 +0,0 @@
|
||||
Feature: Tracks
|
||||
|
||||
So that I can listen music
|
||||
As a listener
|
||||
I want to add, manage and listen some tracks
|
||||
|
||||
Background:
|
||||
Given I am signed in
|
||||
|
||||
Scenario: Show track
|
||||
Given a track named "Mega song"
|
||||
When I go to the track page for "Mega song"
|
||||
Then I should see "Mega song" within "h1"
|
||||
|
||||
Scenario: Create track
|
||||
Given I am on the home page
|
||||
When I follow "Add a track"
|
||||
And I fill in "Name" with "Mega song"
|
||||
And I attach the file "features/fixtures/test.mp3" to "File"
|
||||
And I press "Upload"
|
||||
Then I should see "Mega song" within "h1"
|
||||
|
||||
Scenario: Listen track
|
||||
Given a track named "Mega song"
|
||||
When I go to the track page for "Mega song"
|
||||
Then I should see an audio player
|
||||
And it should provide an audio stream for "Mega song"
|
@ -1,16 +0,0 @@
|
||||
Feature: User
|
||||
|
||||
So that I can use the application
|
||||
As a visitor
|
||||
I want to register
|
||||
|
||||
Scenario: User registration
|
||||
Given I go to the home page
|
||||
When I follow the sign up link
|
||||
And I fill in the sign up form
|
||||
Then I should be redirected to the home page
|
||||
|
||||
Scenario: User can't register twice with the same email address
|
||||
Given a user with "unique@example.net" email address exists
|
||||
When I register with "unique@example.net" email address
|
||||
Then I should see "Email has already been taken"
|
@ -1,65 +0,0 @@
|
||||
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
|
||||
# It is recommended to regenerate this file in the future when you upgrade to a
|
||||
# newer version of cucumber-rails. Consider adding your own code to a new file
|
||||
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
|
||||
# files.
|
||||
|
||||
|
||||
unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
|
||||
|
||||
vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
|
||||
$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
|
||||
|
||||
begin
|
||||
require 'cucumber/rake/task'
|
||||
|
||||
namespace :cucumber do
|
||||
Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
|
||||
t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
|
||||
t.fork = true # You may get faster startup if you set this to false
|
||||
t.profile = 'default'
|
||||
end
|
||||
|
||||
Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
|
||||
t.binary = vendored_cucumber_bin
|
||||
t.fork = true # You may get faster startup if you set this to false
|
||||
t.profile = 'wip'
|
||||
end
|
||||
|
||||
Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
|
||||
t.binary = vendored_cucumber_bin
|
||||
t.fork = true # You may get faster startup if you set this to false
|
||||
t.profile = 'rerun'
|
||||
end
|
||||
|
||||
desc 'Run all features'
|
||||
task :all => [:ok, :wip]
|
||||
|
||||
task :statsetup do
|
||||
require 'rails/code_statistics'
|
||||
::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features')
|
||||
::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features')
|
||||
end
|
||||
end
|
||||
desc 'Alias for cucumber:ok'
|
||||
task :cucumber => 'cucumber:ok'
|
||||
|
||||
task :default => :cucumber
|
||||
|
||||
task :features => :cucumber do
|
||||
STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
|
||||
end
|
||||
|
||||
# In case we don't have ActiveRecord, append a no-op task that we can depend upon.
|
||||
task 'db:test:prepare' do
|
||||
end
|
||||
|
||||
task :stats => 'cucumber:statsetup'
|
||||
rescue LoadError
|
||||
desc 'cucumber rake task not available (cucumber not installed)'
|
||||
task :cucumber do
|
||||
abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@ -1,10 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
|
||||
if vendored_cucumber_bin
|
||||
load File.expand_path(vendored_cucumber_bin)
|
||||
else
|
||||
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
||||
require 'cucumber'
|
||||
load Cucumber::BINARY
|
||||
end
|
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
|
Loading…
x
Reference in New Issue
Block a user