square-cucumber 0.3.12.2 → 0.3.93.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.
Files changed (91) hide show
  1. data/History.txt +117 -4
  2. data/Manifest.txt +11 -0
  3. data/Rakefile +1 -1
  4. data/config/hoe.rb +3 -2
  5. data/cucumber.yml +2 -2
  6. data/examples/i18n/ko/features/addition.feature +5 -5
  7. data/examples/i18n/ko/features/step_definitons/calculator_steps.rb +1 -1
  8. data/examples/i18n/no/features/step_definitons/kalkulator_steps.rb +1 -1
  9. data/examples/i18n/pt/features/adicao.feature +4 -4
  10. data/examples/self_test/features/support/env.rb +2 -1
  11. data/examples/sinatra/features/support/env.rb +7 -1
  12. data/examples/steps_library/features/step_definitions/steps_lib1.rb +8 -0
  13. data/examples/steps_library/features/step_definitions/steps_lib2.rb +8 -0
  14. data/examples/tickets/features/step_definitons/tickets_steps.rb +15 -0
  15. data/examples/tickets/features/table_diffing.feature +13 -0
  16. data/examples/watir/features/step_definitons/search_steps.rb +5 -1
  17. data/features/cucumber_cli_diff_disabled.feature +2 -1
  18. data/features/html_formatter/a.html +5 -7
  19. data/features/junit_formatter.feature +21 -14
  20. data/features/profiles.feature +99 -0
  21. data/features/rake_task.feature +28 -0
  22. data/features/step_definitions/cucumber_steps.rb +28 -15
  23. data/features/steps_formatter.feature +25 -0
  24. data/features/support/env.rb +9 -5
  25. data/features/table_diffing.feature +45 -0
  26. data/features/unicode_table.feature +35 -0
  27. data/features/work_in_progress.feature +1 -0
  28. data/gem_tasks/contributors.rake +4 -0
  29. data/lib/cucumber/ast/background.rb +1 -0
  30. data/lib/cucumber/ast/comment.rb +1 -0
  31. data/lib/cucumber/ast/examples.rb +1 -0
  32. data/lib/cucumber/ast/feature.rb +10 -0
  33. data/lib/cucumber/ast/features.rb +6 -1
  34. data/lib/cucumber/ast/outline_table.rb +4 -1
  35. data/lib/cucumber/ast/py_string.rb +1 -1
  36. data/lib/cucumber/ast/scenario.rb +1 -0
  37. data/lib/cucumber/ast/scenario_outline.rb +2 -0
  38. data/lib/cucumber/ast/step.rb +5 -1
  39. data/lib/cucumber/ast/step_collection.rb +1 -0
  40. data/lib/cucumber/ast/step_invocation.rb +1 -0
  41. data/lib/cucumber/ast/table.rb +306 -52
  42. data/lib/cucumber/ast/tags.rb +1 -0
  43. data/lib/cucumber/ast/visitor.rb +2 -1
  44. data/lib/cucumber/cli/configuration.rb +28 -278
  45. data/lib/cucumber/cli/drb_client.rb +3 -1
  46. data/lib/cucumber/cli/language_help_formatter.rb +9 -7
  47. data/lib/cucumber/cli/main.rb +16 -2
  48. data/lib/cucumber/cli/options.rb +370 -0
  49. data/lib/cucumber/cli/profile_loader.rb +65 -0
  50. data/lib/cucumber/core_ext/instance_exec.rb +8 -5
  51. data/lib/cucumber/feature_file.rb +7 -1
  52. data/lib/cucumber/filter.rb +2 -2
  53. data/lib/cucumber/formatter/ansicolor.rb +42 -9
  54. data/lib/cucumber/formatter/console.rb +1 -1
  55. data/lib/cucumber/formatter/html.rb +12 -10
  56. data/lib/cucumber/formatter/junit.rb +63 -26
  57. data/lib/cucumber/formatter/pretty.rb +20 -5
  58. data/lib/cucumber/formatter/progress.rb +1 -1
  59. data/lib/cucumber/formatter/steps.rb +49 -0
  60. data/lib/cucumber/languages.yml +6 -6
  61. data/lib/cucumber/parser/feature.rb +90 -63
  62. data/lib/cucumber/parser/feature.tt +28 -1
  63. data/lib/cucumber/parser/i18n/language.rb +12 -5
  64. data/lib/cucumber/parser/table.rb +25 -25
  65. data/lib/cucumber/rake/task.rb +9 -3
  66. data/lib/cucumber/step_definition.rb +1 -1
  67. data/lib/cucumber/step_match.rb +1 -1
  68. data/lib/cucumber/step_mother.rb +3 -1
  69. data/lib/cucumber/version.rb +2 -2
  70. data/lib/cucumber/webrat/table_locator.rb +66 -0
  71. data/rails_generators/cucumber/cucumber_generator.rb +5 -1
  72. data/rails_generators/cucumber/templates/cucumber +3 -2
  73. data/rails_generators/cucumber/templates/cucumber.rake +18 -6
  74. data/rails_generators/cucumber/templates/cucumber_environment.rb +7 -4
  75. data/rails_generators/cucumber/templates/env.rb +1 -0
  76. data/rails_generators/cucumber/templates/spork_env.rb +1 -0
  77. data/rails_generators/cucumber/templates/webrat_steps.rb +22 -0
  78. data/rails_generators/feature/templates/feature.erb +1 -1
  79. data/rails_generators/feature/templates/steps.erb +2 -8
  80. data/spec/cucumber/ast/table_spec.rb +169 -0
  81. data/spec/cucumber/cli/configuration_spec.rb +144 -101
  82. data/spec/cucumber/cli/main_spec.rb +14 -5
  83. data/spec/cucumber/cli/options_spec.rb +311 -0
  84. data/spec/cucumber/cli/profile_loader_spec.rb +10 -0
  85. data/spec/cucumber/core_ext/proc_spec.rb +16 -2
  86. data/spec/cucumber/formatter/html_spec.rb +18 -0
  87. data/spec/cucumber/formatter/progress_spec.rb +2 -2
  88. data/spec/cucumber/parser/table_parser_spec.rb +1 -1
  89. data/spec/spec.opts +3 -1
  90. metadata +18 -4
  91. data/lib/cucumber/webrat/mechanize_world.rb +0 -82
