casecumber-rails 1.0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +6 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +205 -0
- data/History.md +219 -0
- data/LICENSE +22 -0
- data/README.md +77 -0
- data/Rakefile +9 -0
- data/config/.gitignore +1 -0
- data/config/cucumber.yml +1 -0
- data/cucumber-rails.gemspec +46 -0
- data/dev_tasks/cucumber.rake +5 -0
- data/dev_tasks/rspec.rake +8 -0
- data/dev_tasks/yard.rake +0 -0
- data/dev_tasks/yard/default/layout/html/bubble_32x32.png +0 -0
- data/dev_tasks/yard/default/layout/html/footer.erb +5 -0
- data/dev_tasks/yard/default/layout/html/index.erb +1 -0
- data/dev_tasks/yard/default/layout/html/layout.erb +25 -0
- data/dev_tasks/yard/default/layout/html/logo.erb +1 -0
- data/dev_tasks/yard/default/layout/html/setup.rb +4 -0
- data/features/allow_rescue.feature +63 -0
- data/features/capybara_javascript_drivers.feature +87 -0
- data/features/database_cleaner.feature +44 -0
- data/features/emulate_javascript.feature +34 -0
- data/features/inspect_query_string.feature +37 -0
- data/features/install_cucumber_rails.feature +16 -0
- data/features/mongoid.feature +53 -0
- data/features/multiple_databases.feature +74 -0
- data/features/named_selectors.feature +33 -0
- data/features/no_database.feature +70 -0
- data/features/pseduo_class_selectors.feature +24 -0
- data/features/rerun_profile.feature +38 -0
- data/features/rest_api.feature +47 -0
- data/features/routing.feature +18 -0
- data/features/select_dates.feature +99 -0
- data/features/step_definitions/cucumber_rails_steps.rb +89 -0
- data/features/support/env.rb +37 -0
- data/features/test_unit.feature +43 -0
- data/lib/cucumber/rails.rb +23 -0
- data/lib/cucumber/rails/action_controller.rb +12 -0
- data/lib/cucumber/rails/application.rb +17 -0
- data/lib/cucumber/rails/capybara.rb +6 -0
- data/lib/cucumber/rails/capybara/javascript_emulation.rb +83 -0
- data/lib/cucumber/rails/capybara/select_dates_and_times.rb +50 -0
- data/lib/cucumber/rails/hooks.rb +4 -0
- data/lib/cucumber/rails/hooks/active_record.rb +21 -0
- data/lib/cucumber/rails/hooks/allow_rescue.rb +8 -0
- data/lib/cucumber/rails/hooks/database_cleaner.rb +13 -0
- data/lib/cucumber/rails/hooks/mail.rb +5 -0
- data/lib/cucumber/rails/rspec.rb +21 -0
- data/lib/cucumber/rails/world.rb +26 -0
- data/lib/cucumber/web/tableish.rb +118 -0
- data/lib/generators/cucumber/feature/USAGE +16 -0
- data/lib/generators/cucumber/feature/feature_generator.rb +28 -0
- data/lib/generators/cucumber/feature/named_arg.rb +19 -0
- data/lib/generators/cucumber/feature/templates/feature.erb +63 -0
- data/lib/generators/cucumber/feature/templates/steps.erb +14 -0
- data/lib/generators/cucumber/install/USAGE +15 -0
- data/lib/generators/cucumber/install/install_generator.rb +88 -0
- data/lib/generators/cucumber/install/templates/config/cucumber.yml.erb +8 -0
- data/lib/generators/cucumber/install/templates/script/cucumber +10 -0
- data/lib/generators/cucumber/install/templates/step_definitions/web_steps.rb.erb +192 -0
- data/lib/generators/cucumber/install/templates/step_definitions/web_steps_cs.rb.erb +127 -0
- data/lib/generators/cucumber/install/templates/step_definitions/web_steps_da.rb.erb +105 -0
- data/lib/generators/cucumber/install/templates/step_definitions/web_steps_de.rb.erb +127 -0
- data/lib/generators/cucumber/install/templates/step_definitions/web_steps_es.rb.erb +127 -0
- data/lib/generators/cucumber/install/templates/step_definitions/web_steps_ja.rb.erb +140 -0
- data/lib/generators/cucumber/install/templates/step_definitions/web_steps_ko.rb.erb +142 -0
- data/lib/generators/cucumber/install/templates/step_definitions/web_steps_no.rb.erb +105 -0
- data/lib/generators/cucumber/install/templates/step_definitions/web_steps_pt-BR.rb.erb +132 -0
- data/lib/generators/cucumber/install/templates/support/_rails_each_run.rb.erb +36 -0
- data/lib/generators/cucumber/install/templates/support/_rails_prefork.rb.erb +1 -0
- data/lib/generators/cucumber/install/templates/support/capybara.rb +5 -0
- data/lib/generators/cucumber/install/templates/support/edit_warning.txt +5 -0
- data/lib/generators/cucumber/install/templates/support/paths.rb +33 -0
- data/lib/generators/cucumber/install/templates/support/rails.rb.erb +4 -0
- data/lib/generators/cucumber/install/templates/support/rails_spork.rb.erb +13 -0
- data/lib/generators/cucumber/install/templates/support/selectors.rb +39 -0
- data/lib/generators/cucumber/install/templates/support/web_steps_warning.txt +19 -0
- data/lib/generators/cucumber/install/templates/tasks/cucumber.rake.erb +60 -0
- data/spec/cucumber/web/tableish_spec.rb +239 -0
- data/spec/spec_helper.rb +3 -0
- metadata +514 -0
@@ -0,0 +1,89 @@
|
|
1
|
+
Given /^I have created a new Rails 3 app "([^"]*)" with cucumber\-rails support$/ do |app_name|
|
2
|
+
steps %Q{
|
3
|
+
When I successfully run `rails new #{app_name}`
|
4
|
+
Then it should pass with:
|
5
|
+
"""
|
6
|
+
README
|
7
|
+
"""
|
8
|
+
And I cd to "#{app_name}"
|
9
|
+
And I append to "Gemfile" with:
|
10
|
+
"""
|
11
|
+
gem "cucumber-rails", :group => :test, :path => "../../.."
|
12
|
+
gem "capybara", :group => :test
|
13
|
+
gem "rspec-rails", :group => :test
|
14
|
+
gem "database_cleaner", :group => :test
|
15
|
+
gem 'factory_girl', :group => :test
|
16
|
+
|
17
|
+
"""
|
18
|
+
And I successfully run `bundle exec rails generate cucumber:install`
|
19
|
+
}
|
20
|
+
if(ENV['ARUBA_REPORT_DIR'])
|
21
|
+
@aruba_report_start = Time.new
|
22
|
+
sleep(1)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Given /^a project without ActiveRecord$/ do
|
27
|
+
steps %Q{
|
28
|
+
Given I successfully run `rails new cuke-app`
|
29
|
+
And I cd to "cuke-app"
|
30
|
+
And I append to "Gemfile" with:
|
31
|
+
"""
|
32
|
+
gem "cucumber-rails", :group => :test, :path => "../../.."
|
33
|
+
gem "capybara", :group => :test
|
34
|
+
gem "rspec-rails", :group => :test
|
35
|
+
|
36
|
+
"""
|
37
|
+
And I successfully run `bundle exec rails generate cucumber:install`
|
38
|
+
And I overwrite "features/support/env.rb" with:
|
39
|
+
"""
|
40
|
+
require 'cucumber/rails'
|
41
|
+
|
42
|
+
"""
|
43
|
+
|
44
|
+
And I write to "config/application.rb" with:
|
45
|
+
"""
|
46
|
+
require File.expand_path('../boot', __FILE__)
|
47
|
+
|
48
|
+
require 'action_controller/railtie'
|
49
|
+
require 'action_mailer/railtie'
|
50
|
+
require 'active_resource/railtie'
|
51
|
+
require 'rails/test_unit/railtie'
|
52
|
+
|
53
|
+
Bundler.require(:default, Rails.env) if defined?(Bundler)
|
54
|
+
|
55
|
+
module CukeApp
|
56
|
+
class Application < Rails::Application
|
57
|
+
config.encoding = "utf-8"
|
58
|
+
config.filter_parameters += [:password]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
"""
|
63
|
+
And I remove the file "config/database.yml"
|
64
|
+
}
|
65
|
+
if(ENV['ARUBA_REPORT_DIR'])
|
66
|
+
@aruba_report_start = Time.new
|
67
|
+
sleep(1)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
And /^a cukes resource$/ do
|
72
|
+
steps %Q{
|
73
|
+
Given I write to "config/routes.rb" with:
|
74
|
+
"""
|
75
|
+
CukeApp::Application.routes.draw do
|
76
|
+
resources :cukes
|
77
|
+
end
|
78
|
+
|
79
|
+
"""
|
80
|
+
And I write to "app/controllers/cukes_controller.rb" with:
|
81
|
+
"""
|
82
|
+
class CukesController < ApplicationController
|
83
|
+
def index
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
"""
|
88
|
+
}
|
89
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../../lib')
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'rspec/expectations'
|
5
|
+
require 'aruba/cucumber'
|
6
|
+
|
7
|
+
Before do
|
8
|
+
@aruba_timeout_seconds = 120 # A long time needed some times
|
9
|
+
unset_bundler_env_vars
|
10
|
+
end
|
11
|
+
|
12
|
+
if(ENV['ARUBA_REPORT_DIR'])
|
13
|
+
# Override reporting behaviour so we don't document all files, only the ones
|
14
|
+
# that have been created after @aruba_report_start (a Time object). This is
|
15
|
+
# given a value after the Rails app is generated (see cucumber_rails_steps.rb)
|
16
|
+
module Aruba
|
17
|
+
module Reporting
|
18
|
+
def children(dir)
|
19
|
+
children = Dir["#{dir}/*"].sort
|
20
|
+
|
21
|
+
# include
|
22
|
+
children = children.select do |child|
|
23
|
+
File.directory?(child) ||
|
24
|
+
(@aruba_report_start && File.stat(child).mtime > @aruba_report_start)
|
25
|
+
end
|
26
|
+
|
27
|
+
# exclude
|
28
|
+
children = children.reject do |child|
|
29
|
+
child =~ /Gemfile/ ||
|
30
|
+
child =~ /\.log$/
|
31
|
+
end
|
32
|
+
|
33
|
+
children
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
Feature: Run with Test::Unit
|
2
|
+
|
3
|
+
Scenario: Delete a widget
|
4
|
+
Given I have created a new Rails 3 app "widgets" with cucumber-rails support
|
5
|
+
And I overwrite "Gemfile" with:
|
6
|
+
"""
|
7
|
+
gem 'rails'
|
8
|
+
gem 'sqlite3'
|
9
|
+
gem "cucumber-rails", :group => :test, :path => "../../.."
|
10
|
+
gem "capybara", :group => :test
|
11
|
+
gem "database_cleaner", :group => :test
|
12
|
+
gem 'factory_girl', :group => :test
|
13
|
+
|
14
|
+
"""
|
15
|
+
And I successfully run `rails generate scaffold widget name:string`
|
16
|
+
And I write to "features/f.feature" with:
|
17
|
+
"""
|
18
|
+
Feature: Widget inventory
|
19
|
+
Scenario: Delete a widget
|
20
|
+
Given there is a widget named "wrench"
|
21
|
+
When I go to the widgets page
|
22
|
+
Then I should see "wrench"
|
23
|
+
"""
|
24
|
+
And I write to "features/step_definitions/s.rb" with:
|
25
|
+
"""
|
26
|
+
Given /^there is a widget named "([^"]*)"$/ do |name|
|
27
|
+
Factory(:widget, :name => name)
|
28
|
+
end
|
29
|
+
"""
|
30
|
+
And I write to "features/support/factories.rb" with:
|
31
|
+
"""
|
32
|
+
Factory.define :widget do |f|
|
33
|
+
f.name 'testwidget'
|
34
|
+
end
|
35
|
+
"""
|
36
|
+
When I run `bundle exec rake db:migrate`
|
37
|
+
And I run `bundle exec rake cucumber`
|
38
|
+
Then it should pass with:
|
39
|
+
"""
|
40
|
+
1 scenario (1 passed)
|
41
|
+
3 steps (3 passed)
|
42
|
+
"""
|
43
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'cucumber/rails/application'
|
3
|
+
ENV["RAILS_ENV"] ||= "test"
|
4
|
+
ENV["RAILS_ROOT"] ||= File.expand_path(File.dirname(caller.detect{|f| f =~ /\/env\.rb:/}) + '/../..')
|
5
|
+
require File.expand_path(ENV["RAILS_ROOT"] + '/config/environment')
|
6
|
+
require 'cucumber/rails/action_controller'
|
7
|
+
|
8
|
+
if defined?(ActiveRecord::Base)
|
9
|
+
require 'rails/test_help'
|
10
|
+
else
|
11
|
+
require 'action_dispatch/testing/test_process'
|
12
|
+
require 'action_dispatch/testing/integration'
|
13
|
+
end
|
14
|
+
|
15
|
+
if !Rails.application.config.cache_classes
|
16
|
+
warn "WARNING: You have set Rails' config.cache_classes to false (most likely in config/environments/cucumber.rb). This setting is known to cause problems with database transactions. Set config.cache_classes to true if you want to use transactions. For more information see https://rspec.lighthouseapp.com/projects/16211/tickets/165."
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'cucumber/rails/world'
|
20
|
+
require 'cucumber/rails/hooks'
|
21
|
+
require 'cucumber/rails/capybara'
|
22
|
+
|
23
|
+
require 'cucumber/web/tableish'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
ActionController::Base.class_eval do
|
2
|
+
cattr_accessor :allow_rescue
|
3
|
+
end
|
4
|
+
|
5
|
+
class ActionDispatch::ShowExceptions
|
6
|
+
alias __cucumber_orig_call__ call
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
env['action_dispatch.show_exceptions'] = !!ActionController::Base.allow_rescue
|
10
|
+
__cucumber_orig_call__(env)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rails/application'
|
2
|
+
|
3
|
+
# Make sure the ActionDispatch::ShowExceptions middleware is always enabled,
|
4
|
+
# regardless of what is in config/environments/test.rb
|
5
|
+
# Instead we are overriding ActionDispatch::ShowExceptions to be able to
|
6
|
+
# toggle whether or not exceptions are raised.
|
7
|
+
class Rails::Application
|
8
|
+
alias __cucumber_orig_initialize__ initialize!
|
9
|
+
|
10
|
+
def initialize!
|
11
|
+
ad = config.action_dispatch
|
12
|
+
def ad.show_exceptions
|
13
|
+
true
|
14
|
+
end
|
15
|
+
__cucumber_orig_initialize__
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Cucumber
|
2
|
+
module Rails
|
3
|
+
module Capybara
|
4
|
+
module JavascriptEmulation
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
alias_method :click_without_javascript_emulation, :click
|
8
|
+
alias_method :click, :click_with_javascript_emulation
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def click_with_javascript_emulation
|
13
|
+
if link_with_non_get_http_method?
|
14
|
+
::Capybara::RackTest::Form.new(driver, js_form(element_node.document, self[:href], emulated_method)).submit(self)
|
15
|
+
else
|
16
|
+
click_without_javascript_emulation
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def js_form(document, action, emulated_method, method = 'POST')
|
23
|
+
js_form = document.create_element('form')
|
24
|
+
js_form['action'] = action
|
25
|
+
js_form['method'] = method
|
26
|
+
|
27
|
+
if emulated_method and emulated_method.downcase != method.downcase
|
28
|
+
input = document.create_element('input')
|
29
|
+
input['type'] = 'hidden'
|
30
|
+
input['name'] = '_method'
|
31
|
+
input['value'] = emulated_method
|
32
|
+
js_form.add_child(input)
|
33
|
+
end
|
34
|
+
|
35
|
+
js_form
|
36
|
+
end
|
37
|
+
|
38
|
+
def link_with_non_get_http_method?
|
39
|
+
if ::Rails.version.to_f >= 3.0
|
40
|
+
tag_name == 'a' && element_node['data-method'] && element_node['data-method'] =~ /(?:delete|put|post)/
|
41
|
+
else
|
42
|
+
tag_name == 'a' && element_node['onclick'] && element_node['onclick'] =~ /var f = document\.createElement\('form'\); f\.style\.display = 'none';/
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def emulated_method
|
47
|
+
if ::Rails.version.to_f >= 3.0
|
48
|
+
element_node['data-method']
|
49
|
+
else
|
50
|
+
element_node['onclick'][/m\.setAttribute\('value', '([^']*)'\)/, 1]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def element_node
|
55
|
+
if self.respond_to? :native
|
56
|
+
self.native
|
57
|
+
else
|
58
|
+
warn "DEPRECATED: cucumber-rails loves you, just not your version of Capybara. Please update Capybara to >= 0.4.0"
|
59
|
+
self.node
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class Capybara::RackTest::Node
|
68
|
+
include ::Cucumber::Rails::Capybara::JavascriptEmulation
|
69
|
+
end
|
70
|
+
|
71
|
+
Before('~@no-js-emulation') do
|
72
|
+
# Enable javascript emulation
|
73
|
+
::Capybara::RackTest::Node.class_eval do
|
74
|
+
alias_method :click, :click_with_javascript_emulation
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
Before('@no-js-emulation') do
|
79
|
+
# Disable javascript emulation
|
80
|
+
::Capybara::RackTest::Node.class_eval do
|
81
|
+
alias_method :click, :click_without_javascript_emulation
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Cucumber
|
2
|
+
module Rails
|
3
|
+
module Capybara
|
4
|
+
module SelectDatesAndTimes
|
5
|
+
def select_date(field, options = {})
|
6
|
+
date = Date.parse(options[:with])
|
7
|
+
base_dom_id = get_base_dom_id_from_label_tag(field)
|
8
|
+
|
9
|
+
find(:xpath, "//select[@id='#{base_dom_id}_1i']").select(date.year.to_s)
|
10
|
+
find(:xpath, "//select[@id='#{base_dom_id}_2i']").select(I18n.l date, :format => '%B')
|
11
|
+
find(:xpath, "//select[@id='#{base_dom_id}_3i']").select(date.day.to_s)
|
12
|
+
end
|
13
|
+
|
14
|
+
def select_time(field, options = {})
|
15
|
+
time = Time.zone.parse(options[:with])
|
16
|
+
base_dom_id = get_base_dom_id_from_label_tag(field)
|
17
|
+
|
18
|
+
find(:xpath, "//select[@id='#{base_dom_id}_4i']").select(time.hour.to_s.rjust(2, '0'))
|
19
|
+
find(:xpath, "//select[@id='#{base_dom_id}_5i']").select(time.min.to_s.rjust(2, '0'))
|
20
|
+
end
|
21
|
+
|
22
|
+
def select_datetime(field, options = {})
|
23
|
+
select_date(field, options)
|
24
|
+
select_time(field, options)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# @example "event_starts_at_"
|
30
|
+
def get_base_dom_id_from_label_tag(field)
|
31
|
+
find(:xpath, "//label[contains(., '#{field}')]")['for'].gsub(/(_[1-5]i)$/, '')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
World(::Cucumber::Rails::Capybara::SelectDatesAndTimes)
|
39
|
+
|
40
|
+
When /^(?:|I )select "([^"]+)" as the "([^"]+)" time$/ do |time, selector|
|
41
|
+
select_time(selector, :with => time)
|
42
|
+
end
|
43
|
+
|
44
|
+
When /^(?:|I )select "([^"]+)" as the "([^"]+)" date$/ do |date, selector|
|
45
|
+
select_date(selector, :with => date)
|
46
|
+
end
|
47
|
+
|
48
|
+
When /^(?:|I )select "([^"]+)" as the "([^"]+)" date and time$/ do |datetime, selector|
|
49
|
+
select_datetime(selector, :with => datetime)
|
50
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
if defined?(ActiveRecord::Base)
|
2
|
+
class ActiveRecord::Base
|
3
|
+
mattr_accessor :shared_connection
|
4
|
+
@@shared_connection = nil
|
5
|
+
|
6
|
+
def self.connection
|
7
|
+
@@shared_connection || retrieve_connection
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
Before('@javascript') do
|
12
|
+
# Forces all threads to share the same connection. This works on
|
13
|
+
# Capybara because it starts the web server in a thread.
|
14
|
+
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
|
15
|
+
end
|
16
|
+
|
17
|
+
Before('~@javascript') do
|
18
|
+
# Do not use a shared connection unless we're in a @javascript scenario
|
19
|
+
ActiveRecord::Base.shared_connection = nil
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'cucumber/rails/world'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rspec/rails/matchers'
|
5
|
+
|
6
|
+
[Cucumber::Rails::World, ActionController::Integration::Session].each do |klass|
|
7
|
+
klass.class_eval do
|
8
|
+
include RSpec::Matchers
|
9
|
+
end
|
10
|
+
end
|
11
|
+
rescue LoadError => try_rspec_1
|
12
|
+
require 'spec/expectations'
|
13
|
+
require 'spec/rails'
|
14
|
+
|
15
|
+
[Cucumber::Rails::World, ActionController::Integration::Session].each do |klass|
|
16
|
+
klass.class_eval do
|
17
|
+
include Spec::Matchers
|
18
|
+
include Spec::Rails::Matchers if defined?(Spec::Rails::Matchers)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|