cucumber-rails 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/.gitignore +3 -2
  2. data/HACKING.rdoc +34 -0
  3. data/History.txt +29 -0
  4. data/README.rdoc +48 -22
  5. data/Rakefile +6 -1
  6. data/VERSION +1 -1
  7. data/config/.gitignore +1 -0
  8. data/cucumber-rails.gemspec +49 -25
  9. data/dev_tasks/cucumber.rake +5 -0
  10. data/{tasks → dev_tasks}/rspec.rake +0 -0
  11. data/features/rails2.feature +56 -0
  12. data/features/rails3.feature +52 -0
  13. data/features/step_definitions/cucumber_rails_steps.rb +7 -0
  14. data/features/support/env.rb +4 -0
  15. data/features/support/matchers/files.rb +17 -0
  16. data/generators/cucumber/cucumber_generator.rb +27 -134
  17. data/generators/cucumber/templates/step_definitions/web_steps_ja.rb.erb +136 -0
  18. data/generators/feature/feature_generator.rb +30 -24
  19. data/lib/cucumber/rails/capybara_javascript_emulation.rb +25 -14
  20. data/lib/cucumber/rails/rspec.rb +20 -7
  21. data/lib/cucumber/rails/world.rb +5 -1
  22. data/lib/cucumber/web/tableish.rb +67 -65
  23. data/lib/generators/cucumber/feature/USAGE +16 -0
  24. data/lib/generators/cucumber/feature/feature_base.rb +29 -0
  25. data/lib/generators/cucumber/feature/feature_generator.rb +37 -0
  26. data/lib/generators/cucumber/feature/named_arg.rb +17 -0
  27. data/lib/generators/cucumber/skeleton/USAGE +21 -0
  28. data/lib/generators/cucumber/skeleton/skeleton_base.rb +202 -0
  29. data/lib/generators/cucumber/skeleton/skeleton_generator.rb +64 -0
  30. data/rvm.yml +22 -0
  31. data/spec/cucumber/web/tableish_spec.rb +2 -0
  32. data/spec/generators/cucumber/skeleton/skeleton_base_spec.rb +84 -0
  33. data/spec/spec.opts +2 -0
  34. data/{generators/feature/templates → templates/feature}/feature.erb +18 -12
  35. data/{generators/feature/templates → templates/feature}/steps.erb +0 -0
  36. data/{generators/cucumber/templates → templates/skeleton}/config/cucumber.yml.erb +0 -0
  37. data/{generators/cucumber/templates → templates/skeleton}/environments/cucumber.rb.erb +2 -2
  38. data/{generators/cucumber/templates → templates/skeleton}/script/cucumber +0 -0
  39. data/{generators/cucumber/templates → templates/skeleton}/step_definitions/capybara_steps.rb.erb +18 -8
  40. data/{generators/cucumber/templates → templates/skeleton}/step_definitions/web_steps_cs.rb.erb +0 -0
  41. data/templates/skeleton/step_definitions/web_steps_da.rb.erb +114 -0
  42. data/{generators/cucumber/templates → templates/skeleton}/step_definitions/web_steps_de.rb.erb +0 -0
  43. data/{generators/cucumber/templates → templates/skeleton}/step_definitions/web_steps_es.rb.erb +0 -0
  44. data/{generators/cucumber/templates → templates/skeleton}/step_definitions/web_steps_no.rb.erb +0 -0
  45. data/{generators/cucumber/templates → templates/skeleton}/step_definitions/web_steps_pt-BR.rb.erb +0 -0
  46. data/{generators/cucumber/templates → templates/skeleton}/step_definitions/webrat_steps.rb.erb +13 -3
  47. data/{generators/cucumber/templates → templates/skeleton}/support/_rails_each_run.rb +7 -2
  48. data/{generators/cucumber/templates → templates/skeleton}/support/_rails_prefork.rb.erb +1 -1
  49. data/{generators/cucumber/templates → templates/skeleton}/support/capybara.rb +0 -0
  50. data/{generators/cucumber/templates → templates/skeleton}/support/edit_warning.txt +0 -0
  51. data/{generators/cucumber/templates → templates/skeleton}/support/paths.rb +0 -0
  52. data/{generators/cucumber/templates → templates/skeleton}/support/rails.rb.erb +0 -0
  53. data/{generators/cucumber/templates → templates/skeleton}/support/rails_spork.rb.erb +0 -0
  54. data/{generators/cucumber/templates → templates/skeleton}/support/webrat.rb +0 -0
  55. data/{generators/cucumber/templates → templates/skeleton}/tasks/cucumber.rake.erb +1 -1
  56. metadata +77 -31