@@ -20,7 +20,7 @@ class CucumberGenerator < Rails::Generator::Base
20
20
 
21
21
  m.directory 'features/support'
22
22
 
23
- if options[:spork]
23
+ if spork?
24
24
  m.template 'spork_env.rb', 'features/support/env.rb'
25
25
  else
26
26
  m.template 'env.rb', 'features/support/env.rb'
@@ -40,6 +40,10 @@ class CucumberGenerator < Rails::Generator::Base
40
40
  def framework
41
41
  options[:framework] || :rspec
42
42
  end
43
+
44
+ def spork?
45
+ options[:spork]
46
+ end
43
47
 
44
48
  protected
45
49
 
@@ -3,6 +3,7 @@ begin
3
3
  load File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/cucumber/bin/cucumber")
4
4
  rescue LoadError => e
5
5
  raise unless e.to_s =~ /cucumber/
6
- require "rubygems"
7
- load File.join(Gem.bindir, "cucumber")
6
+ require 'rubygems'
7
+ require 'cucumber'
8
+ load Cucumber::BINARY
8
9
  end
@@ -4,15 +4,27 @@ unless ARGV.any? {|a| a =~ /^gems/}
4
4
 
5
5
  begin
6
6
  require 'cucumber/rake/task'
7
+ namespace :cucumber do
8
+ Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass (no @wip tag)') do |t|
9
+ t.fork = true # You may get faster startup if you set this to false
10
+ t.cucumber_opts = "--tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}<%= spork? ? ' --drb' : '' %>"
11
+ end
7
12
 
8
- Cucumber::Rake::Task.new(:features) do |t|
9
- t.fork = true
10
- t.cucumber_opts = [<%= options[:spork] ? "'--drb', " : "" %>'--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')]
13
+ Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run @wip features (not passing yet)') do |t|
14
+ t.fork = true # You may get faster startup if you set this to false
15
+ t.cucumber_opts = "--tags @wip --wip --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}<%= spork? ? ' --drb' : '' %>"
16
+ end
17
+
18
+ desc 'Run all features'
19
+ task :all => [:ok, :wip]
20
+ end
21
+
22
+ task :features => 'cucumber:ok' do
23
+ STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
11
24
  end
12
- task :features => 'db:test:prepare'
13
25
  rescue LoadError
14
- desc 'Cucumber rake task not available'
15
- task :features do
26
+ desc 'cucumber rake task not available (cucumber not installed)'
27
+ task :cucumber do
16
28
  abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
17
29
  end
18
30
  end
@@ -15,9 +15,12 @@ config.action_controller.allow_forgery_protection = false
15
15
  # ActionMailer::Base.deliveries array.
16
16
  config.action_mailer.delivery_method = :test
17
17
 
18
- config.gem "cucumber", :lib => false, :version => ">=<%= cucumber_version %>" unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber'))
19
- config.gem "webrat", :lib => false, :version => ">=0.4.4" unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat'))
18
+ config.gem 'cucumber', :lib => false, :version => '>=<%= cucumber_version %>' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber'))
19
+ config.gem 'webrat', :lib => false, :version => '>=0.4.4' unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat'))
20
20
  <% if framework == :rspec -%>
21
- config.gem "rspec", :lib => false, :version => ">=1.2.6" unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec'))
22
- config.gem "rspec-rails", :lib => 'spec/rails', :version => ">=1.2.6" unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails'))
21
+ config.gem 'rspec', :lib => false, :version => '>=1.2.6' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec'))
22
+ config.gem 'rspec-rails', :lib => 'spec/rails', :version => '>=1.2.6' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails'))
23
+ <% end %>
24
+ <% if spork? -%>
25
+ config.gem 'spork', :lib => false, :version => '>=0.5.7' unless File.directory?(File.join(Rails.root, 'vendor/plugins/spork'))
23
26
  <% end %>
@@ -15,6 +15,7 @@ Cucumber::Rails.use_transactional_fixtures
15
15
  Cucumber::Rails.bypass_rescue
16
16
 
17
17
  require 'webrat'
18
+ require 'cucumber/webrat/table_locator' # Lets you do table.diff!(table_at('#my_table').to_a)
18
19
 
19
20
  Webrat.configure do |config|
20
21
  config.mode = :rails
@@ -7,6 +7,7 @@ Spork.prefork do
7
7
  require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
