cucumber-rails 1.1.1 → 1.2.0

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.
Files changed (42) hide show
  1. data/.gitignore +1 -0
  2. data/History.md +8 -1
  3. data/Rakefile +4 -2
  4. data/cucumber-rails.gemspec +17 -17
  5. data/features/allow_rescue.feature +1 -1
  6. data/features/capybara_javascript_drivers.feature +1 -1
  7. data/features/choose_javascript_database_strategy.feature +63 -0
  8. data/features/database_cleaner.feature +1 -1
  9. data/features/emulate_javascript.feature +2 -2
  10. data/features/field_with_errors.feature +2 -2
  11. data/features/fixing_bundler_pre.feature +1 -1
  12. data/features/inspect_query_string.feature +1 -1
  13. data/features/install_cucumber_rails.feature +1 -1
  14. data/features/multiple_databases.feature +1 -1
  15. data/features/no_database.feature +1 -1
  16. data/features/rerun_profile.feature +1 -1
  17. data/features/rest_api.feature +1 -1
  18. data/features/routing.feature +1 -1
  19. data/features/step_definitions/cucumber_rails_steps.rb +52 -398
  20. data/features/support/bundler_pre_support.rb +28 -0
  21. data/features/support/env.rb +1 -4
  22. data/features/support/fixtures/bundler-1.0.21.gem +0 -0
  23. data/features/support/fixtures/bundler-1.1.rc.gem +0 -0
  24. data/{lib/generators/cucumber/install/templates/step_definitions/web_steps.rb.erb → features/support/legacy_web_steps_support.rb} +69 -14
  25. data/lib/cucumber/rails.rb +1 -1
  26. data/lib/cucumber/rails/database.rb +67 -0
  27. data/lib/cucumber/rails/hooks/active_record.rb +2 -12
  28. data/lib/generators/cucumber/install/USAGE +0 -3
  29. data/lib/generators/cucumber/install/templates/support/_rails_each_run.rb.erb +6 -1
  30. metadata +79 -88
  31. data/Gemfile.lock +0 -202
  32. data/features/test_unit.feature +0 -45
  33. data/lib/cucumber/web/tableish.rb +0 -119
  34. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_cs.rb.erb +0 -127
  35. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_da.rb.erb +0 -105
  36. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_de.rb.erb +0 -127
  37. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_es.rb.erb +0 -127
  38. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_ja.rb.erb +0 -140
  39. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_ko.rb.erb +0 -142
  40. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_no.rb.erb +0 -105
  41. data/lib/generators/cucumber/install/templates/step_definitions/web_steps_pt-BR.rb.erb +0 -132
  42. data/spec/cucumber/web/tableish_spec.rb +0 -239
data/.gitignore CHANGED
@@ -6,3 +6,4 @@ coverage
6
6
  .rvmrc
7
7
  .yardoc/
8
8
  .rvmrc