@@ -0,0 +1,64 @@
1
+ require File.join(File.dirname(__FILE__), 'skeleton_base')
2
+
3
+ module Cucumber
4
+ class SkeletonGenerator < Rails::Generators::Base
5
+
6
+ include Cucumber::Generators::SkeletonBase
7
+
8
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
9
+
10
+ argument :language, :type => :string, :banner => "LANG", :optional => true
11
+
12
+ class_option :webrat, :type => :boolean, :desc => "Use Webrat"
13
+ class_option :capybara, :type => :boolean, :desc => "Use Capybara"
14
+ class_option :rspec, :type => :boolean, :desc => "Use RSpec"
15
+ class_option :testunit, :type => :boolean, :desc => "Use Test::Unit"
16
+ class_option :spork, :type => :boolean, :desc => "Use Spork"
17
+ class_option :skip_database, :type => :boolean, :desc => "Skip modification of database.yml", :aliases => '-D', :default => false
18
+
19
+ attr_reader :framework, :driver
20
+
21
+ def configure_defaults
22
+ @language ||= 'en'
23
+ @framework = framework_from_options || detect_current_framework || detect_default_framework
24
+ @driver = driver_from_options || detect_current_driver || detect_default_driver
25
+ end
26
+
27
+ def generate
28
+ check_upgrade_limitations
29
+ create_templates
30
+ create_scripts
31
+ create_step_definitions
32
+ create_feature_support
33
+ create_tasks
34
+ create_database unless options[:skip_database]
35
+ end
36
+
37
+ def self.gem_root
38
+ File.expand_path("../../../../../", __FILE__)
39
+ end
40
+
41
+ def self.source_root
42
+ File.join(gem_root, 'templates/skeleton')
43
+ end
44
+
45
+ def cucumber_rails_env
46
+ 'test'
47
+ end
48
+
49
+ private
50
+
51
+ def framework_from_options
52
+ return :rspec if options[:rspec]
53
+ return :testunit if options[:testunit]
54
+ return nil
55
+ end
56
+
57
+ def driver_from_options
58
+ return :webrat if options[:webrat]
59
+ return :capybara if options[:capybara]
60
+ return nil
61
+ end
62
+
63
+ end
64
+ end
data/rvm.yml ADDED
@@ -0,0 +1,22 @@
1
+ rubies:
2
+ 1.8.7: ruby-1.8.7-tv1_8_7_174
3
+ # 1.9.1: ruby-1.9.1-p378
4
+ gems:
5
+ - aruba jeweler sqlite3-ruby capybara webrat spork database_cleaner cucumber rspec rspec-rails
6
+ rails_gems:
7
+ 2.3.5:
8
+ - rails -v 2.3.5
9
+ 3.0.0.beta:
10
+ - i18n -v 0.3.0
11
+ - tzinfo -v 0.3.16
12
+ - memcache-client -v 1.7.5
13
+ - rack-mount -v 0.4.0
14
+ - rack-test -v 0.5.0
15
+ - text-format -v 1.0.0
16
+ - erubis -v 2.6.5
17
+ - mail -v 2.1.2
18
+ - thor -v 0.13
19
+ - bundler -v 0.9.7
20
+ - builder -v 2.1.2
21
+ - rails --pre
22
+
@@ -1,3 +1,5 @@
1
+ # -*- encoding: utf-8 -*-
2
+
1
3
  require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