8
8
 
9
9
  require 'webrat'
10
+ require 'cucumber/webrat/table_locator' # Lets you do table.diff!(table_at('#my_table').to_a)
10
11
 
11
12
  Webrat.configure do |config|
12
13
  config.mode = :rails
@@ -19,6 +19,10 @@ When /^I follow "([^\"]*)"$/ do |link|
19
19
  click_link(link)
20
20
  end
21
21
 
22
+ When /^I follow "([^\"]*)" within "([^\"]*)"$/ do |link, parent|
23
+ click_link_within(parent, link)
24
+ end
25
+
22
26
  When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
23
27
  fill_in(field, :with => value)
24
28
  end
@@ -98,6 +102,15 @@ Then /^I should see "([^\"]*)"$/ do |text|
98
102
  <% end -%>
99
103
  end
100
104
 
105
+ Then /^I should see \/([^\/]*)\/$/ do |regexp|
106
+ regexp = Regexp.new(regexp)
107
+ <% if framework == :rspec -%>
108
+ response.should contain(regexp)
109
+ <% else -%>
110
+ assert_contain regexp
111
+ <% end -%>
112
+ end
113
+
101
114
  Then /^I should not see "([^\"]*)"$/ do |text|
102
115
  <% if framework == :rspec -%>
103
116
  response.should_not contain(text)
@@ -106,6 +119,15 @@ Then /^I should not see "([^\"]*)"$/ do |text|
106
119
  <% end -%>
107
120
  end
108
121
 
122
+ Then /^I should not see \/([^\/]*)\/$/ do |regexp|
123
+ regexp = Regexp.new(regexp)
124
+ <% if framework == :rspec -%>
125
+ response.should_not contain(regexp)
126
+ <% else -%>
127
+ assert_not_contain regexp
128
+ <% end -%>
129
+ end
130
+
109
131
  Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
110
132
  <% if framework == :rspec -%>
111
133
  field_labeled(field).value.should =~ /#{value}/
@@ -25,7 +25,7 @@ Feature: Manage <%= plural_name %>
25
25
  <% end -%>
26
26
  When I delete the 3rd <%= singular_name %>
27
27
  Then I should see the following <%= plural_name %>:
28
- |<%= named_args.map(&:name).join('|') %>|
28
+ |<%= named_args.map{|arg| arg.name.humanize}.join('|') %>|
29
29
  <% [1,2,4].each do |n| -%>
30
30
  |<%= named_args.map{|arg| arg.value(n)}.join('|') %>|
31
31
  <% end -%>
@@ -9,12 +9,6 @@ When /^I delete the (\d+)(?:st|nd|rd|th) <%= singular_name %>$/ do |pos|
9
9
  end
10
10
  end
11
11
 
12
- Then /^I should see the following <%= plural_name %>:$/ do |<%= plural_name %>|
13
- <%= plural_name %>.rows.each_with_index do |row, i|
14
- row.each_with_index do |cell, j|
15
- response.should have_selector("table > tr:nth-child(#{i+2}) > td:nth-child(#{j+1})") { |td|
16
- td.inner_text.should == cell
17
- }
18
- end
19
- end
12
+ Then /^I should see the following <%= plural_name %>:$/ do |expected_<%= plural_name %>_table|
13
+ expected_<%= plural_name %>_table.diff!(table_at('table').to_a)
20
14
  end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require File.dirname(__FILE__) + '/../../spec_helper'
2
3
  require 'cucumber/ast/table'
3
4
 
@@ -100,6 +101,11 @@ module Cucumber
100
101
  table2.hashes.first[:three].should == '4444'
101
102
  end
102
103
 
104
+ it "should allow renaming columns using regexp" do
105
+ table2 = @table.map_headers(/one|uno/ => :three)
106
+ table2.hashes.first[:three].should == '4444'
107
+ end
108
+
103
109
  it "should copy column mappings when mapping headers" do
104
110
  @table.map_column!('one') { |v| v.to_i }
105
111
  table2 = @table.map_headers('one' => 'three')
@@ -168,6 +174,169 @@ module Cucumber
168
174
 
169
175
  end
170
176
 