9
+ Gemfile.lock
data/History.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [v1.2.0](https://github.com/cucumber/cucumber-rails/compare/v1.1.1...v1.2.0)
2
+
3
+ ### Removed features
4
+ * The (deprecated) tableish method has been removed. See https://gist.github.com/1299371 for an alternative. (Aslak Hellesøy)
5
+
6
+ ### Bugfixes
7
+ * Non-threadsafe database connections shared between threads ([#166](https://github.com/cucumber/cucumber-rails/issues/166) Matt Wynne)
8
+
1
9
  ## [v1.1.1](https://github.com/cucumber/cucumber-rails/compare/v1.1.0...v1.1.1)
2
10
 
3
11
  ### Removed features
@@ -26,7 +34,6 @@ with a Step Definition that perhaps looks like this:
26
34
  Given /^I have signed up as "([^"]*)"$/ do |email|
27
35
  visit(signup_path)
28
36
  fill_in('Email', :with => email)
29
- fill_in('Email', :with => email)
30
37
  fill_in('Password', :with => 's3cr3t')
31
38
  fill_in('Password Confirmation', :with => 's3cr3t')
32
39
  click_button('Sign up')
data/Rakefile CHANGED
@@ -1,12 +1,14 @@
1
1
  # encoding: utf-8
2
2
  CUCUMBER_RAILS_VERSION = Gem::Specification.load(File.dirname(__FILE__) + '/cucumber-rails.gemspec').version.version
3
3
  require 'rubygems'
4
- require 'bundler/setup'
4
+ require 'rake/clean'
5
+ require 'bundler'
5
6
  Bundler::GemHelper.install_tasks
6
7
 
7
8
  $:.unshift(File.dirname(__FILE__) + '/lib')
8
9
  Dir["#{File.dirname(__FILE__)}/dev_tasks/*.rake"].sort.each { |ext| load ext }
9
10
 
11
+ CLEAN.include('doc', 'tmp')
10
12
 
11
13
  # Needed for selenium browser
12
14
  # See http://about.travis-ci.org/docs/user/selenium-setup/
@@ -21,5 +23,5 @@ end
21
23
  if ENV['TRAVIS']
22
24
  task :default => :travis
23
25
  else
24
- task :default => :cucumber
26
+ task :default => [:spec, :cucumber]
25
27
  end
@@ -3,38 +3,38 @@ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'cucumber-rails'
6
- s.version = '1.1.1'
6
+ s.version = '1.2.0'
7
7
  s.authors = ["Aslak Hellesøy", "Dennis Blöte", "Rob Holland"]
8
- s.description = "Cucumber Generators and Runtime for Rails"
8
+ s.description = "Cucumber Generator and Runtime for Rails"
9
9
  s.summary = "#{s.name}-#{s.version}"
10
10
  s.email = 'cukes@googlegroups.com'
11
11
  s.homepage = "http://cukes.info"
12
12
 
13
- s.add_runtime_dependency('cucumber', '>= 1.1.0')
13
+ s.add_runtime_dependency('cucumber', '>= 1.1.1')
14
14
  s.add_runtime_dependency('nokogiri', '>= 1.5.0')
15
15
  s.add_runtime_dependency('capybara', '>= 1.1.1')
16
- s.add_development_dependency('rails', '>= 3.1.0')
16
+ s.add_development_dependency('rails', '>= 3.1.1')
17
17
  s.add_development_dependency('rake', '>= 0.9.2')
18
- s.add_development_dependency('bundler', '>= 1.0.18')
18
+ s.add_development_dependency('bundler', '>= 1.0.21')
19
19
  s.add_development_dependency('aruba', '>= 0.4.6')
20
20
  s.add_development_dependency('sqlite3', '>= 1.3.4')
21
- s.add_development_dependency('rspec', '>= 2.6.0')
22
- s.add_development_dependency('rspec-rails', '>= 2.6.1')
23
- s.add_development_dependency('ammeter', '>= 0.1.2')
24
- s.add_development_dependency('factory_girl', '>= 2.1.0')
21
+ s.add_development_dependency('rspec', '>= 2.7.0')
22
+ s.add_development_dependency('rspec-rails', '>= 2.7.0')
23
+ s.add_development_dependency('ammeter', '>= 0.2.1')
24
+ s.add_development_dependency('factory_girl', '>= 2.2.0')
25
25
  s.add_development_dependency('database_cleaner', '>= 0.6.7')
26
- s.add_development_dependency('mongoid', '>= 2.2.2')
27
- s.add_development_dependency('bson_ext', '>= 1.3.1')
26
+ s.add_development_dependency('mongoid', '>= 2.3.3')
27
+ s.add_development_dependency('bson_ext', '>= 1.4.0')
28
28
 
29
29
  # Various Stuff that Rails 3.1 puts inside apps.
30
- s.add_development_dependency('turn', '>= 0.8.2')
31
- s.add_development_dependency('sass', '>= 3.1.7')
32
- s.add_development_dependency('coffee-script', '>= 2.2.0')
33
- s.add_development_dependency('uglifier', '>= 1.0.3')
34
- s.add_development_dependency('jquery-rails', '>= 1.0.14')
30
+ s.add_development_dependency('turn', '>= 0.8.3')
31
+ s.add_development_dependency('sass-rails', '>= 3.1.4')
32
+ s.add_development_dependency('coffee-rails', '>= 3.1.1')
33
+ s.add_development_dependency('uglifier', '>= 1.0.4')
34
+ s.add_development_dependency('jquery-rails', '>= 1.0.16')
35
35
 
36
36
  # For Documentation:
37
- s.add_development_dependency('yard', '~> 0.7.2')
37
+ s.add_development_dependency('yard', '~> 0.7.3')
38
38
  s.add_development_dependency('rdiscount', '~> 1.6.8')
39
39
  s.add_development_dependency('bcat', '~> 0.6.2')
40
40
 
@@ -1,7 +1,7 @@
1
1
  Feature: Allow Cucumber to rescue exceptions
2
2
 
3
3
  Background: A controller that raises an exception
4
- Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
4
+ Given I have created a new Rails 3 app "rails-3-app" and installed cucumber-rails
5
5
  And I write to "app/controllers/posts_controller.rb" with:
6
6
  """
7
7
  class PostsController < ApplicationController
@@ -1,7 +1,7 @@
1
1
  Feature: Capybara Javascript Drivers
2
2
 
3
3
  Background: A simple calendar app
4
- Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
4
+ Given I have created a new Rails 3 app and installed cucumber-rails
5
5
  And I successfully run `bundle exec rails g scaffold appointment name:string when:datetime`
6
6
  And I write to "features/step_definitions/date_time_steps.rb" with:
7
7
  """
@@ -0,0 +1,63 @@
1
+ @announce
2
+ Feature: Choose javascript database strategy
3
+
4
+ When running a scenario with the @javascript tag, Capybara will fire up a web server
5
+ in the same process in a separate thread to your cukes. By default, this means ActiveRecord will give it a
6
+ separate database connection, which in turn means data you put into your database from
7
+ Cucumber step definitions (e.g. using FactoryGirl) won't be visible to the web server
8
+ until the database transaction is committed.
9
+
10
+ So if you use a transaction strategy for cleaning up your database at the end of a scenario,
11
+ it won't work for javascript scenarios by default.
12
+
13
+ There are two ways around this. One is to switch to a truncation strategy for javascript
14
+ scenarios. This is slower, but more reliable.
15
+
16
+ The alternative is to patch ActiveRecord to share a single database connection between
17
+ threads. This means you still get the speed benefits of using a transaction to roll back
18
+ your database, but you run the risk of the two threads stomping on one another as they
19
+ talk to the database.
20
+
21
+ Right now, the default behavior which works for 80% of cucumber-rails users is to use
22
+ the shared connection patch, but you can override this by telling cucumber-rails which
23
+ strategy to use for javascript scenarios.
24
+
25
+ Background:
26
+ Given I have created a new Rails 3 app and installed cucumber-rails
27
+ And I have a "Widget" ActiveRecord model object
28
+ And I append to "features/env.rb" with:
29
+ """
30
+ Cucumber::Rails::Database.javascript_strategy = :truncation
31
+ """
32
+
33
+ Scenario: Set the strategy to truncation and run a javascript scenario.
34
+ Given I write to "features/widgets.feature" with:
35
+ """
36
+ @javascript
37
+ Feature:
38
+ Background:
39
+ Given I have created 2 widgets
40
+
41
+ Scenario:
42
+ When I create 3 widgets
43
+ Then I should have 5 widgets
44
+
45
+ Scenario:
46
+ Then I should have 2 widgets
47
+ """
48
+ And I write to "features/step_definitions/widget_steps.rb" with:
49
+ """
50
+ Given /created? (\d) widgets/ do |num|
51
+ num.to_i.times { Widget.create! }
52
+ end
53
+
54
+ Then /should have (\d) widgets/ do |num|
55
+ Widget.count.should == num.to_i
56
+ end
57
+ """
58
+ When I run the cukes
59
+ Then it should pass with:
60
+ """
61
+ 2 scenarios (2 passed)
62
+ 5 steps (5 passed)
63
+ """
@@ -1,7 +1,7 @@
1
1
  Feature: DatabaseCleaner
2
2
 
3
3
  Scenario: Create records in background
4
- Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
4
+ Given I have created a new Rails 3 app and installed cucumber-rails
5
5
  And I write to "features/widgets.feature" with:
6
6
  """
7
7
  Feature: Create widgets
@@ -1,7 +1,7 @@
1
1
  Feature: Emulate Javascript
2
2
 
3
3
  Scenario: See a widget
4
- Given I have created a new Rails 3 app "widgets" with cucumber-rails support
4
+ Given I have created a new Rails 3 app and installed cucumber-rails
5
5
  And I successfully run `rails generate scaffold widget name:string`
6
6
  And I write to "features/f.feature" with:
7
7
  """
@@ -35,7 +35,7 @@ Feature: Emulate Javascript
35
35
  """
36
36
 
37
37
  Scenario: Pass on the CSRF token
38
- Given I have created a new Rails 3 app "widgets" with cucumber-rails support
38
+ Given I have created a new Rails 3 app and installed cucumber-rails
39
39
  And I successfully run `rails generate scaffold widget name:string`
40
40
  And I successfully run `sed -i -e 's/forgery_protection *= false/forgery_protection = true/' config/environments/test.rb`
41
41
  And I successfully run `rails generate controller session establish`
@@ -1,7 +1,7 @@
1
1
  Feature: Detecting a field has errors on it
2
2
 
3
3
  Scenario: A form with some fields with errors
4
- Given I have created a new Rails 3 app "enemies" with cucumber-rails support
4
+ Given I have created a new Rails 3 app and installed cucumber-rails
5
5
  And I successfully run `rails generate scaffold enemy name:string nickname:string`
6
6
  And I write to "app/models/enemy.rb" with:
7
7
  """
@@ -27,7 +27,7 @@ Feature: Detecting a field has errors on it
27
27
  """
28
28
 
29
29
  Scenario: A formtastic form with some fields with errors
30
- Given I have created a new Rails 3 app "enemies" with cucumber-rails support
30
+ Given I have created a new Rails 3 app and installed cucumber-rails
31
31
  And I append to "Gemfile" with:
32
32
  """
33
33
  gem "formtastic"
@@ -5,7 +5,7 @@ Feature: Fixing Bundler Pre
5
5
 
6
6
  @bundler-pre
7
7
  Scenario: Install Cucumber-Rails with bundler prerelease
8
- Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support and cucumber-rails is outside of test group
8
+ Given I have created a new Rails 3 app and installed cucumber-rails, accidentally outside of the test group in my Gemfile
9
9
  And I successfully run `rake db:migrate`
10
10
  And I write to "features/tests.feature" with:
11
11
  """
@@ -1,7 +1,7 @@
1
1
  Feature: Inspect query string
2
2
 
3
3
  Scenario: Inspect query string
4
- Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
4
+ Given I have created a new Rails 3 app and installed cucumber-rails
5
5
  And I successfully run `rails generate scaffold cuke name:string`
6
6
  And I overwrite "app/controllers/cukes_controller.rb" with:
7
7
  """
@@ -4,7 +4,7 @@ Feature: Rails 3
4
4
  of Rails 3 and Ruby, with Capybara, Spork and DatabaseCleaner
5
5
 
6
6
  Scenario: Install Cucumber-Rails
7
- Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
7
+ Given I have created a new Rails 3 app and installed cucumber-rails
8
8
  Then the following files should exist:
9
9
  | config/cucumber.yml |
10
10
  | script/cucumber |
@@ -4,7 +4,7 @@ Feature: Multiple Databases
4
4
  I want to specify explicit strategies for each
5
5
 
6
6
  Background: A Rails 3 app utilizing multiple database repositories exists
7
- Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
7
+ Given I have created a new Rails 3 app and installed cucumber-rails
8
8
  And I append to "config/database.yml" with:
9
9
  """
10
10
 
@@ -2,7 +2,7 @@ Feature: No Database
2
2
  Allow Cucumber to work with a Rails app without a database
3
3
 
4
4
  Scenario: No ActiveRecord and DatabaseCleaner
5
- Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
5
+ Given I have created a new Rails 3 app "rails-3-app" and installed cucumber-rails
6
6
  # Turn off ActiveRecord
7
7
  And I write to "config/application.rb" with:
8
8
  """
@@ -4,7 +4,7 @@ Feature: Rerun profile
4
4
  I want to rerun only failing features
5
5
 
6
6
  Scenario: Rerun
7
- Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
7
+ Given I have created a new Rails 3 app and installed cucumber-rails
8
8
  And a file named "rerun.txt" with:
9
9
  """
10
10
  features/rerun_test.feature:2
@@ -1,7 +1,7 @@
1
1
  Feature: REST API
2
2
 
3
3
  Scenario: Compare JSON
4
- Given I have created a new Rails 3 app "rails-3-app" with cucumber-rails support
4
+ Given I have created a new Rails 3 app "rails-3-app" and installed cucumber-rails
5
5
  And I write to "app/controllers/posts_controller.rb" with:
6
6
  """
7
7
  class PostsController < ApplicationController
@@ -1,7 +1,7 @@
1
1
  Feature: Routing
2
2
 
3
3
  Scenario: Visit undefined route
4
- Given a project without ActiveRecord
4
+ Given I have created a new Rails 3 app with no database and installed cucumber-rails
5
5
  And I remove the file "public/index.html"
6
6
  And I write to "features/tests.feature" with:
7
7
  """
@@ -1,421 +1,75 @@
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)
1
+ module CucumberRailsHelper
2
+ def rails_new(options={})
3
+ options[:name] ||= 'test_app'
4
+ run_simple "rails new #{options[:name]} --skip-bundle --skip-test-unit #{options[:args]}"
5
+ assert_passing_with('README')
6
+ cd options[:name]
105
7
  end
106
- end
107
-
108
- Then /^(?:|I )should see \\/([^\\/]*)\\/$/ do |regexp|
109
- regexp = Regexp.new(regexp)
110
8
 
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}/
9
+ def install_cucumber_rails(*options)
10
+ if options.include?(:not_in_test_group)
11
+ gem "cucumber-rails", :path => "#{File.expand_path('.')}"
142
12
  else
143
- assert_match(/\#{value}/, field_value)
13
+ gem "cucumber-rails", :group => :test, :path => "#{File.expand_path('.')}"
144
14
  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)
15
+ gem "capybara", :group => :test
16
+ gem "rspec-rails", :group => :test
17
+ gem "database_cleaner", :group => :test unless options.include?(:no_database_cleaner)
18
+ gem 'factory_girl', :group => :test unless options.include?(:no_factory_girl)
19
+ run_simple 'bundle exec rails generate cucumber:install'
20
+ end
21
+
22
+ def gem(name, options)
23
+ line = %{gem "#{name}", #{options.inspect}\n}
24
+ append_to_file('Gemfile', line)
25
+ end
26
+
27
+ def prepare_aruba_report
28
+ if(ENV['ARUBA_REPORT_DIR'])
29
+ @aruba_report_start = Time.new
30
+ sleep(1)
156
31
  end
157
32
  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
33
+
34
+ def fixture(path)
35
+ File.expand_path(File.dirname(__FILE__) + "./../support/fixtures/#{path}")
211
36
  end
212
37
  end
38
+ World(CucumberRailsHelper)
213
39
 
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)
290
-
291
- Given /^I have created a new Rails 3 app "([^"]*)" with cucumber\-rails support and cucumber-rails is outside of test group$/ do |app_name|
292
- steps %Q{
293
- When I successfully run `rails new #{app_name}`
294
- Then it should pass with:
295
- """
296
- README
297
- """
298
- And I cd to "#{app_name}"
299
- And I append to "Gemfile" with:
300
- """
301
- gem "cucumber-rails", :path => "../../.."
302
- gem "capybara", :group => :test
303
- gem "rspec-rails", :group => :test
304
- gem "database_cleaner", :group => :test
305
- gem 'factory_girl', :group => :test
306
-
307
- """
308
- And I successfully run `bundle exec rails generate cucumber:install`
309
- }
40
+ Given /^I have created a new Rails 3 app and installed cucumber\-rails, accidentally outside of the test group in my Gemfile$/ do
41
+ rails_new
42
+ install_cucumber_rails :not_in_test_group
310
43
  create_web_steps
311
- if(ENV['ARUBA_REPORT_DIR'])
312
- @aruba_report_start = Time.new
313
- sleep(1)
314
- end
44
+ prepare_aruba_report
315
45
  end
316
46
 
317
- Given /^I have created a new Rails 3 app "([^"]*)" with cucumber\-rails support$/ do |app_name|
318
- steps %Q{
319
- When I successfully run `rails new #{app_name}`
320
- Then it should pass with:
321
- """
322
- README
323
- """
324
- And I cd to "#{app_name}"
325
- And I append to "Gemfile" with:
326
- """
327
- gem "cucumber-rails", :group => :test, :path => "../../.."
328
- gem "capybara", :group => :test
329
- gem "rspec-rails", :group => :test
330
- gem "database_cleaner", :group => :test
331
- gem 'factory_girl', :group => :test
332
-
333
- """
334
- And I successfully run `bundle exec rails generate cucumber:install`
335
- }
47
+ Given /^I have created a new Rails 3 app "([^"]*)" and installed cucumber\-rails$/ do |app_name|
48
+ rails_new :name => app_name
49
+ install_cucumber_rails
336
50
  create_web_steps
337
- if(ENV['ARUBA_REPORT_DIR'])
338
- @aruba_report_start = Time.new
339
- sleep(1)
340
- end
51
+ prepare_aruba_report
341
52
  end
342
53
 
343
- Given /^a project without ActiveRecord$/ do
344
- steps %Q{
345
- Given I successfully run `rails new cuke-app`
346
- And I cd to "cuke-app"
347
- And I append to "Gemfile" with:
348
- """
349
- gem "cucumber-rails", :group => :test, :path => "../../.."
350
- gem "capybara", :group => :test
351
- gem "rspec-rails", :group => :test
352
-
353
- """
354
- And I successfully run `bundle exec rails generate cucumber:install`
355
- And I overwrite "features/support/env.rb" with:
356
- """
357
- require 'cucumber/rails'
358
-
359
- """
360
-
361
- And I write to "config/application.rb" with:
362
- """
363
- require File.expand_path('../boot', __FILE__)
364
-
365
- require 'action_controller/railtie'
366
- require 'action_mailer/railtie'
367
- require 'active_resource/railtie'
368
- require 'rails/test_unit/railtie'
369
-
370
- Bundler.require(:default, Rails.env) if defined?(Bundler)
371
-
372
- module CukeApp
373
- class Application < Rails::Application
374
- config.encoding = "utf-8"
375
- config.filter_parameters += [:password]
376
- end
377
- end
378
-
379
- """
380
- And I remove the file "config/database.yml"
381
- }
54
+ Given /^I have created a new Rails 3 app and installed cucumber\-rails$/ do
55
+ rails_new
56
+ install_cucumber_rails
382
57
  create_web_steps
383
- if(ENV['ARUBA_REPORT_DIR'])
384
- @aruba_report_start = Time.new
385
- sleep(1)
386
- end
58
+ prepare_aruba_report
387
59
  end
388
60
 
389
- Given /^a cukes resource$/ do
390
- steps %Q{
391
- Given I write to "config/routes.rb" with:
392
- """
393
- CukeApp::Application.routes.draw do
394
- resources :cukes
395
- end
396
-
397
- """
398
- And I write to "app/controllers/cukes_controller.rb" with:
399
- """
400
- class CukesController < ApplicationController
401
- def index
402
- end
403
- end
404
-
405
- """
406
- }
61
+ Given /^I have created a new Rails 3 app with no database and installed cucumber-rails$/ do
62
+ rails_new :args => '--skip-active-record'
63
+ install_cucumber_rails :no_database_cleaner, :no_factory_girl
64
+ overwrite_file('features/support/env.rb', "require 'cucumber/rails'\n")
65
+ create_web_steps
407
66
  end
408
67
 
409
- Before('@bundler-pre') do
410
- steps %Q{
411
- Given I successfully run `gem uninstall bundler`
412
- And I successfully run `gem install bundler --pre`
413
- }
68
+ Given /^I have a "([^"]*)" ActiveRecord model object$/ do |name|
69
+ run_simple("bundle exec rails g model #{name}")
70
+ run_simple("bundle exec rake db:migrate RAILS_ENV=test")
414
71
  end
415
72
 
416
- After('@bundler-pre') do
417
- steps %Q{
418
- Given I successfully run `gem uninstall bundler`
419
- And I successfully run `gem install bundler`
420
- }
73
+ When /^I run the cukes$/ do
74
+ run_simple('bundle exec cucumber')
421
75
  end