4
 
3
5
  def World(*a); end
@@ -0,0 +1,84 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper")
2
+
3
+ # TODO using this seam as an interim way to get the file to load
4
+ module Config
5
+ CONFIG = {
6
+ 'bindir' => 'foo',
7
+ 'ruby_install_name' => 'bar'
8
+ }
9
+ end
10
+ require 'generators/cucumber/skeleton/skeleton_base'
11
+
12
+ module Cucumber
13
+ module Generators
14
+ describe SkeletonBase do
15
+ def instance_of_class_including(mixin)
16
+ Class.new do
17
+ include mixin
18
+ end.new
19
+ end
20
+
21
+ before(:each) do
22
+ Kernel.stub(:require => nil)
23
+
24
+ @generator = instance_of_class_including(Cucumber::Generators::SkeletonBase)
25
+ end
26
+
27
+ # This is a private method, but there was a bug in it where it
28
+ # defaulted to :testunit (the framework) when called to identify
29
+ # the driver
30
+ describe "#first_loadable" do
31
+ it "detects loadable libraries" do
32
+ Gem.should_receive(:available?).with('capybara').and_return(true)
33
+ @generator.send(:first_loadable, [['capybara', :capybara], ['webrat', :webrat ]]).should == :capybara
34
+ end
35
+
36
+ it "tries the given libraries in order" do
37
+ Gem.stub(:available?).with('capybara').and_return(false)
38
+ Gem.should_receive(:available?).with('webrat').and_return(true)
39
+ @generator.send(:first_loadable, [['capybara', :capybara], ['webrat', :webrat ]]).should == :webrat
40
+ end
41
+
42
+ it "returns nil if no libraries are available" do
43
+ Gem.stub(:available? => false)
44
+ @generator.send(:first_loadable, [['capybara', :capybara], ['webrat', :webrat ]]).should be_nil
45
+ end
46
+ end
47
+
48
+ # This is a private method, but there may have been a bug in it where
49
+ # it defaulted to :testunit (the framework) when called to identify
50
+ # the driver
51
+ describe "#detect_in_env" do
52
+ describe "when env.rb doesn't exist" do
53
+ it "returns nil" do
54
+ File.should_receive(:file?).with("features/support/env.rb").and_return(false)
55
+ @generator.send(:detect_in_env, [['capybara', :capybara], ['webrat', :webrat]]).should be_nil
56
+ end
57
+ end
58
+
59
+ describe "when env.rb exists" do
60
+ before(:each) do
61
+ File.stub(:file => true)
62
+ end
63
+
64
+ it "detects loadable libraries, choosing the first in the argument list" do
65
+ IO.should_receive(:read).with("features/support/env.rb").and_return("blah webrat capybara blah")
66
+ @generator.send(:detect_in_env, [['capybara', :capybara], ['webrat', :webrat]]).should == :capybara
67
+ end
68
+
69
+ it "tries the given libraries in order" do
70
+ IO.should_receive(:read).with("features/support/env.rb").and_return("blah webrat blah")
71
+ @generator.send(:detect_in_env, [['capybara', :capybara], ['webrat', :webrat]]).should == :webrat
72
+ end
73
+
74
+ it "returns nil if no libraries are available" do
75
+ IO.should_receive(:read).with("features/support/env.rb").and_return("blah blah")
76
+ @generator.send(:detect_in_env, [['capybara', :capybara], ['webrat', :webrat]]).should be_nil
77
+ end
78
+ end
79
+
80
+ end
81
+
82
+ end
83
+ end
84
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --format progress
2
+ --colour
@@ -27,23 +27,29 @@ Feature: Manage <%= plural_name %>
27
27
  #
28
28
  # Capybara must use Culerity or Selenium2 (webdriver) when pages rely on
29
29
  # Javascript events. Only Culerity supports confirmation dialogs.