177
+ describe "diff!" do
178
+ it "should detect a complex diff" do
179
+ t1 = table(%{
180
+ | 1 | 22 | 333 | 4444 |
181
+ | 55555 | 666666 | 7777777 | 88888888 |
182
+ | 999999999 | 0000000000 | 01010101010 | 121212121212 |
183
+ | 4000 | ABC | DEF | 50000 |
184
+ })
185
+
186
+ t2 = table(%{
187
+ | a | 4444 | 1 |
188
+ | bb | 88888888 | 55555 |
189
+ | ccc | xxxxxxxx | 999999999 |
190
+ | dddd | 4000 | 300 |
191
+ | e | 50000 | 4000 |
192
+ })
193
+ lambda{t1.diff!(t2)}.should raise_error
194
+ t1.to_s(:indent => 12, :color => false).should == %{
195
+ | 1 | (-) 22 | (-) 333 | 4444 | (+) a |
196
+ | 55555 | (-) 666666 | (-) 7777777 | 88888888 | (+) bb |
197
+ | (-) 999999999 | (-) 0000000000 | (-) 01010101010 | (-) 121212121212 | (+) |
198
+ | (+) 999999999 | (+) | (+) | (+) xxxxxxxx | (+) ccc |
199
+ | (+) 300 | (+) | (+) | (+) 4000 | (+) dddd |
200
+ | 4000 | (-) ABC | (-) DEF | 50000 | (+) e |
201
+ }
202
+ end
203
+
204
+ it "should not change table when diffed with identical" do
205
+ t = table(%{
206
+ |a|b|c|
207
+ |d|e|f|
208
+ |g|h|i|
209
+ })
210
+ t.diff!(t.dup)
211
+ t.to_s(:indent => 12, :color => false).should == %{
212
+ | a | b | c |
213
+ | d | e | f |
214
+ | g | h | i |
215
+ }
216
+ end
217
+
218
+ it "should inspect missing and surplus cells" do
219
+ t1 = Table.new([
220
+ ['name', 'male', 'lastname', 'swedish'],
221
+ ['aslak', 'true', 'hellesøy', 'false']
222
+ ])
223
+ t2 = Table.new([
224
+ ['name', 'male', 'lastname', 'swedish'],
225
+ ['aslak', true, 'hellesøy', false]
226
+ ])
227
+ lambda{t1.diff!(t2)}.should raise_error
228
+ t1.to_s(:indent => 12, :color => false).should == %{
229
+ | name | male | lastname | swedish |
230
+ | (-) aslak | (-) (i) "true" | (-) hellesøy | (-) (i) "false" |
231
+ | (+) aslak | (+) (i) true | (+) hellesøy | (+) (i) false |
232
+ }
233
+ end
234
+
235
+ it "should allow column mapping of target before diffing" do
236
+ t1 = Table.new([
237
+ ['name', 'male'],
238
+ ['aslak', 'true']
239
+ ])
240
+ t1.map_column!('male') { |m| m == 'true' }
241
+ t2 = Table.new([
242
+ ['name', 'male'],
243
+ ['aslak', true]
244
+ ])
245
+ t1.diff!(t2)
246
+ t1.to_s(:indent => 12, :color => false).should == %{
247
+ | name | male |
248
+ | aslak | true |
249
+ }
250
+ end
251
+
252
+ it "should allow column mapping of argument before diffing" do
253
+ t1 = Table.new([
254
+ ['name', 'male'],
255
+ ['aslak', true]
256
+ ])
257
+ t1.map_column!('male') {
258
+ 'true'
259
+ }
260
+ t2 = Table.new([
261
+ ['name', 'male'],
262
+ ['aslak', 'true']
263
+ ])
264
+ t2.diff!(t1)
265
+ t1.to_s(:indent => 12, :color => false).should == %{
266
+ | name | male |
267
+ | aslak | true |
268
+ }
269
+ end
270
+
271
+ it "should allow header mapping before diffing" do
272
+ t1 = Table.new([
273
+ ['Name', 'Male'],
274
+ ['aslak', 'true']
275
+ ])
276
+ t1.map_headers!('Name' => 'name', 'Male' => 'male')
277
+ t1.map_column!('male') { |m| m == 'true' }
278
+ t2 = Table.new([
279
+ ['name', 'male'],
280
+ ['aslak', true]
281
+ ])
282
+ t1.diff!(t2)
283
+ t1.to_s(:indent => 12, :color => false).should == %{
284
+ | name | male |
285
+ | aslak | true |
286
+ }
287
+ end
288
+
289
+ describe "raising" do
290
+ before do
291
+ @t = table(%{
292
+ | a | b |
293
+ | c | d |
294
+ })
295
+ end
296
+
297
+ it "should raise on missing rows" do
298
+ t = table(%{
299
+ | a | b |
300
+ })
301
+ lambda { @t.dup.diff!(t) }.should raise_error
302
+ lambda { @t.dup.diff!(t, :missing_row => false) }.should_not raise_error
303
+ end
304
+
305
+ it "should raise on surplus rows" do
306
+ t = table(%{
307
+ | a | b |
308
+ | c | d |
309
+ | e | f |
310
+ })
311
+ lambda { @t.dup.diff!(t) }.should raise_error
312
+ lambda { @t.dup.diff!(t, :surplus_row => false) }.should_not raise_error
313
+ end
314
+
315
+ it "should raise on missing columns" do
316
+ t = table(%{
317
+ | a |
318
+ | c |
319
+ })
320
+ lambda { @t.dup.diff!(t) }.should raise_error
321
+ lambda { @t.dup.diff!(t, :missing_col => false) }.should_not raise_error
322
+ end
323
+
324
+ it "should not raise on surplus columns" do
325
+ t = table(%{
326
+ | a | b | x |
327
+ | c | d | y |
328
+ })
329
+ lambda { @t.dup.diff!(t) }.should_not raise_error
330
+ lambda { @t.dup.diff!(t, :surplus_col => true) }.should raise_error
331
+ end
332
+ end
333
+
334
+ def table(text, file=nil, line_offset=0)
335
+ @table_parser ||= Parser::TableParser.new
336
+ @table_parser.parse_or_fail(text.strip, file, line_offset)
337
+ end
338
+ end
339
+
171
340
  it "should convert to sexp" do
172
341
  @table.to_sexp.should ==
