Commit e2bec5da authored by Antonio Terceiro's avatar Antonio Terceiro

Imported Upstream version 1.4.2

parents
pkg
doc
tmp
coverage
.bundle
.rvmrc
.yardoc/
.rvmrc
.cucumber.rerun
gemfiles/*.lock
Gemfile.lock
Gemfile.appraisal.lock
--format progress --colour
rvm:
- 1.9.3
- 2.0.0
# whitelist
branches:
only:
- master
gemfile:
- gemfiles/capybara_1_1.gemfile
- gemfiles/rails_4_1.gemfile
- gemfiles/rails_4_0.gemfile
- gemfiles/rails_3_2.gemfile
- gemfiles/rails_3_1.gemfile
- gemfiles/rails_3_0.gemfile
matrix:
exclude:
- rvm: 2.0.0
gemfile: gemfiles/capybara_1_1.gemfile
- rvm: 2.0.0
gemfile: gemfiles/rails_3_1.gemfile
- rvm: 2.0.0
gemfile: gemfiles/rails_3_0.gemfile
# Needed for selenium browser
before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
notifications:
email:
- cukes-devs@googlegroups.com
irc:
- "irc.freenode.org#cucumber"
appraise "rails_3_0" do
gem "rails", "~> 3.0.20"
gem "capybara", "~> 2.0.2"
gem "turn", "~> 0.9.6"
gem "rspec-rails", "~> 3.1.0"
gem "jquery-rails", "~> 2.2.1"
gem "uglifier", "~> 2.1.0"
gem "sqlite3", "~> 1.3.7"
gem "database_cleaner", "~> 1.0.1"
end
appraise "rails_3_1" do
gem "rails", "~> 3.1.11"
gem "capybara", "~> 2.0.2"
gem "turn", "~> 0.9.6"
gem "rspec-rails", "~> 3.1.0"
gem "sass-rails", "~> 3.1.7"
gem "coffee-rails", "~> 3.1.1"
gem "jquery-rails", "~> 2.2.1"
gem "uglifier", "~> 2.1.0"
gem "sqlite3", "~> 1.3.7"
gem "database_cleaner", "~> 1.0.1"
end
appraise "rails_3_2" do
gem "rails", "~> 3.2.12"
gem "capybara", "~> 2.0.2"
gem "turn", "~> 0.9.6"
gem "rspec-rails", "~> 3.1.0"
gem "sass-rails", "~> 3.2.6"
gem "coffee-rails", "~> 3.2.2"
gem "jquery-rails", "~> 2.2.1"
gem "uglifier", "~> 2.1.0"
gem "sqlite3", "~> 1.3.7"
gem "database_cleaner", "~> 1.0.1"
end
appraise "capybara_1_1" do
gem "capybara", "~> 1.1.2"
gem "rails", "~> 3.2.12"
gem "turn", "~> 0.9.6"
gem "rspec-rails", "~> 3.1.0"
gem "sass-rails", "~> 3.2.6"
gem "coffee-rails", "~> 3.2.2"
gem "jquery-rails", "~> 2.2.1"
gem "uglifier", "~> 2.1.0"
gem "sqlite3", "~> 1.3.7"
gem "database_cleaner", "~> 1.0.1"
end
appraise "rails_4_0" do
gem "protected_attributes", "~> 1.0.3"
gem "rails", "~> 4.0.0"
gem "railties", "~> 4.0.0"
gem "capybara", "~> 2.0.2"
gem "turn", "~> 0.9.6"
gem "rspec-rails", "~> 3.1.0"
gem "sass-rails", "~> 4.0.0"
gem "coffee-rails", "~> 4.0.0"
gem "jquery-rails", "~> 2.2.1"
gem "uglifier", "~> 2.1.0"
gem "sqlite3", "~> 1.3.7"
gem "database_cleaner", "~> 1.0.1"
end
appraise "rails_4_1" do
gem "protected_attributes", "~> 1.0.3"
gem "rails", "~> 4.1.0"
gem "railties", "~> 4.1.0"
gem "capybara", "~> 2.0.2"
gem "rspec-rails", "~> 3.1.0"
gem "sass-rails", "~> 4.0.0"
gem "coffee-rails", "~> 4.0.0"
gem "jquery-rails", "~> 2.2.1"
gem "uglifier", "~> 2.1.0"
gem "sqlite3", "~> 1.3.7"
gem "database_cleaner", "~> 1.0.1"
end
## About to create a new Github Issue?
We appreciate that. But before you do, please learn our basic rules:
* This is not a support forum. If you have a question, please go to [The Cukes Google Group](http://groups.google.com/group/cukes).
* Do you have an idea for a new feature? Then don't expect it to be implemented unless you or someone else sends a [pull request](https://help.github.com/articles/using-pull-requests). You might be better to start a discussion on [the google group](http://groups.google.com/group/cukes).
* Reporting a bug? Please tell us:
* which version of Cucumber you're using
* which version of Ruby you're using.
* How to reproduce it. Bugs with a failing test in a [pull request](https://help.github.com/articles/using-pull-requests) get fixed much quicker. Some bugs may never be fixed.
* Want to paste some code or output? Put \`\`\` on a line above and below your code/output. See [GFM](https://help.github.com/articles/github-flavored-markdown)'s *Fenced Code Blocks* for details.
* We love [pull requests](https://help.github.com/articles/using-pull-requests). But if you don't have a test to go with it we probably won't merge it.
# Contributing to cucumber-rails
This document is a guide for those maintaining cucumber-Rails, and others who would like to submit patches.
## Note on Patches/Pull Requests
* Fork the project. Make a branch for your change.
* Make your feature addition or bug fix.
* Make sure your patch is well covered by tests. We don't accept changes to cucumber-rails that aren't tested.
* Please do not change the Rakefile, version, or history.
(if you want to have your own version, that is fine but
bump version in a commit by itself so we can ignore when we merge your change)
* Send us a pull request.
## Running tests
gem install bundler
bundle install
bundle exec rake
## Release Process
* Make sure `History.md` is updated with the upcoming version number, and has entries for all fixes.
* No need to add a `History.md` header at this point - this should be done when a new change is made, later.
* Make sure you have up-to-date and clean copy of cucumber/cucumber.github.com.git at the same level as cucumber repo.
Now release it
bundle update
bundle exec rake
git commit -m "Release X.Y.Z"
rake release
### NOTE:
If after running the rake release task you get an eror similiar to this:
rake aborted!
Couldn't git push. `git push 2>&1' failed with the following output:
To git@github.com:cucumber/cucumber-rails.git
! [rejected] rails-2.3.x -> rails-2.3.x (non-fast-forward)
error: failed to push some refs to 'git@github.com:cucumber/cucumber-rails.git'
make sure that you have pulled all the recent changes from both the master and the rails-2.3.x branch
## Gaining Release Karma
To become a release manager, create a pull request adding your name to the list below, and include your Rubygems email address in the ticket. One of the existing Release managers will then add you.
Current release managers:
* Matt Wynne
* Aslak Hellesøy
* Kosmas Chatzimichalis
To grant release karma, issue the following command:
gem owner cucumber --add <NEW OWNER RUBYGEMS EMAIL>
source "https://rubygems.org"
# Test dependencies for Rails in the default test task, as test-generated
# apps do not run bundler for speed reasons. Kept here so they can be
# excluded from Appraisal-generated gemfiles.
gemspec
source "https://rubygems.org"
gemspec
This diff is collapsed.
The MIT License
Copyright (c) 2008,2009,2010,2011,2012,2013 Aslak Hellesøy and the Cucumber Team.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Cucumber-Rails
[![Build Status](https://secure.travis-ci.org/cucumber/cucumber-rails.png?branch=master)](http://travis-ci.org/cucumber/cucumber-rails)
[![Code Climate](https://codeclimate.com/github/cucumber/cucumber-rails.png)](https://codeclimate.com/github/cucumber/cucumber-rails)
[![Dependency Status](https://gemnasium.com/Kosmas/cucumber-rails.svg)](https://gemnasium.com/Kosmas/cucumber-rails)
[![PullReview stats](https://www.pullreview.com/github/cucumber/cucumber-rails/badges/master.svg?)](https://www.pullreview.com/github/cucumber/cucumber-rails/reviews/master)
Cucumber-Rails brings Cucumber to Rails 3.x and 4.x. For Rails 2.3.x support, see the [rails-2.3.x branch](https://github.com/cucumber/cucumber-rails/tree/rails-2.3.x).
## Installation
Before you can use the generator, add the gem to your project's Gemfile as follows:
group :test do
gem 'cucumber-rails', :require => false
# database_cleaner is not required, but highly recommended
gem 'database_cleaner'
end
Then install it by running:
bundle install
Learn about the various options:
rails generate cucumber:install --help
Finally, bootstrap your Rails app, for example:
rails generate cucumber:install
## Running Cucumber
With Rake:
rake cucumber
Without Rake:
[bundle exec] cucumber
## Configuration options
By default, cucumber-rails runs `DatabaseCleaner.start` and `DatabaseCleaner.clean` before and after your scenarios. You can disable this behaviour like so:
# features/support/env.rb
# ...
Cucumber::Rails::Database.autorun_database_cleaner = false
## Upgrading from a previous version
When upgrading from a previous version it is recommended that you rerun:
rails generate cucumber:install
## Bugs and feature requests
The *only* way to have a bug fixed or a new feature accepted is to describe it with a Cucumber feature. Let's say you think you have found a bug in the cucumber:install generator. Fork this project, clone it to your workstation and check out a branch with a descriptive name:
git clone git@github.com:you/cucumber-rails.git
git checkout -b bug-install-generator
Start by making sure you can run the existing features. Now, create a feature that demonstrates what's wrong. See the existing features for examples. When you have a failing feature that reproduces the bug, commit, push and send a pull request. Someone from the Cucumber-Rails team will review it and hopefully create a fix.
If you know how to fix the bug yourself, make a second commit (after committing the failing feature) before you send the pull request.
### Setting up your environment
I strongly recommend rvm and ruby 1.9.3. When you have that, cd into your cucumber-rails repository and:
gem install bundler
bundle install
### Running all tests
With all dependencies installed, all specs and features should pass:
rake
### Running Appraisal suite
In order to test against multiple versions of key dependencies, the [Appraisal](https://github.com/thoughtbot/appraisal) is used to generate multiple gemfiles, stored in the `gemfiles/` directory. Normally these will only run on Travis; however, if you want to run the full test suite against all gemfiles, run the following commands:
appraisal install
appraisal rake test
To run the suite against a named gemfile, use the following:
appraisal rails_4_1 rake test
To remove and rebuild the different gemfiles (for example, to update a rails version or its dependencies), use the following:
appraisal install
### Adding dependencies
To support the multiple-gemfile testing, when adding a new dependency the following rules apply:
1. If it's a runtime dependency of the gem, add it to the gemspec
2. If it's a primary development dependency, add it to the gemspec
3. If it's a dependency of a generated rails app in a test, add it to the Gemfile (for local test runs) and each appraisal section (if necessary).
For example, rspec is a primary development dependency, so it lives in the gemspec. By contrast, coffee-rails is a dependency of apps generated with rails 3.1 and 3.2, so lives in the main Gemfile and the rails 3.1 and 3.2 appraisal sections.
### NOTE
If you get an error while trying to run the tests locally, similar to the one below:
Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
you would need to install a javascript runtime.
You can do that in ubuntu by using:
sudo apt-get install nodejs
# encoding: utf-8
CUCUMBER_RAILS_VERSION = Gem::Specification.load(File.dirname(__FILE__) + '/cucumber-rails.gemspec').version.version
require 'rubygems'
require 'bundler'
require 'bundler/setup'
require 'appraisal'
require 'rdoc' # https://github.com/lsegal/yard/commit/b861dcc2d7f7e1fbbed7b552ac2e4f7caf68bafa
require 'rake/clean'
require 'pathname'
Bundler::GemHelper.install_tasks
$:.unshift(File.dirname(__FILE__) + '/lib')
Dir["#{File.dirname(__FILE__)}/dev_tasks/*.rake"].sort.each { |ext| load ext }
CLEAN.include('doc', 'tmp')
task :default => :test
task :test => [:spec, :cucumber]
namespace :test do
desc "Run tests against all gemfiles"
task :all do
Rake::Task['appraisal'].invoke('test')
end
desc "Run tests against specified gemfile, e.g. rake test:gemfile[rails_3_0]"
task :gemfile, :name do |task, args|
unless args.name && Pathname.new("gemfiles/#{args.name}.gemfile").exist?
raise ArgumentError "You must provide the name of an existing Appraisal gemfile, e.g. 'rake test:gemfile[rails_3_2]'"
end
Rake::Task["appraisal:#{args.name}"].invoke('test')
end
end
namespace :gemfiles do
desc "Install dependencies for all gemfiles"
task :install do
ENV['BUNDLE_GEMFILE'] = "Gemfile.appraisal"
Rake::Task['appraisal:install'].invoke
end
task :clean do
FileUtils.rm_rf("gemfiles/*")
end
desc "Rebuild generated gemfiles and install dependencies"
task :rebuild => [:clean, :install]
end
aruba-rvm.yml
<%
rerun_file = '.cucumber.rerun'
failing_scenarios = IO.read(rerun_file) rescue ''
path = if failing_scenarios.empty?
'features'
else
puts "Running failed scenarios"
failing_scenarios
end
opts = [
"--format #{path == 'features' ? 'progress' : 'pretty'}",
"--format rerun -o #{rerun_file}"
].join(' ')
%>
default: <%= path %> <%= opts %> --tags ~@broken
# -*- encoding: utf-8 -*-
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
Gem::Specification.new do |s|
s.name = 'cucumber-rails'
s.version = '1.4.2'
s.authors = ["Aslak Hellesøy", "Dennis Blöte", "Rob Holland"]
s.description = "Cucumber Generator and Runtime for Rails"
s.summary = "#{s.name}-#{s.version}"
s.email = 'cukes@googlegroups.com'
s.homepage = "http://cukes.info"
s.license = 'MIT'
s.add_runtime_dependency('capybara', ['>= 1.1.2', '< 3'])
s.add_runtime_dependency('cucumber', ['>= 1.3.8', '< 2'])
s.add_runtime_dependency('nokogiri', '~> 1.5')
s.add_runtime_dependency('rails', ['>= 3', '< 5'])
s.add_runtime_dependency('mime-types', ['>= 1.16', '< 3'])
# Main development dependencies
s.add_development_dependency('ammeter', ['>= 0.2.9', '< 2'])
s.add_development_dependency('appraisal', '>= 0.5.1')
s.add_development_dependency('aruba', '>= 0.4.11')
s.add_development_dependency('builder', ['>= 2.1.2', '< 4'])
s.add_development_dependency('bundler', '>= 1.3.5')
s.add_development_dependency('database_cleaner', '>= 0.7.2')
s.add_development_dependency('factory_girl', '>= 3.2')
s.add_development_dependency('rake', '>= 0.9.2.2')
s.add_development_dependency('rspec', '>= 2.2', '<= 3.1')
# For Documentation:
s.add_development_dependency('bcat', '>= 0.6.2')
s.add_development_dependency('rdiscount', '>= 2.0.7')
s.add_development_dependency('rdoc', '>= 3.4')
s.add_development_dependency('yard', '>= 0.8.7')
s.rubygems_version = ">= 1.6.1"
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_path = "lib"
end
require 'cucumber/rake/task'
Cucumber::Rake::Task.new
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new
require 'yard'
require 'yard/rake/yardoc_task'
SITE_DIR = File.expand_path(File.dirname(__FILE__) + '/../cucumber.github.com')
API_DIR = File.join(SITE_DIR, 'api', 'cucumber-rails', 'ruby', 'yardoc')
namespace :api do
file :dir do
unless File.directory?(SITE_DIR)
raise "You need to git clone git@github.com:cucumber/cucumber.github.com.git #{SITE_DIR}"
end
sh('git pull origin master')
mkdir_p API_DIR
end
template_path = File.expand_path(File.join(File.dirname(__FILE__), 'yard'))
YARD::Templates::Engine.register_template_path(template_path)
YARD::Rake::YardocTask.new(:yard) do |yard|
dir = API_DIR
mkdir_p dir
yard.options = ["--out", dir]
end
task :yard => :dir
task :release do
Dir.chdir(SITE_DIR) do
sh('git add .')
sh("git commit -m 'Update API docs for cucumber-rails v#{cucumber-rails::VERSION}'")
sh('git push origin master')
end
end
desc "Generate YARD docs for Cucumber-Rails' API"
task :doc => [:yard, :release]
end
<div id="footer">
Generated on <%= Time.now.strftime("%c") %> by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
<%= YARD::VERSION %> (ruby-<%= RUBY_VERSION %>).
</div>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<%= erb(:headers) %>
</head>
<body>
<script type="text/javascript" charset="utf-8">
if (window.top.frames.main) document.body.className = 'frames';
</script>
<div id="header">
<%= erb(:logo) %>
<%= erb(:breadcrumb) %>
<%= erb(:search) %>
<div class="clear"></div>
</div>
<iframe id="search_frame"></iframe>
<div id="content"><%= yieldall %></div>
<%= erb(:footer) %>
</body>
</html>
<h3><img src="<%= url_for('images/bubble_32x32.png') %>"></img> Cucumber-Rails <%= CUCUMBER_RAILS_VERSION %></h3>
def init
super
options[:serializer].serialize('/images/bubble_32x32.png', IO.read(File.dirname(__FILE__) + '/bubble_32x32.png'))
end
Feature: Allow Cucumber to rescue exceptions
Background: A controller that raises an exception
Given I have created a new Rails app "rails-3-app" and installed cucumber-rails
And I write to "app/controllers/posts_controller.rb" with:
"""
class PostsController < ApplicationController
def index
raise "There is an error in index"
end
end
"""
And I write to "config/routes.rb" with:
"""
Rails3App::Application.routes.draw do
resources :posts
end
"""
Scenario: Allow rescue
Given I write to "features/posts.feature" with:
"""
Feature: posts
@allow-rescue
Scenario: See posts
When I look at the posts
"""
And I write to "features/step_definitions/posts_steps.rb" with:
"""
When /^I look at the posts$/ do
visit '/posts'
end
"""
And I run `bundle exec rake db:migrate`
And I run `bundle exec cucumber`
Then it should pass with:
"""
1 scenario (1 passed)
1 step (1 passed)
"""
Scenario: Don't allow rescue
Given I write to "features/posts.feature" with:
"""
Feature: posts
Scenario: See them
When I look at the posts
"""
And I write to "features/step_definitions/posts_steps.rb" with:
"""
When /^I look at the posts$/ do
visit '/posts'
end
"""
And I run `bundle exec rake db:migrate`
And I run `bundle exec cucumber`
Then it should fail with:
"""
1 scenario (1 failed)
1 step (1 failed)
"""
@focus
Feature: Capybara Javascript Drivers
Background: A simple calendar app
Given I have created a new Rails app and installed cucumber-rails
And I successfully run `bundle exec rails g scaffold appointment name:string when:datetime`
And I write to "features/step_definitions/date_time_steps.rb" with:
"""
When /^(?:|I )select "([^"]+)" as the "([^"]+)" time$/ do |time, selector|
select_time(time, :from => selector)
end
When /^(?:|I )select "([^"]+)" as the "([^"]+)" date$/ do |date, selector|
select_date(date, :from => selector)
end
When /^(?:|I )select "([^"]+)" as the "([^"]+)" date and time$/ do |datetime, selector|
select_datetime(datetime, :from => selector)
end
"""
Scenario: Use a particular driver
Given I write to "features/create_appointment.feature" with:
"""
@javascript
Feature: Create appointments
Scenario: Constitution on May 17
Given I am on the new appointment page
And I fill in "Norway's constitution" for "Name"
And I select "2009-02-20 15:10:00 UTC" as the "When" date and time
And I press "Create Appointment"
Then I should see "Norway's constitution"
And I should see "2009-02-20 15:10:00 UTC"
"""
When I run `bundle exec rake db:migrate`
And I run `bundle exec rake cucumber`
Then it should pass with:
"""
1 scenario (1 passed)
6 steps (6 passed)
"""
Scenario: Mixed DB access
Given I write to "features/create_appointment.feature" with:
"""
@javascript
Feature: Create appointments
Scenario: Constitution on May 17
Given a random appointment
And I am viewing random appointment
Then I should see "Random appointment"
"""
And I write to "features/step_definitions/custom_steps.rb" with:
"""
Given /^a random appointment$/ do
@appointment = Appointment.create!(:name => 'Random appointment', :when => DateTime.now)
end
Given /^I am viewing random appointment$/ do
visit appointment_path(@appointment)
end
"""
When I run `bundle exec rake db:migrate`
And I run `bundle exec rake cucumber`
Then it should pass with:
"""
1 scenario (1 passed)
3 steps (3 passed)
"""
Feature: Choose javascript database strategy
When running a scenario with the @javascript tag, Capybara will fire up a web server
in the same process in a separate thread to your cukes. By default, this means ActiveRecord will give it a
separate database connection, which in turn means data you put into your database from
Cucumber step definitions (e.g. using FactoryGirl) won't be visible to the web server
until the database transaction is committed.
So if you use a transaction strategy for cleaning up your database at the end of a scenario,
it won't work for javascript scenarios by default.
There are two ways around this. One is to switch to a truncation strategy for javascript
scenarios. This is slower, but more reliable.
The alternative is to patch ActiveRecord to share a single database connection between
threads. This means you still get the speed benefits of using a transaction to roll back
your database, but you run the risk of the two threads stomping on one another as they
talk to the database.
Right now, the default behavior is to use truncation, but you can override this by telling
cucumber-rails which strategy to use for javascript scenarios.
The deletion strategy can be quicker for situations where truncation causes locks which
has been reported by some Oracle users.
Background:
Given I have created a new Rails app and installed cucumber-rails
And I have a "Widget" ActiveRecord model object
Scenario: Set the strategy to truncation and run a javascript scenario.
Given I append to "features/env.rb" with:
"""