30
- #
31
- # cucumber-rails will turn off transactions for scenarios tagged with
32
- # @selenium, @culerity, @javascript or @no-txn and clean the database with
33
- # DatabaseCleaner after the scenario has finished. This is to prevent data
34
- # from leaking into the next scenario.
35
30
  #
36
- # Culerity has some performance overhead, and there are two alternatives to using
37
- # Culerity:
31
+ # Since Culerity and Selenium2 has some overhead, Cucumber-Rails will detect
32
+ # the presence of Javascript behind Delete links and issue a DELETE request
33
+ # instead of a GET request.
38
34
  #
39
- # a) You can remove the @culerity tag and run everything in-process, but then you
40
- # also have to modify your views to use <button> instead: http://github.com/jnicklas/capybara/issues#issue/12
35
+ # You can turn off this emulation by tagging your scenario with @selenium,
36
+ # @culerity, @celerity or @javascript. (See the Capybara documentation for
37
+ # details about those tags). If any of these tags are present, Cucumber-Rails
38
+ # will also turn off transactions and clean the database with DatabaseCleaner
39
+ # after the scenario has finished. This is to prevent data from leaking into
40
+ # the next scenario.
41
41
  #
42
- # b) Replace the @culerity tag with @emulate_rails_javascript. This will detect
43
- # the onclick javascript and emulate its behaviour without a real Javascript
42
+ # Another way to avoid Cucumber-Rails'' javascript emulation without using any
43
+ # of the tags above is to modify your views to use <button> instead. You can
44
+ # see how in http://github.com/jnicklas/capybara/issues#issue/12
45
+ #
46
+ # TODO: Verify with Rob what this means: The rack driver will detect the
47
+ # onclick javascript and emulate its behaviour without a real Javascript
44
48
  # interpreter.
45
49
  #
46
- @culerity
50
+ <% if options[:capybara] -%>
51
+ @<%= options[:capybara] %>
52
+ <% end -%>
47
53
  <% end -%>
48
54
  Scenario: Delete <%= singular_name %>
49
55
  Given the following <%= plural_name %>:
@@ -22,11 +22,11 @@ config.action_controller.allow_forgery_protection = false
22
22
  config.action_mailer.delivery_method = :test
23
23
 
24
24
  config.gem 'cucumber-rails', :lib => false, :version => '>=<%= version %>' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber-rails'))
25
- config.gem 'database_cleaner', :lib => false, :version => '>=0.4.3' unless File.directory?(File.join(Rails.root, 'vendor/plugins/database_cleaner'))
25
+ config.gem 'database_cleaner', :lib => false, :version => '>=0.5.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/database_cleaner'))
26
26
  <% if driver == :capybara -%>
27
27
  config.gem 'capybara', :lib => false, :version => '>=0.3.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/capybara'))
28
28
  <% else -%>
29
- config.gem 'webrat', :lib => false, :version => '>=0.6.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat'))
29
+ config.gem 'webrat', :lib => false, :version => '>=0.7.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat'))
30
30
  <% end -%>
31
31
  <% if framework == :rspec -%>
32
32
  config.gem 'rspec', :lib => false, :version => '>=1.3.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec'))
@@ -126,9 +126,9 @@ Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^\"]*)")?$/ do |regexp, s
126
126
  regexp = Regexp.new(regexp)
127
127
  with_scope(selector) do
128
128
  if defined?(Spec::Rails::Matchers)
129
- page.shoul have_not_xpath('//*', :text => regexp)
129
+ page.should have_no_xpath('//*', :text => regexp)
130
130
  else
131
- assert page.has_not_xpath?('//*', :text => regexp)
131
+ assert page.has_no_xpath?('//*', :text => regexp)
132
132
  end
133
133
  end
134
134
  end
@@ -158,7 +158,7 @@ Then /^the "([^\"]*)" checkbox(?: within "([^\"]*)")? should be checked$/ do |la
158
158
  if defined?(Spec::Rails::Matchers)
159
159
  find_field(label)['checked'].should == 'checked'
160
160
  else
161
- assert field_labeled(label)['checked'] == 'checked'
161
+ assert_equal 'checked', field_labeled(label)['checked']
162
162
  end