173
342
  [:table,
@@ -17,13 +17,25 @@ module Cli
17
17
  end
18
18
 
19
19
  before(:each) do
20
+ #given_cucumber_yml_defined_as({'default' => '-q'})
21
+ File.stub!(:exist?).and_return(false) # Meaning, no cucumber.yml exists
20
22
  Kernel.stub!(:exit).and_return(nil)
21
23
  end
22
24
 
25
+ def config
26
+ @config ||= Configuration.new(@out = StringIO.new, @error = StringIO.new)
27
+ end
28
+
29
+ def reset_config
30
+ @config = nil
31
+ end
32
+
33
+ attr_reader :out, :error
34
+
35
+
23
36
  it "should require files in support paths first" do
24
37
  given_the_following_files("/features/step_definitions/foo.rb","/features/support/bar.rb")
25
38
 
26
- config = Configuration.new(StringIO.new)
27
39
  config.parse!(%w{--require /features})
28
40
 
29
41
  config.files_to_require.should == [
@@ -35,7 +47,6 @@ module Cli
35
47
  it "should require env.rb files first" do
36
48
  given_the_following_files("/features/support/a_file.rb","/features/support/env.rb")
37
49
 
38
- config = Configuration.new(StringIO.new)
39
50
  config.parse!(%w{--require /features})
40
51
 
41
52
  config.files_to_require.should == [
@@ -47,7 +58,6 @@ module Cli
47
58
  it "should not require env.rb files when --dry-run" do
48
59
  given_the_following_files("/features/support/a_file.rb","/features/support/env.rb")
49
60
 
50
- config = Configuration.new(StringIO.new)
51
61
  config.parse!(%w{--require /features --dry-run})
52
62
 
53
63
  config.files_to_require.should == [
@@ -55,12 +65,23 @@ module Cli
55
65
  ]
56
66
  end
57
67
 
68
+ it "should require files in vendor/{plugins,gems}/*/cucumber/*.rb" do
69
+ given_the_following_files("/vendor/plugins/plugin_a/cucumber/foo.rb",
70
+ "/vendor/gems/gem_a/cucumber/bar.rb")
71
+
72
+ config.parse!(%w{--require /features})
73
+
74
+ config.files_to_require.should == [
75
+ "/vendor/plugins/plugin_a/cucumber/foo.rb",
76
+ "/vendor/gems/gem_a/cucumber/bar.rb"
77
+ ]
78
+ end
79
+
58
80
  describe "--exclude" do
59
81
 
60
82
  it "excludes a ruby file from requiring when the name matches exactly" do
61
83
  given_the_following_files("/features/support/a_file.rb","/features/support/env.rb")
62
84
 
63
- config = Configuration.new(StringIO.new)
64
85
  config.parse!(%w{--require /features --exclude a_file.rb})
65
86
 
66
87
  config.files_to_require.should == [
@@ -73,7 +94,6 @@ module Cli
73
94
  "/features/support/food.rb","/features/blah.rb",
74
95
  "/features/support/fooz.rb")
75
96
 
76
- config = Configuration.new(StringIO.new)
77
97
  config.parse!(%w{--require /features --exclude foo[df] --exclude blah})
78
98
 
79
99
  config.files_to_require.should == [
@@ -85,29 +105,23 @@ module Cli
85
105
 
86
106
  describe '#drb?' do
87
107
  it "indicates whether the --drb flag was passed in or not" do
88
- config = Configuration.new(StringIO.new)
89
-
90
108
  config.parse!(%w{features})
91
- config.drb?.should == false
109
+ config.should_not be_drb
92
110
 
93
111
 
94
112
  config.parse!(%w{features --drb})
95
- config.drb?.should == true
113
+ config.should be_drb
96
114
  end
97
115
  end
98
116
 
99
117
  context '--drb' do
100
118
  it "removes the --drb flag from the args" do
101
- config = Configuration.new(StringIO.new)
102
-
103
119
  args = %w{features --drb}
104
120
  config.parse!(args)
105
121
  args.should == %w{features}
106
122
  end
107
123
 
108
124
  it "keeps all other flags intact" do
109
- config = Configuration.new(StringIO.new)
110
-
111
125
  args = %w{features --drb --format profile}
112
126
  config.parse!(args)
113
127
  args.should == %w{features --format profile}
@@ -118,7 +132,6 @@ module Cli
118
132
  context '--drb in a profile' do
119
133
  it "removes the --drb flag from the args" do
120
134
  given_cucumber_yml_defined_as({'server' => '--drb features'})
121
- config = Configuration.new(StringIO.new)
122
135
 
123
136
  args = %w{--profile server}
124
137
  config.parse!(args)
@@ -129,11 +142,9 @@ module Cli
129
142
  given_cucumber_yml_defined_as({'server' => '--drb features --profile nested',
130
143
  'nested' => '--verbose'})
131
144
 
132
- config = Configuration.new(StringIO.new)
133
-
134
145
  args = %w{--profile server --format profile}
135
146
  config.parse!(args)
136
- args.should == %w{features --verbose --format profile}
147
+ args.should == %w{--format profile features --verbose}
137
148
  end
138
149
 
139
150
  end
@@ -141,35 +152,40 @@ module Cli
141
152
  context '--drb in the default profile and no arguments specified' do
142
153
  it "expands the profile's arguments into the args excpet for --drb" do
143
154
  given_cucumber_yml_defined_as({'default' => '--drb features --format pretty'})
144
- config = Configuration.new(StringIO.new)
145
155
  args = []
146
156
  config.parse!(args)
147
157
  args.should == %w{features --format pretty}
148
158
  end
149
159
  end
150
160
 
151
- it "should expand args from YAML file" do
152
- given_cucumber_yml_defined_as({'bongo' => '--require from/yml'})
161
+ it "uses the default profile when no profile is defined" do
162
+ given_cucumber_yml_defined_as({'default' => '--require some_file'})
153
163
 
154
- config = Configuration.new
155
- config.parse!(%w{--format progress --profile bongo})
156
- config.options[:formats].should == [['progress', STDOUT]]
157
- config.options[:require].should == ['from/yml']
164
+ config.parse!(%w{--format progress})
165
+ config.options[:require].should include('some_file')
158
166
  end
159
167
 
160
- it "should expand args from YAML file's default if there are no args" do
161
- given_cucumber_yml_defined_as({'default' => '--require from/yml'})
168
+ context '--profile' do
162
169
 
163
- config = Configuration.new
164
- config.parse!([])
165
- config.options[:require].should == ['from/yml']
166
- end
170
+ it "expands args from profiles in the cucumber.yml file" do
171
+ given_cucumber_yml_defined_as({'bongo' => '--require from/yml'})
172
+
173
+ config.parse!(%w{--format progress --profile bongo})
174
+ config.options[:formats].should == [['progress', out]]
175
+ config.options[:require].should == ['from/yml']
176
+ end
167
177
 
168
- it "should provide a helpful error message when a specified profile does not exists in YAML file" do
169
- given_cucumber_yml_defined_as({'default' => '--require from/yml', 'html_report' => '--format html'})
178
+ it "expands args from the default profile when no flags are provided" do
179
+ given_cucumber_yml_defined_as({'default' => '--require from/yml'})
180
+
181
+ config.parse!([])
182
+ config.options[:require].should == ['from/yml']
183
+ end
170
184
 
171
- config = Configuration.new(StringIO.new, error = StringIO.new)
172
- expected_message = <<-END_OF_MESSAGE
185
+ it "provides a helpful error message when a specified profile does not exists in cucumber.yml" do
186
+ given_cucumber_yml_defined_as({'default' => '--require from/yml', 'html_report' => '--format html'})
187
+
188
+ expected_message = <<-END_OF_MESSAGE
173
189
  Could not find profile: 'i_do_not_exist'
174
190
 
175
191
  Defined profiles in cucumber.yml:
@@ -177,141 +193,175 @@ Defined profiles in cucumber.yml:
177
193
  * html_report
178
194
  END_OF_MESSAGE
179
195
 
180
- lambda{config.parse!(%w{--profile i_do_not_exist})}.should raise_error(expected_message)
181
- end
196
+ lambda{config.parse!(%w{--profile i_do_not_exist})}.should raise_error(ProfileNotFound, expected_message)
197
+ end
182
198
 
183
- it "should allow array as profile" do
184
- given_cucumber_yml_defined_as({'foo' => [1,2,3]})
199
+ it "allows profiles to be defined in arrays" do
200
+ given_cucumber_yml_defined_as({'foo' => [1,2,3]})
185
201
 
186
- config = Configuration.new(StringIO.new, error = StringIO.new)
187
- config.parse!(%w{--profile foo})
188
- config.paths.should == [1,2,3]
189
- end
202
+ config.parse!(%w{--profile foo})
203
+ config.paths.should == [1,2,3]
204
+ end
190
205
 
191
- it "should provide a helpful error message when a specified profile exists but is nil or blank" do
192
- [nil, ' '].each do |bad_input|
193
- given_cucumber_yml_defined_as({'foo' => bad_input})
206
+ it "notifies the user that an individual profile is being used" do
207
+ given_cucumber_yml_defined_as({'foo' => [1,2,3]})
194
208
 
195
- config = Configuration.new(StringIO.new, error = StringIO.new)
196
- expected_error = /The 'foo' profile in cucumber.yml was blank. Please define the command line arguments for the 'foo' profile in cucumber.yml./
197
- lambda{config.parse!(%w{--profile foo})}.should raise_error(expected_error)
209
+ config.parse!(%w{--profile foo})
210
+ out.string.should =~ /Using the foo profile...\n/
198
211
  end
199
- end
200
212
 
201
- it "should provide a helpful error message when no YAML file exists and a profile is specified" do
202
- File.should_receive(:exist?).with('cucumber.yml').and_return(false)
213
+ it "notifies the user when multiple profiles are being used" do
214
+ given_cucumber_yml_defined_as({'foo' => [1,2,3], 'bar' => ['v'], 'dog' => ['v']})
203
215
 
204
- config = Configuration.new(StringIO.new, error = StringIO.new)
205
- expected_error = /cucumber.yml was not found. Please refer to cucumber's documentation on defining profiles in cucumber.yml./
206
- lambda{config.parse!(%w{--profile i_do_not_exist})}.should raise_error(expected_error)
207
- end
216
+ config.parse!(%w{--profile foo --profile bar})
217
+ out.string.should =~ /Using the foo and bar profiles...\n/
218
+
219
+ reset_config
208
220
 
209
- it "should provide a helpful error message when cucumber.yml is blank or malformed" do
210
- expected_error_message = /cucumber.yml was found, but was blank or malformed. Please refer to cucumber's documentation on correct profile usage./
221
+ config.parse!(%w{--profile foo --profile bar --profile dog})
222
+ out.string.should =~ /Using the foo, bar and dog profiles...\n/
223
+ end
211
224
 
212
- ['', 'sfsadfs', "--- \n- an\n- array\n", "---dddfd"].each do |bad_input|
213
- given_cucumber_yml_defined_as(bad_input)
225
+ it "disregards paths in profiles when other paths are passed in (via cmd line)" do
226
+ given_cucumber_yml_defined_as({'foo' => %w[-v features]})
214
227
 
215
- config = Configuration.new(StringIO.new, error = StringIO.new)
216
- lambda{config.parse!([])}.should raise_error(expected_error_message)
228
+ config.parse!(%w{--profile foo features/specific.feature --format pretty})
229
+ config.paths.should == ['features/specific.feature']
230
+ end
231
+
232
+ it "disregards default STDOUT formatter defined in profile when another is passed in (via cmd line)" do
233
+ given_cucumber_yml_defined_as({'foo' => %w[--format pretty]})
234
+ config.parse!(%w{--format progress --profile foo})
235
+ config.options[:formats].should == [['progress', out]]#, ['pretty', 'pretty.txt']]
236
+ end
237
+
238
+
239
+
240
+ ["--no-profile", "-P"].each do |flag|
241
+
242
+ context 'when none is specified with #{flag}' do
243
+
244
+ it "disables profiles" do
245
+ given_cucumber_yml_defined_as({'default' => '-v --require file_specified_in_default_profile.rb'})
246
+
247
+ config.parse!("#{flag} --require some_file.rb".split(" "))
248
+ config.options[:require].should == ['some_file.rb']
249
+ end
250
+
251
+ it "notifies the user that the profiles are being disabled" do
252
+ given_cucumber_yml_defined_as({'default' => '-v'})
253
+
254
+ config.parse!("#{flag} --require some_file.rb".split(" "))
255
+ out.string.should =~ /Disabling profiles.../
256
+ end
257
+
258
+ end
259
+
260
+ end
261
+
262
+
263
+
264
+ it "issues a helpful error message when a specified profile exists but is nil or blank" do
265
+ [nil, ' '].each do |bad_input|
266
+ given_cucumber_yml_defined_as({'foo' => bad_input})
267
+
268
+ expected_error = /The 'foo' profile in cucumber.yml was blank. Please define the command line arguments for the 'foo' profile in cucumber.yml./
269
+ lambda{config.parse!(%w{--profile foo})}.should raise_error(expected_error)
270
+ end
271
+ end
272
+
273
+ it "issues a helpful error message when no YAML file exists and a profile is specified" do
274
+ File.should_receive(:exist?).with('cucumber.yml').and_return(false)
275
+
276
+ expected_error = /cucumber.yml was not found. Please refer to cucumber's documentation on defining profiles in cucumber.yml./
277
+ lambda{config.parse!(%w{--profile i_do_not_exist})}.should raise_error(expected_error)
278
+ end
279
+
280
+ it "issues a helpful error message when cucumber.yml is blank or malformed" do
281
+ expected_error_message = /cucumber.yml was found, but was blank or malformed. Please refer to cucumber's documentation on correct profile usage./
282
+
283
+ ['', 'sfsadfs', "--- \n- an\n- array\n", "---dddfd"].each do |bad_input|
284
+ given_cucumber_yml_defined_as(bad_input)
285
+ lambda{config.parse!([])}.should raise_error(expected_error_message)
286
+ reset_config
287
+ end
217
288
  end
218
- end
219
289
 
220
- it "should procide a helpful error message when the YAML can not be parsed" do
221
- expected_error_message = /cucumber.yml was found, but could not be parsed. Please refer to cucumber's documentation on correct profile usage./
290
+ it "issues a helpful error message when cucumber.yml can not be parsed" do
291
+ expected_error_message = /cucumber.yml was found, but could not be parsed. Please refer to cucumber's documentation on correct profile usage./
222
292
 
223
- given_cucumber_yml_defined_as("input that causes an exception in YAML loading")
224
- YAML.should_receive(:load).and_raise ArgumentError
293
+ given_cucumber_yml_defined_as("input that causes an exception in YAML loading")
294
+ YAML.should_receive(:load).and_raise ArgumentError
225
295
 
226
- config = Configuration.new(StringIO.new, error = StringIO.new)
227
- lambda{config.parse!([])}.should raise_error(expected_error_message)
296
+ lambda{config.parse!([])}.should raise_error(expected_error_message)
297
+ end
228
298
  end
229
299
 
300
+
230
301
  it "should accept --dry-run option" do
231
- config = Configuration.new(StringIO.new)
232
302
  config.parse!(%w{--dry-run})
233
303
  config.options[:dry_run].should be_true
234
304
  end
235
305
 
236
306
  it "should accept --no-source option" do
237
- config = Configuration.new
238
307
  config.parse!(%w{--no-source})
239
308
 
240
309
  config.options[:source].should be_false
241
310
  end
242
311
 
243
312
  it "should accept --no-snippets option" do
244
- config = Configuration.new
245
313
  config.parse!(%w{--no-snippets})
246
314
 
247
315
  config.options[:snippets].should be_false
248
316
  end
249
317
 
250
318
  it "should set snippets and source to false with --quiet option" do
251
- config = Configuration.new
252
319
  config.parse!(%w{--quiet})
253
320
 
254
- config.options[:snippets].should be_nil
255
- config.options[:source].should be_nil
321
+ config.options[:snippets].should be_false
322
+ config.options[:source].should be_false
256
323
  end
257
324
 
258
325
  it "should accept --verbose option" do
259
- config = Configuration.new
260
326
  config.parse!(%w{--verbose})
261
327
 
262
328
  config.options[:verbose].should be_true
263
329
  end
264
330
 
265
331
  it "should accept --out option" do
266
- config = Configuration.new(StringIO.new)
267
332
  config.parse!(%w{--out jalla.txt})
268
333
  config.options[:formats].should == [['pretty', 'jalla.txt']]
269
334
  end
270
335
 
271
336
  it "should accept multiple --out options" do
272
- config = Configuration.new(StringIO.new)
273
337
  config.parse!(%w{--format progress --out file1 --out file2})
274
338
  config.options[:formats].should == [['progress', 'file2']]
275
339
  end
276
340
 
277
341
  it "should accept multiple --format options and put the STDOUT one first so progress is seen" do
278
- io = StringIO.new
279
- config = Configuration.new(io)
280
342
  config.parse!(%w{--format pretty --out pretty.txt --format progress})
281
- config.options[:formats].should == [['progress', io], ['pretty', 'pretty.txt']]
343
+ config.options[:formats].should == [['progress', out], ['pretty', 'pretty.txt']]
282
344
  end
283
345
 
284
346
  it "should not accept multiple --format options when both use implicit STDOUT" do
285
- io = StringIO.new
286
- config = Configuration.new(io)
287
347
  lambda do
288
348
  config.parse!(%w{--format pretty --format progress})
289
349
  end.should raise_error("All but one formatter must use --out, only one can print to STDOUT")
290
350
  end
291
351
 
292
352
  it "should associate --out to previous --format" do
293
- config = Configuration.new(StringIO.new)
294
353
  config.parse!(%w{--format progress --out file1 --format profile --out file2})
295
354
  config.options[:formats].should == [["progress", "file1"], ["profile" ,"file2"]]
296
355
  end
297
356
 
298
357
  it "should accept --color option" do
299
358
  Term::ANSIColor.should_receive(:coloring=).with(true)
300
- config = Configuration.new(StringIO.new)
301
359
  config.parse!(['--color'])
302
360
  end
303
361
 
304
362
  it "should accept --no-color option" do
305
363
  Term::ANSIColor.should_receive(:coloring=).with(false)
306
- config = Configuration.new(StringIO.new)
307
- config.parse!(['--no-color'])
308
- end
309
-
310
- it "should parse tags" do
311
- config = Configuration.new(nil)
312
- includes, excludes = config.parse_tags("one,~two,@three,~@four")
313
- includes.should == ['one', 'three']
314
- excludes.should == ['two', 'four']
364
+ config.parse!(%w[--no-color])
315
365
  end
316
366
 
317
367
  describe "--backtrace" do
@@ -336,12 +386,10 @@ END_OF_MESSAGE
336
386
  describe "diff output" do
337
387
 
338
388
  it "is enabled by default" do
339
- config = Configuration.new
340
389
  config.diff_enabled?.should be_true
341
390
  end
342
391
 
343
392
  it "is disabled when the --no-diff option is supplied" do
344
- config = Configuration.new
345
393
  config.parse!(%w{--no-diff})
346
394
 
347
395
  config.diff_enabled?.should be_false
@@ -350,7 +398,6 @@ END_OF_MESSAGE
350
398
  end
351
399
 
352
400
  it "should accept multiple --name options" do
353
- config = Configuration.new
354
401
  config.parse!(['--name', "User logs in", '--name', "User signs up"])
355
402
 
356
403
  config.options[:name_regexps].should include(/User logs in/)
@@ -358,7 +405,6 @@ END_OF_MESSAGE
358
405
  end
359
406
 
360
407
  it "should accept multiple -n options" do
361
- config = Configuration.new
362
408
  config.parse!(['-n', "User logs in", '-n', "User signs up"])
363
409
 
364
410
  config.options[:name_regexps].should include(/User logs in/)
@@ -370,22 +416,19 @@ END_OF_MESSAGE
370
416
  Dir.should_receive(:[]).with("feature_directory/**/*.feature").
371
417
  any_number_of_times.and_return(["cucumber.feature"])
372
418
 
373
- config = Configuration.new(StringIO)
374
419
  config.parse!(%w{feature_directory/})
375
420
 
376
421
  config.feature_files.should == ["cucumber.feature"]
377
422
  end
378
423
 
379
424
  it "should allow specifying environment variables on the command line" do
380
- config = Configuration.new
381
425
  config.parse!(["foo=bar"])
382
426
  ENV["foo"].should == "bar"
383
427
  config.feature_files.should == []
384
428
  end
385
-
429
+
386
430
  it "should allow specifying environment variables in profiles" do
387
431
  given_cucumber_yml_defined_as({'selenium' => 'RAILS_ENV=selenium'})
388
- config = Configuration.new
389
432
  config.parse!(["--profile", "selenium"])
390
433
  ENV["RAILS_ENV"].should == "selenium"
391
434
  config.feature_files.should == []