cucumber-rails 1.7.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +197 -19
- data/CONTRIBUTING.md +16 -14
- data/LICENSE +1 -1
- data/README.md +27 -21
- data/lib/cucumber/rails.rb +23 -17
- data/lib/cucumber/rails/action_dispatch.rb +21 -0
- data/lib/cucumber/rails/application.rb +16 -7
- data/lib/cucumber/rails/capybara.rb +2 -0
- data/lib/cucumber/rails/capybara/javascript_emulation.rb +42 -21
- data/lib/cucumber/rails/capybara/select_dates_and_times.rb +3 -1
- data/lib/cucumber/rails/database.rb +24 -56
- data/lib/cucumber/rails/database/deletion_strategy.rb +13 -0
- data/lib/cucumber/rails/database/shared_connection_strategy.rb +27 -0
- data/lib/cucumber/rails/database/strategy.rb +33 -0
- data/lib/cucumber/rails/database/truncation_strategy.rb +13 -0
- data/lib/cucumber/rails/hooks.rb +2 -0
- data/lib/cucumber/rails/hooks/active_record.rb +8 -4
- data/lib/cucumber/rails/hooks/allow_rescue.rb +2 -0
- data/lib/cucumber/rails/hooks/database_cleaner.rb +11 -3
- data/lib/cucumber/rails/hooks/mail.rb +3 -1
- data/lib/cucumber/rails/rspec.rb +3 -1
- data/lib/cucumber/rails/world.rb +24 -7
- data/lib/generators/cucumber/{install/USAGE → USAGE} +0 -0
- data/lib/generators/cucumber/{install/install_generator.rb → install_generator.rb} +18 -9
- data/lib/generators/cucumber/{install/templates → templates}/config/cucumber.yml.erb +0 -0
- data/lib/generators/cucumber/{install/templates → templates}/script/cucumber +1 -0
- data/lib/generators/cucumber/{install/templates → templates}/support/_rails_each_run.rb.erb +0 -0
- data/lib/generators/cucumber/{install/templates → templates}/support/_rails_prefork.rb.erb +0 -0
- data/lib/generators/cucumber/{install/templates → templates}/support/capybara.rb +2 -0
- data/lib/generators/cucumber/{install/templates → templates}/support/edit_warning.txt +0 -0
- data/lib/generators/cucumber/{install/templates → templates}/support/rails.rb.erb +0 -0
- data/lib/generators/cucumber/{install/templates → templates}/support/rails_spork.rb.erb +0 -0
- data/lib/generators/cucumber/{install/templates → templates}/tasks/cucumber.rake.erb +0 -0
- metadata +100 -169
- data/.github/ISSUE_TEMPLATE.md +0 -52
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -42
- data/.gitignore +0 -13
- data/.rspec +0 -1
- data/.rubocop.yml +0 -1
- data/.rubocop_todo.yml +0 -443
- data/.travis.yml +0 -45
- data/Appraisals +0 -32
- data/Gemfile +0 -7
- data/Rakefile +0 -49
- data/bin/install_geckodriver.sh +0 -19
- data/bin/install_webpacker.sh +0 -9
- data/config/.gitignore +0 -1
- data/config/cucumber.yml +0 -17
- data/cucumber-rails.gemspec +0 -44
- data/dev_tasks/cucumber.rake +0 -3
- data/dev_tasks/rspec.rake +0 -3
- data/dev_tasks/yard.rake +0 -35
- data/dev_tasks/yard/default/layout/html/bubble_32x32.png +0 -0
- data/dev_tasks/yard/default/layout/html/footer.erb +0 -5
- data/dev_tasks/yard/default/layout/html/index.erb +0 -1
- data/dev_tasks/yard/default/layout/html/layout.erb +0 -25
- data/dev_tasks/yard/default/layout/html/logo.erb +0 -1
- data/dev_tasks/yard/default/layout/html/setup.rb +0 -4
- data/features/allow_rescue.feature +0 -65
- data/features/annotations.feature +0 -22
- data/features/capybara_javascript_drivers.feature +0 -73
- data/features/choose_javascript_database_strategy.feature +0 -145
- data/features/database_cleaner.feature +0 -44
- data/features/disable_automatic_database_cleaning.feature +0 -55
- data/features/emulate_javascript.feature +0 -94
- data/features/install_cucumber_rails.feature +0 -14
- data/features/no_database.feature +0 -61
- data/features/raising_errors.feature +0 -16
- data/features/rerun_profile.feature +0 -46
- data/features/rest_api.feature +0 -47
- data/features/step_definitions/cucumber_rails_steps.rb +0 -153
- data/features/support/aruba.rb +0 -3
- data/features/support/bundler_pre_support.rb +0 -28
- data/features/support/env.rb +0 -40
- data/features/support/fixtures/bundler-1.0.21.gem +0 -0
- data/features/support/fixtures/bundler-1.1.rc.gem +0 -0
- data/features/support/legacy_web_steps_support.rb +0 -289
- data/gemfiles/rails_4_2.gemfile +0 -10
- data/gemfiles/rails_5_0.gemfile +0 -10
- data/gemfiles/rails_5_1.gemfile +0 -10
- data/gemfiles/rails_5_2.gemfile +0 -10
- data/gemfiles/rails_6_0.gemfile +0 -8
- data/lib/cucumber/rails/action_controller.rb +0 -13
- data/spec/cucumber/rails/database_spec.rb +0 -57
- data/spec/generators/cucumber/install/install_generator_spec.rb +0 -47
- data/spec/spec_helper.rb +0 -14
data/features/rest_api.feature
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
Feature: REST API
|
2
|
-
|
3
|
-
Scenario: Compare JSON
|
4
|
-
Given I have created a new Rails app "rails-app" and installed cucumber-rails
|
5
|
-
And I write to "app/controllers/posts_controller.rb" with:
|
6
|
-
"""
|
7
|
-
class PostsController < ApplicationController
|
8
|
-
def index
|
9
|
-
render json: {'hello' => 'world'}.to_json
|
10
|
-
end
|
11
|
-
end
|
12
|
-
"""
|
13
|
-
And I write to "config/routes.rb" with:
|
14
|
-
"""
|
15
|
-
RailsApp::Application.routes.draw do
|
16
|
-
resources :posts
|
17
|
-
end
|
18
|
-
"""
|
19
|
-
And I write to "features/posts.feature" with:
|
20
|
-
"""
|
21
|
-
Feature: posts
|
22
|
-
Scenario: See them
|
23
|
-
When the client requests GET /posts
|
24
|
-
Then the response should be JSON:
|
25
|
-
\"\"\"
|
26
|
-
{
|
27
|
-
"hello": "world"
|
28
|
-
}
|
29
|
-
\"\"\"
|
30
|
-
"""
|
31
|
-
And I write to "features/step_definitions/rest_steps.rb" with:
|
32
|
-
"""
|
33
|
-
When /^the client requests GET (.*)$/ do |path|
|
34
|
-
get(path)
|
35
|
-
end
|
36
|
-
|
37
|
-
Then /^the response should be JSON:$/ do |json|
|
38
|
-
JSON.parse(last_response.body).should == JSON.parse(json)
|
39
|
-
end
|
40
|
-
"""
|
41
|
-
And I run `bundle exec rake db:migrate`
|
42
|
-
And I run `bundle exec rake cucumber`
|
43
|
-
Then the feature run should pass with:
|
44
|
-
"""
|
45
|
-
1 scenario (1 passed)
|
46
|
-
2 steps (2 passed)
|
47
|
-
"""
|
@@ -1,153 +0,0 @@
|
|
1
|
-
module CucumberRailsHelper
|
2
|
-
def rails_new(options = {})
|
3
|
-
options[:name] ||= 'test_app'
|
4
|
-
command = run "bundle exec rails new #{options[:name]} --skip-bundle --skip-test-unit --skip-spring #{options[:args]}"
|
5
|
-
expect(command).to have_output /README/
|
6
|
-
expect(last_command_started).to be_successfully_executed
|
7
|
-
cd options[:name]
|
8
|
-
delete_environment_variable 'RUBYOPT'
|
9
|
-
delete_environment_variable 'BUNDLE_BIN_PATH'
|
10
|
-
delete_environment_variable 'BUNDLE_GEMFILE'
|
11
|
-
end
|
12
|
-
|
13
|
-
def install_cucumber_rails(*options)
|
14
|
-
if options.include?(:not_in_test_group)
|
15
|
-
gem 'cucumber-rails', path: "#{File.expand_path('.')}"
|
16
|
-
else
|
17
|
-
gem 'cucumber-rails' , group: :test, require: false, path: "#{File.expand_path('.')}"
|
18
|
-
end
|
19
|
-
|
20
|
-
gem 'sqlite3', '~> 1.3.13'
|
21
|
-
if RUBY_VERSION < '2.4.0'
|
22
|
-
gem 'capybara', '< 3.16.0', group: :test
|
23
|
-
else
|
24
|
-
gem 'capybara', group: :test
|
25
|
-
end
|
26
|
-
gem 'selenium-webdriver', '~> 3.11', group: :test
|
27
|
-
|
28
|
-
gem 'rspec-expectations', '~> 3.7', group: :test
|
29
|
-
gem 'database_cleaner', '>= 1.1', group: :test unless options.include?(:no_database_cleaner)
|
30
|
-
gem 'factory_bot', '>= 3.2', group: :test unless options.include?(:no_factory_bot)
|
31
|
-
run_simple 'bundle install'
|
32
|
-
|
33
|
-
if `bundle exec rails -v`.split("\n").last.strip =~ /\ARails 6\./
|
34
|
-
run_simple 'bundle exec rails webpacker:install'
|
35
|
-
end
|
36
|
-
|
37
|
-
run_simple 'bundle exec rails generate cucumber:install'
|
38
|
-
end
|
39
|
-
|
40
|
-
def gem(name, *args)
|
41
|
-
options = args.last.is_a?(Hash) ? args.pop : {}
|
42
|
-
|
43
|
-
parts = ["'#{name}'"]
|
44
|
-
parts << args.map(&:inspect) if args.any?
|
45
|
-
parts << options.inspect[1..-2] if options.any?
|
46
|
-
|
47
|
-
line = "gem #{parts.join(', ')}\n"
|
48
|
-
|
49
|
-
gem_regexp = /gem ["']#{name}["'].*$/
|
50
|
-
gemfile_content = File.read(expand_path('Gemfile'))
|
51
|
-
|
52
|
-
if gemfile_content =~ gem_regexp
|
53
|
-
gemfile_content.gsub!(gem_regexp, line)
|
54
|
-
overwrite_file('Gemfile', gemfile_content)
|
55
|
-
else
|
56
|
-
append_to_file('Gemfile', line)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def prepare_aruba_report
|
61
|
-
if(ENV['ARUBA_REPORT_DIR'])
|
62
|
-
@aruba_report_start = Time.new
|
63
|
-
sleep(1)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def fixture(path)
|
68
|
-
File.expand_path(File.dirname(__FILE__) + "./../support/fixtures/#{path}")
|
69
|
-
end
|
70
|
-
end
|
71
|
-
World(CucumberRailsHelper)
|
72
|
-
|
73
|
-
Given /^I have created a new Rails app and installed cucumber\-rails, accidentally outside of the test group in my Gemfile$/ do
|
74
|
-
rails_new
|
75
|
-
install_cucumber_rails :not_in_test_group
|
76
|
-
create_web_steps
|
77
|
-
prepare_aruba_report
|
78
|
-
end
|
79
|
-
|
80
|
-
Given /^I have created a new Rails app "([^"]*)" and installed cucumber\-rails$/ do |app_name|
|
81
|
-
rails_new name: app_name
|
82
|
-
install_cucumber_rails
|
83
|
-
create_web_steps
|
84
|
-
prepare_aruba_report
|
85
|
-
end
|
86
|
-
|
87
|
-
Given /^I have created a new Rails app and installed cucumber\-rails$/ do
|
88
|
-
rails_new
|
89
|
-
install_cucumber_rails
|
90
|
-
create_web_steps
|
91
|
-
prepare_aruba_report
|
92
|
-
end
|
93
|
-
|
94
|
-
Given /^I have created a new Rails app with no database and installed cucumber-rails$/ do
|
95
|
-
rails_new args: '--skip-active-record'
|
96
|
-
install_cucumber_rails :no_database_cleaner, :no_factory_bot
|
97
|
-
overwrite_file('features/support/env.rb', "require 'cucumber/rails'\n")
|
98
|
-
create_web_steps
|
99
|
-
end
|
100
|
-
|
101
|
-
Given /^I have created a new Rails app "(.*?)" with no database and installed cucumber\-rails$/ do |app_name|
|
102
|
-
rails_new name: app_name, args: '--skip-active-record'
|
103
|
-
install_cucumber_rails :no_database_cleaner, :no_factory_bot
|
104
|
-
overwrite_file('features/support/env.rb', "require 'cucumber/rails'\n")
|
105
|
-
create_web_steps
|
106
|
-
end
|
107
|
-
|
108
|
-
Given /^I have a "([^"]*)" ActiveRecord model object$/ do |name|
|
109
|
-
run_simple("bundle exec rails g model #{name}")
|
110
|
-
run_simple('bundle exec rake db:migrate RAILS_ENV=test')
|
111
|
-
end
|
112
|
-
|
113
|
-
Given /^I force selenium to run Firefox in headless mode$/ do
|
114
|
-
selenium_config = %{
|
115
|
-
Capybara.register_driver :selenium do |app|
|
116
|
-
http_client = Selenium::WebDriver::Remote::Http::Default.new
|
117
|
-
http_client.read_timeout = 180
|
118
|
-
|
119
|
-
browser_options = ::Selenium::WebDriver::Firefox::Options.new()
|
120
|
-
browser_options.args << '--headless'
|
121
|
-
Capybara::Selenium::Driver.new(app, browser: :firefox, options: browser_options, http_client: http_client)
|
122
|
-
end
|
123
|
-
|
124
|
-
Capybara.server = :webrick
|
125
|
-
}
|
126
|
-
|
127
|
-
step 'I append to "features/support/env.rb" with:', selenium_config
|
128
|
-
end
|
129
|
-
|
130
|
-
When /^I run the cukes$/ do
|
131
|
-
run_simple('bundle exec cucumber')
|
132
|
-
end
|
133
|
-
|
134
|
-
# Copied from Aruba
|
135
|
-
Then /^the feature run should pass with:$/ do |string|
|
136
|
-
step 'the output should not contain " failed)"'
|
137
|
-
step 'the output should not contain " undefined)"'
|
138
|
-
step 'the exit status should be 0'
|
139
|
-
step 'the output should contain:', string
|
140
|
-
end
|
141
|
-
|
142
|
-
Given("I remove the {string} gem from the Gemfile") do |gem_name|
|
143
|
-
content = File.open(expand_path('Gemfile'), 'r').readlines
|
144
|
-
new_content = []
|
145
|
-
|
146
|
-
content.each do |line|
|
147
|
-
next if line =~ /gem ["|']#{gem_name}["|'].*/
|
148
|
-
|
149
|
-
new_content << line
|
150
|
-
end
|
151
|
-
|
152
|
-
overwrite_file('Gemfile', new_content.join("\r\n"))
|
153
|
-
end
|
data/features/support/aruba.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
module BundlerPreHelper
|
2
|
-
def bundler
|
3
|
-
fixture 'bundler-1.0.21.gem'
|
4
|
-
end
|
5
|
-
|
6
|
-
def bundler_pre
|
7
|
-
fixture 'bundler-1.1.rc.gem'
|
8
|
-
end
|
9
|
-
|
10
|
-
def gem_install(path)
|
11
|
-
run_simple("gem install #{path} --no-ri --no-rdoc")
|
12
|
-
end
|
13
|
-
|
14
|
-
def gem_uninstall(path)
|
15
|
-
run_simple("gem uninstall #{path}")
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
Before('@bundler-pre') do
|
20
|
-
extend(BundlerPreHelper)
|
21
|
-
gem_uninstall bundler
|
22
|
-
gem_install bundler_pre
|
23
|
-
end
|
24
|
-
|
25
|
-
After('@bundler-pre') do
|
26
|
-
gem_uninstall bundler_pre
|
27
|
-
gem_install bundler
|
28
|
-
end
|
data/features/support/env.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__) + '/../../lib')
|
2
|
-
require 'rubygems'
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'rspec/expectations'
|
5
|
-
require 'aruba/cucumber'
|
6
|
-
|
7
|
-
if(ENV['ARUBA_REPORT_DIR'])
|
8
|
-
# Override reporting behaviour so we don't document all files, only the ones
|
9
|
-
# that have been created after @aruba_report_start (a Time object). This is
|
10
|
-
# given a value after the Rails app is generated (see cucumber_rails_steps.rb)
|
11
|
-
module Aruba
|
12
|
-
module Reporting
|
13
|
-
def children(dir)
|
14
|
-
children = Dir["#{dir}/*"].sort
|
15
|
-
|
16
|
-
# include
|
17
|
-
children = children.select do |child|
|
18
|
-
File.directory?(child) ||
|
19
|
-
(@aruba_report_start && File.stat(child).mtime > @aruba_report_start)
|
20
|
-
end
|
21
|
-
|
22
|
-
# exclude
|
23
|
-
children = children.reject do |child|
|
24
|
-
child =~ /Gemfile/ ||
|
25
|
-
child =~ /\.log$/
|
26
|
-
end
|
27
|
-
|
28
|
-
children
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
After do |scenario|
|
35
|
-
if scenario.failed?
|
36
|
-
puts last_command_stopped.stdout
|
37
|
-
puts last_command_stopped.stderr
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
Binary file
|
Binary file
|
@@ -1,289 +0,0 @@
|
|
1
|
-
module WebSteps
|
2
|
-
def create_web_steps
|
3
|
-
write_file('features/step_definitions/web_steps.rb', <<-EOF)
|
4
|
-
# web_steps.rb used to be in Cucumber-Rails, but was removed in 1.1.0. We're still using them in the tests because
|
5
|
-
# the tests were written while we still thought web_steps.rb was a good idea. We don't think so anymore:
|
6
|
-
#
|
7
|
-
# http://groups.google.com/group/cukes/browse_thread/thread/26f80b93c94f2952
|
8
|
-
# https://github.com/cucumber/cucumber-rails/issues/174
|
9
|
-
# http://benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories.html
|
10
|
-
# http://dannorth.net/2011/01/31/whose-domain-is-it-anyway/
|
11
|
-
# http://elabs.se/blog/15-you-re-cuking-it-wrong
|
12
|
-
#
|
13
|
-
# I'm sure someone will find this and paste it into their own projects. Go ahead. It's a bad idea.
|
14
|
-
# You have been warned.
|
15
|
-
#
|
16
|
-
# Aslak
|
17
|
-
|
18
|
-
require 'uri'
|
19
|
-
require 'cgi'
|
20
|
-
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
|
21
|
-
|
22
|
-
module WithinHelpers
|
23
|
-
def with_scope(locator)
|
24
|
-
locator ? within(*selector_for(locator)) { yield } : yield
|
25
|
-
end
|
26
|
-
end
|
27
|
-
World(WithinHelpers)
|
28
|
-
|
29
|
-
# Single-line step scoper
|
30
|
-
When /^(.*) within (.*[^:])$/ do |step, parent|
|
31
|
-
with_scope(parent) { When step }
|
32
|
-
end
|
33
|
-
|
34
|
-
# Multi-line step scoper
|
35
|
-
When /^(.*) within (.*[^:]):$/ do |step, parent, table_or_string|
|
36
|
-
with_scope(parent) { When "\#{step}:", table_or_string }
|
37
|
-
end
|
38
|
-
|
39
|
-
Given /^(?:|I )am on (.+)$/ do |page_name|
|
40
|
-
visit path_to(page_name)
|
41
|
-
end
|
42
|
-
|
43
|
-
When /^(?:|I )go to (.+)$/ do |page_name|
|
44
|
-
visit path_to(page_name)
|
45
|
-
end
|
46
|
-
|
47
|
-
When /^(?:|I )press "([^"]*)"$/ do |button|
|
48
|
-
click_button(button)
|
49
|
-
end
|
50
|
-
|
51
|
-
When /^(?:|I )follow "([^"]*)"$/ do |link|
|
52
|
-
click_link(link)
|
53
|
-
end
|
54
|
-
|
55
|
-
When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
|
56
|
-
fill_in(field, with: value)
|
57
|
-
end
|
58
|
-
|
59
|
-
When /^(?:|I )fill in "([^"]*)" for "([^"]*)"$/ do |value, field|
|
60
|
-
fill_in(field, with: value)
|
61
|
-
end
|
62
|
-
|
63
|
-
# Use this to fill in an entire form with data from a table. Example:
|
64
|
-
#
|
65
|
-
# When I fill in the following:
|
66
|
-
# | Account Number | 5002 |
|
67
|
-
# | Expiry date | 2009-11-01 |
|
68
|
-
# | Note | Nice guy |
|
69
|
-
# | Wants Email? | |
|
70
|
-
#
|
71
|
-
# TODO: Add support for checkbox, select or option
|
72
|
-
# based on naming conventions.
|
73
|
-
#
|
74
|
-
When /^(?:|I )fill in the following:$/ do |fields|
|
75
|
-
fields.rows_hash.each do |name, value|
|
76
|
-
When %{I fill in "\#{name}" with "\#{value}"}
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
|
81
|
-
select(value, from: field)
|
82
|
-
end
|
83
|
-
|
84
|
-
When /^(?:|I )check "([^"]*)"$/ do |field|
|
85
|
-
check(field)
|
86
|
-
end
|
87
|
-
|
88
|
-
When /^(?:|I )uncheck "([^"]*)"$/ do |field|
|
89
|
-
uncheck(field)
|
90
|
-
end
|
91
|
-
|
92
|
-
When /^(?:|I )choose "([^"]*)"$/ do |field|
|
93
|
-
choose(field)
|
94
|
-
end
|
95
|
-
|
96
|
-
When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
|
97
|
-
attach_file(field, File.expand_path(path))
|
98
|
-
end
|
99
|
-
|
100
|
-
Then /^(?:|I )should see "([^"]*)"$/ do |text|
|
101
|
-
if page.respond_to? :should
|
102
|
-
page.should have_content(text)
|
103
|
-
else
|
104
|
-
assert page.has_content?(text)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
Then /^(?:|I )should see \\/([^\\/]*)\\/$/ do |regexp|
|
109
|
-
regexp = Regexp.new(regexp)
|
110
|
-
|
111
|
-
if page.respond_to? :should
|
112
|
-
page.should have_xpath('//*', text: regexp)
|
113
|
-
else
|
114
|
-
assert page.has_xpath?('//*', text: regexp)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
Then /^(?:|I )should not see "([^"]*)"$/ do |text|
|
119
|
-
if page.respond_to? :should
|
120
|
-
page.should have_no_content(text)
|
121
|
-
else
|
122
|
-
assert page.has_no_content?(text)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
Then /^(?:|I )should not see \\/([^\\/]*)\\/$/ do |regexp|
|
127
|
-
regexp = Regexp.new(regexp)
|
128
|
-
|
129
|
-
if page.respond_to? :should
|
130
|
-
page.should have_no_xpath('//*', text: regexp)
|
131
|
-
else
|
132
|
-
assert page.has_no_xpath?('//*', text: regexp)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
|
137
|
-
with_scope(parent) do
|
138
|
-
field = find_field(field)
|
139
|
-
field_value = (field.tag_name == 'textarea') ? field.text : field.value
|
140
|
-
if field_value.respond_to? :should
|
141
|
-
field_value.should =~ /\#{value}/
|
142
|
-
else
|
143
|
-
assert_match(/\#{value}/, field_value)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
|
149
|
-
with_scope(parent) do
|
150
|
-
field = find_field(field)
|
151
|
-
field_value = (field.tag_name == 'textarea') ? field.text : field.value
|
152
|
-
if field_value.respond_to? :should_not
|
153
|
-
field_value.should_not =~ /\#{value}/
|
154
|
-
else
|
155
|
-
assert_no_match(/\#{value}/, field_value)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
Then /^the "([^"]*)" field should have the error "([^"]*)"$/ do |field, error_message|
|
161
|
-
element = find_field(field)
|
162
|
-
classes = element.find(:xpath, '..')[:class].split(' ')
|
163
|
-
|
164
|
-
form_for_input = element.find(:xpath, 'ancestor::form[1]')
|
165
|
-
using_formtastic = form_for_input[:class].include?('formtastic')
|
166
|
-
error_class = using_formtastic ? 'error' : 'field_with_errors'
|
167
|
-
|
168
|
-
if classes.respond_to? :should
|
169
|
-
classes.should include(error_class)
|
170
|
-
else
|
171
|
-
assert classes.include?(error_class)
|
172
|
-
end
|
173
|
-
|
174
|
-
if page.respond_to?(:should)
|
175
|
-
if using_formtastic
|
176
|
-
error_paragraph = element.find(:xpath, '../*[@class="inline-errors"][1]')
|
177
|
-
error_paragraph.should have_content(error_message)
|
178
|
-
else
|
179
|
-
page.should have_content("\#{field.titlecase} \#{error_message}")
|
180
|
-
end
|
181
|
-
else
|
182
|
-
if using_formtastic
|
183
|
-
error_paragraph = element.find(:xpath, '../*[@class="inline-errors"][1]')
|
184
|
-
assert error_paragraph.has_content?(error_message)
|
185
|
-
else
|
186
|
-
assert page.has_content?("\#{field.titlecase} \#{error_message}")
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
Then /^the "([^"]*)" field should have no error$/ do |field|
|
192
|
-
element = find_field(field)
|
193
|
-
classes = element.find(:xpath, '..')[:class].split(' ')
|
194
|
-
if classes.respond_to? :should
|
195
|
-
classes.should_not include('field_with_errors')
|
196
|
-
classes.should_not include('error')
|
197
|
-
else
|
198
|
-
assert !classes.include?('field_with_errors')
|
199
|
-
assert !classes.include?('error')
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
|
204
|
-
with_scope(parent) do
|
205
|
-
field_checked = find_field(label)['checked']
|
206
|
-
if field_checked.respond_to? :should
|
207
|
-
field_checked.should be_true
|
208
|
-
else
|
209
|
-
assert field_checked
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
|
215
|
-
with_scope(parent) do
|
216
|
-
field_checked = find_field(label)['checked']
|
217
|
-
if field_checked.respond_to? :should
|
218
|
-
field_checked.should be_false
|
219
|
-
else
|
220
|
-
assert !field_checked
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
Then /^(?:|I )should be on (.+)$/ do |page_name|
|
226
|
-
current_path = URI.parse(current_url).path
|
227
|
-
if current_path.respond_to? :should
|
228
|
-
current_path.should == path_to(page_name)
|
229
|
-
else
|
230
|
-
assert_equal path_to(page_name), current_path
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
|
235
|
-
query = URI.parse(current_url).query
|
236
|
-
actual_params = query ? CGI.parse(query) : {}
|
237
|
-
expected_params = {}
|
238
|
-
expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
|
239
|
-
|
240
|
-
if actual_params.respond_to? :should
|
241
|
-
actual_params.should == expected_params
|
242
|
-
else
|
243
|
-
assert_equal expected_params, actual_params
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
Then /^show me the page$/ do
|
248
|
-
save_and_open_page
|
249
|
-
end
|
250
|
-
EOF
|
251
|
-
|
252
|
-
write_file('features/support/paths.rb', <<-EOF)
|
253
|
-
module NavigationHelpers
|
254
|
-
# Maps a name to a path. Used by the
|
255
|
-
#
|
256
|
-
# When /^I go to (.+)$/ do |page_name|
|
257
|
-
#
|
258
|
-
# step definition in web_steps.rb
|
259
|
-
#
|
260
|
-
def path_to(page_name)
|
261
|
-
case page_name
|
262
|
-
|
263
|
-
when /^the home\s?page$/
|
264
|
-
'/'
|
265
|
-
|
266
|
-
# Add more mappings here.
|
267
|
-
# Here is an example that pulls values out of the Regexp:
|
268
|
-
#
|
269
|
-
# when /^(.*)'s profile page$/i
|
270
|
-
# user_profile_path(User.find_by_login($1))
|
271
|
-
|
272
|
-
else
|
273
|
-
begin
|
274
|
-
page_name =~ /^the (.*) page$/
|
275
|
-
path_components = $1.split(/\s+/)
|
276
|
-
self.send(path_components.push('path').join('_').to_sym)
|
277
|
-
rescue NoMethodError, ArgumentError
|
278
|
-
raise "Can't find mapping from \"\#{page_name}\" to a path.\\n" +
|
279
|
-
"Now, go and add a mapping in \#{__FILE__}"
|
280
|
-
end
|
281
|
-
end
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
World(NavigationHelpers)
|
286
|
-
EOF
|
287
|
-
end
|
288
|
-
end
|
289
|
-
World(WebSteps)
|