163
163
  end
164
164
  end
@@ -168,17 +168,27 @@ Then /^the "([^\"]*)" checkbox(?: within "([^\"]*)")? should not be checked$/ do
168
168
  if defined?(Spec::Rails::Matchers)
169
169
  find_field(label)['checked'].should_not == 'checked'
170
170
  else
171
- assert field_labeled(label)['checked'] != 'checked'
171
+ assert_not_equal 'checked', field_labeled(label)['checked']
172
172
  end
173
173
  end
174
174
  end
175
-
175
+
176
176
  Then /^(?:|I )should be on (.+)$/ do |page_name|
177
- current_path = URI.parse(current_url).select(:path, :query).compact.join('?')
178
177
  if defined?(Spec::Rails::Matchers)
179
- current_path.should == path_to(page_name)
178
+ URI.parse(current_url).path.should == path_to(page_name)
179
+ else
180
+ assert_equal path_to(page_name), URI.parse(current_url).path
181
+ end
182
+ end
183
+
184
+ Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
185
+ actual_params = CGI.parse(URI.parse(current_url).query)
186
+ expected_params = Hash[expected_pairs.rows_hash.map{|k,v| [k,[v]]}]
187
+
188
+ if defined?(Spec::Rails::Matchers)
189
+ actual_params.should == expected_params
180
190
  else
181
- assert_equal path_to(page_name), current_path
191
+ assert_equal expected_params, actual_params
182
192
  end
183
193
  end
184
194
 
@@ -0,0 +1,114 @@
1
+ # encoding: utf-8
2
+ <%= embed_file('support/edit_warning.txt') %>
3
+
4
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
5
+
6
+ Givet /^(?:at )jeg står på (.*)$/ do |page_name|
7
+ Given %{I am on #{page_name}}
8
+ end
9
+
10
+ Når /^jeg går til (.*)$/ do |page_name|
11
+ When %{I go to #{page_name}}
12
+ end
13
+
14
+ Når /^jeg trykker "([^\"]*)"$/ do |button|
15
+ When %{I press "#{button}"}
16
+ end
17
+
18
+ Når /^jeg klikker "([^\"]*)"$/ do |link|
19
+ When %{I follow "#{link}"}
20
+ end
21
+
22
+ Når /^jeg klikker "([^\"]*)" under "([^\"]*)"$/ do |link, parent|
23
+ When %{I follow "#{link}" within "#{parent}"}
24
+ end
25
+
26
+ Når /^jeg fylder ud "([^\"]*)" med "([^\"]*)"$/ do |field, value|
27
+ When %{I fill in "#{field}" with "#{value}"}
28
+ end
29
+
30
+ Når /^jeg fylder ud "([^\"]*)" for "([^\"]*)"$/ do |value, field|
31
+ When %{I fill in "#{value}" for "#{field}"}
32
+ end
33
+
34
+ Når /^jeg fylder følgende ud:$/ do |fields|
35
+ When %{I fill in the following:}, fields
36
+ end
37
+
38
+ Når /^jeg vælger "([^\"]*)" fra "([^\"]*)"$/ do |value, field|
39
+ When %{I select "#{value}" from "#{field}"}
40
+ end
41
+
42
+ # Missing: date stuff
43
+
44
+ Når /^jeg afkrydser "([^\"]*)"$/ do |field|
45
+ When %{I check "#{field}"}
46
+ end
47
+
48
+ Når /^jeg fjerner afkrydsning for "([^\"]*)"$/ do |field|
49
+ When %{I uncheck "#{field}"}
50
+ end
51
+
52
+ Når /^jeg vælger "([^\"]*)"$/ do |field|
53
+ When %{I choose "#{field}"}
54
+ end
55
+
56
+ Når /^jeg tilsætter filen "([^\"]*)" til "([^\"]*)"$/ do |path, field|
57
+ When %{I attach the file "#{path}" to "#{field}"}
58
+ end
59
+
60
+ Så /^(?:skal jeg|jeg skal) se "([^\"]*)"$/ do |text|
61
+ Then %{I should see "#{text}"}
62
+ end
63
+
64
+ Så /^(?:skal jeg|jeg skal) se "([^\"]*)" under "([^\"]*)"$/ do |text, selector|
65
+ Then %{I should see "#{text}" within "#{selector}"}
66
+ end
67
+
68
+ Så /^(?:skal jeg|jeg skal) se \/([^\/]*)\/$/ do |regexp|
69
+ Then %{I should see /#{regexp}/}
70
+ end
71
+
72
+ Så /^(?:skal jeg|jeg skal) se \/([^\/]*)\/ under "([^\"]*)"$/ do |regexp, selector|
73
+ Then %{I should see /#{regexp}/ within "#{selector}"}
74
+ end
75
+
76
+ Så /^(?:skal jeg|jeg skal) ikke se "([^\"]*)"$/ do |text|
77
+ Then %{I should not see "#{text}"}
78
+ end
79
+
80
+ Så /^(?:skal jeg|jeg skal) ikke se "([^\"]*)" under "([^\"]*)"$/ do |text, selector|
81
+ Then %{I should not see "#{text}" within "#{selector}"}
82
+ end
83
+
84
+ Så /^(?:skal jeg|jeg skal) ikke se \/([^\/]*)\/$/ do |regexp|
85
+ Then %{I should not see /#{regexp}/}
86
+ end
87
+
88
+ Så /^(?:skal jeg|jeg skal) ikke se \/([^\/]*)\/ under "([^\"]*)"$/ do |regexp, selector|
89
+ Then %{I should not see /#{regexp}/ within "#{selector}"}
90
+ end
91
+
92
+ Så /^(?:skal )"([^\"]*)" feltet (?:skal )indeholde "([^\"]*)"$/ do |field, value|
93
+ Then %{the "#{field}" field should contain "#{value}"}
94
+ end
95
+
96
+ Så /^(?:skal ) "([^\"]*)" feltet (?:skal )ikke indeholde "([^\"]*)"$/ do |field, value|
97
+ Then %{the "#{field}" field should not contain "#{value}"}
98
+ end
99
+
100
+ Så /^(?:skal ) "([^\"]*)" afkrydsningsboksen (?:skal )være krydset af$/ do |label|
101
+ Then %{the "#{label}" checkbox should be checked}
102
+ end
103
+
104
+ Så /^(?:skal ) "([^\"]*)" afkrydsningsboksen (?:skal )ikke være krydset af$/ do |label|
105
+ Then %{the "#{label}" checkbox should not be checked}
106
+ end
107
+
108
+ Så /^(?:skal jeg|jeg skal) komme til (.+)$/ do |page_name|
109
+ Then %{I should be on #{page_name}}
110
+ end
111
+
112
+ Så /^vil jeg se siden$/ do |page_name|
113
+ Then %{show me the page}
114
+ end
@@ -245,11 +245,21 @@ Then /^the "([^\"]*)" checkbox should not be checked$/ do |label|
245
245
  end
246
246
 
247
247
  Then /^(?:|I )should be on (.+)$/ do |page_name|
248
- current_path = URI.parse(current_url).select(:path, :query).compact.join('?')
249
248
  if defined?(Spec::Rails::Matchers)
250
- current_path.should == path_to(page_name)
249
+ URI.parse(current_url).path.should == path_to(page_name)
251
250
  else
252
- assert_equal path_to(page_name), current_path
251
+ assert_equal path_to(page_name), URI.parse(current_url).path
252
+ end
253
+ end
254
+
255
+ Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
256
+ actual_params = CGI.parse(URI.parse(current_url).query)
257
+ expected_params = Hash[expected_pairs.rows_hash.map{|k,v| [k,[v]]}]
258
+
259
+ if defined?(Spec::Rails::Matchers)
260
+ actual_params.should == expected_params
261
+ else
262
+ assert_equal expected_params, actual_params
253
263
  end
254
264
  end
255
265