cucumber 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. data/History.txt +86 -3
  2. data/Manifest.txt +93 -44
  3. data/Rakefile +5 -1
  4. data/bin/cucumber +1 -0
  5. data/cucumber.yml +1 -1
  6. data/examples/calculator_ruby_features/features/{steps → step_definitons}/calculator_steps.rb +0 -0
  7. data/examples/cs/features/{steps → step_definitons}/hello_steps.rb +0 -0
  8. data/examples/cs/features/{steps → step_definitons}/tree_steps.rb +0 -0
  9. data/examples/i18n/README.textile +18 -0
  10. data/examples/i18n/Rakefile +16 -0
  11. data/examples/i18n/ar/Rakefile +6 -0
  12. data/examples/i18n/ar/features/addition.feature +17 -0
  13. data/examples/i18n/ar/features/step_definitons/calculator_steps.rb +31 -0
  14. data/examples/i18n/ar/lib/calculator.rb +10 -0
  15. data/examples/i18n/da/Rakefile +6 -0
  16. data/examples/{danish_calculator/features/steps → i18n/da/features/step_definitons}/kalkulator_steps.rb +0 -0
  17. data/examples/{danish_calculator → i18n/da}/features/summering.feature +1 -1
  18. data/examples/{danish_calculator → i18n/da}/lib/kalkulator.rb +0 -0
  19. data/examples/{swedish_calculator → i18n/en}/Rakefile +1 -1
  20. data/examples/{calculator → i18n/en}/features/addition.feature +0 -0
  21. data/examples/{calculator → i18n/en}/features/division.feature +0 -0
  22. data/examples/{calculator/features/steps → i18n/en/features/step_definitons}/calculator_steps.rb +0 -0
  23. data/examples/{calculator → i18n/en}/lib/calculator.rb +0 -2
  24. data/examples/i18n/es/Rakefile +6 -0
  25. data/examples/{spanish_calculator → i18n/es}/features/adicion.feature +1 -1
  26. data/examples/{spanish_calculator/features/steps → i18n/es/features/step_definitons}/calculador_steps.rb +0 -0
  27. data/examples/{spanish_calculator/lib/Calculador.rb → i18n/es/lib/calculador.rb} +0 -0
  28. data/examples/i18n/et/Rakefile +6 -0
  29. data/examples/i18n/et/features/liitmine.feature +17 -0
  30. data/examples/{estonian_calculator/features → i18n/et/features/step_definitions}/kalkulaator_steps.rb +2 -11
  31. data/examples/i18n/et/lib/kalkulaator.rb +10 -0
  32. data/examples/i18n/fr/Rakefile +6 -0
  33. data/examples/{calculatrice_francaise_avec_soit_scenario → i18n/fr}/features/addition.feature +0 -0
  34. data/examples/{calculatrice_francaise_avec_soit_scenario/features → i18n/fr/features/step_definitions}/calculatrice_steps.rb +2 -11
  35. data/examples/i18n/fr/lib/calculatrice.rb +10 -0
  36. data/examples/i18n/id/Rakefile +6 -0
  37. data/examples/i18n/id/features/addition.feature +17 -0
  38. data/examples/i18n/id/features/division.feature +10 -0
  39. data/examples/i18n/id/features/step_definitons/calculator_steps.rb +31 -0
  40. data/examples/i18n/id/lib/calculator.rb +14 -0
  41. data/examples/i18n/it/Rakefile +6 -0
  42. data/examples/i18n/it/features/somma.feature +10 -0
  43. data/examples/i18n/it/features/step_definitons/calcolatrice_steps.rb +22 -0
  44. data/examples/i18n/it/lib/calcolatrice.rb +11 -0
  45. data/examples/{calculator → i18n/ja}/README.txt +0 -0
  46. data/examples/i18n/ja/Rakefile +6 -0
  47. data/examples/i18n/ja/features/addition.feature +17 -0
  48. data/examples/i18n/ja/features/division.feature +10 -0
  49. data/examples/i18n/ja/features/step_definitons/calculator_steps.rb +30 -0
  50. data/examples/i18n/ja/lib/calculator.rb +14 -0
  51. data/examples/i18n/no/Rakefile +6 -0
  52. data/examples/{norwegian_calculator/features/steps → i18n/no/features/step_definitons}/kalkulator_steps.rb +0 -0
  53. data/examples/{norwegian_calculator → i18n/no}/features/summering.feature +0 -0
  54. data/examples/{norwegian_calculator → i18n/no}/lib/kalkulator.rb +0 -0
  55. data/examples/i18n/pt/Rakefile +6 -0
  56. data/examples/{portuguese_calculator → i18n/pt}/features/adicao.feature +0 -0
  57. data/examples/{portuguese_calculator/features → i18n/pt/features/step_definitions}/calculadora_steps.rb +2 -11
  58. data/examples/i18n/pt/lib/calculadora.rb +10 -0
  59. data/examples/i18n/ro/Rakefile +6 -0
  60. data/examples/i18n/ro/features/step_definitons/calculator_steps.rb +22 -0
  61. data/examples/i18n/ro/features/suma.feature +10 -0
  62. data/examples/i18n/ro/lib/calculator.rb +11 -0
  63. data/examples/i18n/se/Rakefile +6 -0
  64. data/examples/{swedish_calculator/features/steps → i18n/se/features/step_definitons}/kalkulator_steps.rb +0 -0
  65. data/examples/{swedish_calculator → i18n/se}/features/summering.feature +0 -0
  66. data/examples/{swedish_calculator → i18n/se}/lib/kalkulator.rb +0 -0
  67. data/examples/i18n/zh-CN/Rakefile +6 -0
  68. data/examples/{chinese_simplified_calculator → i18n/zh-CN}/features/addition.feature +0 -0
  69. data/examples/{chinese_simplified_calculator/features/steps → i18n/zh-CN/features/step_definitons}/calculator_steps.rb +0 -0
  70. data/examples/{chinese_simplified_calculator → i18n/zh-CN}/lib/calculator.rb +0 -0
  71. data/examples/java/features/{steps → step_definitons}/hello_steps.rb +0 -0
  72. data/examples/java/features/{steps → step_definitons}/tree_steps.rb +0 -0
  73. data/examples/selenium/features/{steps → step_definitons}/stories_steps.rb +0 -0
  74. data/examples/tickets/features/{steps → step_definitons}/tickets_steps.rb +0 -0
  75. data/examples/watir/features/search.feature +2 -2
  76. data/examples/watir/features/{steps → step_definitons}/stories_steps.rb +0 -0
  77. data/gem_tasks/treetop.rake +1 -9
  78. data/lib/autotest/cucumber.rb +6 -0
  79. data/lib/autotest/cucumber_mixin.rb +109 -0
  80. data/lib/autotest/cucumber_rails.rb +6 -0
  81. data/lib/autotest/cucumber_rails_rspec.rb +6 -0
  82. data/lib/autotest/cucumber_rspec.rb +6 -0
  83. data/lib/autotest/discover.rb +9 -0
  84. data/lib/cucumber.rb +4 -0
  85. data/lib/cucumber/broadcaster.rb +20 -0
  86. data/lib/cucumber/cli.rb +139 -48
  87. data/lib/cucumber/core_ext/proc.rb +2 -3
  88. data/lib/cucumber/executor.rb +59 -32
  89. data/lib/cucumber/formatters.rb +1 -1
  90. data/lib/cucumber/formatters/ansicolor.rb +3 -4
  91. data/lib/cucumber/formatters/autotest_formatter.rb +23 -0
  92. data/lib/cucumber/formatters/pretty_formatter.rb +99 -42
  93. data/lib/cucumber/formatters/progress_formatter.rb +21 -5
  94. data/lib/cucumber/languages.yml +125 -10
  95. data/lib/cucumber/rails/world.rb +1 -1
  96. data/lib/cucumber/rake/task.rb +52 -26
  97. data/lib/cucumber/step_mother.rb +7 -1
  98. data/lib/cucumber/tree/feature.rb +8 -6
  99. data/lib/cucumber/tree/scenario.rb +34 -15
  100. data/lib/cucumber/tree/step.rb +3 -1
  101. data/lib/cucumber/treetop_parser/feature.treetop.erb +15 -10
  102. data/lib/cucumber/treetop_parser/feature_ar.rb +1591 -0
  103. data/lib/cucumber/treetop_parser/feature_cy.rb +1591 -0
  104. data/lib/cucumber/treetop_parser/feature_da.rb +238 -240
  105. data/lib/cucumber/treetop_parser/feature_de.rb +238 -240
  106. data/lib/cucumber/treetop_parser/feature_en-tx.rb +1591 -0
  107. data/lib/cucumber/treetop_parser/feature_en.rb +238 -240
  108. data/lib/cucumber/treetop_parser/feature_es.rb +238 -240
  109. data/lib/cucumber/treetop_parser/feature_et.rb +238 -240
  110. data/lib/cucumber/treetop_parser/feature_fr.rb +238 -240
  111. data/lib/cucumber/treetop_parser/feature_id.rb +1591 -0
  112. data/lib/cucumber/treetop_parser/feature_it.rb +1591 -0
  113. data/lib/cucumber/treetop_parser/feature_ja.rb +1591 -0
  114. data/lib/cucumber/treetop_parser/feature_nl.rb +238 -240
  115. data/lib/cucumber/treetop_parser/feature_no.rb +238 -240
  116. data/lib/cucumber/treetop_parser/feature_pl.rb +1591 -0
  117. data/lib/cucumber/treetop_parser/feature_pt.rb +238 -240
  118. data/lib/cucumber/treetop_parser/feature_ro.rb +1591 -0
  119. data/lib/cucumber/treetop_parser/feature_ro2.rb +1591 -0
  120. data/lib/cucumber/treetop_parser/feature_ru.rb +238 -240
  121. data/lib/cucumber/treetop_parser/feature_se.rb +238 -240
  122. data/lib/cucumber/treetop_parser/feature_zh-CN.rb +238 -240
  123. data/lib/cucumber/version.rb +1 -1
  124. data/rails_generators/cucumber/USAGE +11 -0
  125. data/rails_generators/cucumber/cucumber_generator.rb +9 -6
  126. data/rails_generators/cucumber/templates/cucumber +6 -1
  127. data/rails_generators/cucumber/templates/{common_webrat.rb → webrat_steps.rb} +4 -0
  128. data/rails_generators/feature/USAGE +12 -0
  129. data/rails_generators/feature/feature_generator.rb +3 -4
  130. data/spec/cucumber/broadcaster_spec.rb +27 -0
  131. data/spec/cucumber/cli_spec.rb +211 -23
  132. data/spec/cucumber/executor_spec.rb +104 -14
  133. data/spec/cucumber/formatters/ansicolor_spec.rb +9 -1
  134. data/spec/cucumber/formatters/autotest_formatter_spec.rb +26 -0
  135. data/spec/cucumber/formatters/pretty_formatter_spec.rb +119 -26
  136. data/spec/cucumber/formatters/profile_formatter_spec.rb +1 -2
  137. data/spec/cucumber/formatters/progress_formatter_spec.rb +22 -1
  138. data/spec/cucumber/sell_cucumbers.feature +10 -0
  139. data/spec/cucumber/step_mother_spec.rb +21 -0
  140. data/spec/cucumber/tree/row_scenario_spec.rb +25 -0
  141. data/spec/cucumber/tree/scenario_spec.rb +47 -8
  142. data/spec/cucumber/tree/step_spec.rb +19 -0
  143. data/spec/cucumber/treetop_parser/feature_parser_spec.rb +2 -0
  144. data/spec/cucumber/treetop_parser/multiline_steps.feature +7 -3
  145. data/spec/spec_helper.rb +2 -0
  146. metadata +97 -48
  147. data/examples/calculator/Rakefile +0 -5
  148. data/examples/calculatrice_francaise_avec_soit_scenario/Rakefile +0 -6
  149. data/examples/chinese_simplified_calculator/Rakefile +0 -6
  150. data/examples/danish_calculator/Rakefile +0 -6
  151. data/examples/estonian_calculator/Rakefile +0 -6
  152. data/examples/estonian_calculator/features/liitmine.feature +0 -16
  153. data/examples/norwegian_calculator/Rakefile +0 -6
  154. data/examples/portuguese_calculator/Rakefile +0 -6
  155. data/examples/spanish_calculator/Rakefile +0 -6
@@ -2,7 +2,7 @@ module Cucumber #:nodoc:
2
2
  class VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 8
5
+ TINY = 9
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -0,0 +1,11 @@
1
+ Description:
2
+ Sets up Cucumber in your Rails project. After running this generator you will
3
+ get a new rake task called features.
4
+
5
+ This also generates the necessary files in the features directory.
6
+
7
+ Also see the feature generator, which you can use to generate skeletons
8
+ for new features.
9
+
10
+ Examples:
11
+ `./script/generate cucumber`
@@ -6,15 +6,18 @@ class CucumberGenerator < Rails::Generator::Base
6
6
  Config::CONFIG['ruby_install_name'])
7
7
  def manifest
8
8
  record do |m|
9
- script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
9
+ m.directory 'features/step_definitions'
10
+ m.file 'webrat_steps.rb', 'features/step_definitions/webrat_steps.rb'
10
11
 
11
- m.directory 'features/steps'
12
- m.file 'env.rb', 'features/steps/env.rb'
13
- m.file 'common_webrat.rb', 'features/steps/common_webrat.rb'
12
+ m.directory 'features/support'
13
+ m.file 'env.rb', 'features/support/env.rb'
14
14
 
15
15
  m.directory 'lib/tasks'
16
- m.file 'cucumber.rake', 'lib/tasks/cucumber.rake'
17
- m.file 'cucumber', 'script/cucumber', script_options
16
+ m.file 'cucumber.rake', 'lib/tasks/cucumber.rake'
17
+
18
+ m.file 'cucumber', 'script/cucumber', {
19
+ :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang]
20
+ }
18
21
  end
19
22
  end
20
23
 
@@ -1,2 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- load File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/cucumber/bin/cucumber")
2
+ begin
3
+ load File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/cucumber/bin/cucumber")
4
+ rescue LoadError
5
+ require "rubygems"
6
+ load File.join(Gem.bindir, "cucumber")
7
+ end
@@ -40,3 +40,7 @@ end
40
40
  Then /^I should not see "(.*)"$/ do |text|
41
41
  response.body.should_not =~ /#{text}/m
42
42
  end
43
+
44
+ Then /^the "(.*)" checkbox should be checked$/ do |label|
45
+ field_labeled(label).should be_checked
46
+ end
@@ -0,0 +1,12 @@
1
+ Description:
2
+ Generates a skeleton for a new feature. Both a simple .feature file and
3
+ a steps.rb file is generated. This generator should be used with moderation.
4
+ See http://github.com/aslakhellesoy/cucumber/wikis/feature-coupled-steps-antipattern
5
+ for details about the dangers involved.
6
+
7
+ This generator can take an optional list of attribute pairs similar to Rails'
8
+ built-in resource generator.
9
+
10
+ Examples:
11
+ `./script/generate feature post` # no attributes
12
+ `./script/generate feature post title:string body:text published:boolean`
@@ -2,16 +2,15 @@
2
2
  class FeatureGenerator < Rails::Generator::NamedBase
3
3
  def manifest
4
4
  record do |m|
5
- m.directory 'features/steps'
5
+ m.directory 'features/step_definitions'
6
6
  m.template 'feature.erb', "features/manage_#{plural_name}.feature"
7
- m.template 'steps.erb', "features/steps/#{singular_name}_steps.rb"
7
+ m.template 'steps.erb', "features/step_definitions/#{singular_name}_steps.rb"
8
8
  end
9
9
  end
10
10
 
11
11
  protected
12
12
 
13
13
  def banner
14
- "Usage: #{$0} cucumber"
14
+ "Usage: #{$0} feature ModelName [field:type, field:type]"
15
15
  end
16
-
17
16
  end
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module Cucumber
4
+ describe Broadcaster do
5
+
6
+ it "should broadcast methods to registered objects" do
7
+ broadcaster = Broadcaster.new
8
+ mock_receiver = mock('receiver')
9
+
10
+ mock_receiver.should_receive(:konbanwa).with('good evening')
11
+ broadcaster.register(mock_receiver)
12
+
13
+ broadcaster.konbanwa('good evening')
14
+ end
15
+
16
+ it "should not call methods on registered objects if they dont support the method" do
17
+ broadcaster = Broadcaster.new
18
+ mock_receiver = mock('receiver', :respond_to? => false)
19
+
20
+ mock_receiver.should_not_receive(:konbanwa)
21
+ broadcaster.register(mock_receiver)
22
+
23
+ broadcaster.konbanwa()
24
+ end
25
+
26
+ end
27
+ end
@@ -3,44 +3,101 @@ require 'yaml'
3
3
 
4
4
  module Cucumber
5
5
  describe CLI do
6
+
7
+ def mock_executor(stubs = {})
8
+ stub('executor', {:visit_features => nil, :failed => false, :formatters= => nil}.merge(stubs))
9
+ end
10
+
11
+ def mock_broadcaster(stubs = {})
12
+ stub(Broadcaster, {:register => nil}.merge(stubs))
13
+ end
14
+
15
+ before(:each) do
16
+ Kernel.stub!(:exit)
17
+ end
18
+
19
+ def given_cucumber_yml_defined_as(hash)
20
+ File.stub!(:exist?).and_return(true)
21
+ cucumber_yml = hash.to_yaml
22
+ IO.stub!(:read).with('cucumber.yml').and_return(cucumber_yml)
23
+ end
24
+
6
25
  it "should expand args from YAML file" do
7
26
  cli = CLI.new
8
-
9
- cucumber_yml = {'bongo' => '--require from/yml'}.to_yaml
10
- IO.should_receive(:read).with('cucumber.yml').and_return(cucumber_yml)
27
+
28
+ given_cucumber_yml_defined_as({'bongo' => '--require from/yml'})
11
29
 
12
30
  cli.parse_options!(%w{--format progress --profile bongo})
13
- cli.options.should == {
14
- :format => 'progress',
15
- :require => ['from/yml'],
16
- :dry_run => false,
17
- :lang => 'en',
18
- :source => true,
19
- :out => STDOUT
20
- }
31
+ cli.options[:formats].should == {'progress' => [STDOUT]}
32
+ cli.options[:require].should == ['from/yml']
21
33
  end
22
34
 
23
35
  it "should expand args from YAML file's default if there are no args" do
24
36
  cli = CLI.new
25
37
 
26
- cucumber_yml = {'default' => '--require from/yml'}.to_yaml
27
- IO.should_receive(:read).with('cucumber.yml').and_return(cucumber_yml)
38
+ given_cucumber_yml_defined_as({'default' => '--require from/yml'})
28
39
 
29
40
  cli.parse_options!([])
30
- cli.options.should == {
31
- :format => 'pretty',
32
- :require => ['from/yml'],
33
- :dry_run => false,
34
- :lang => 'en',
35
- :source => true,
36
- :out => STDOUT
37
- }
41
+ cli.options[:require].should == ['from/yml']
42
+ end
43
+
44
+ it "should provide a helpful error message when a specified profile does not exists in YAML file" do
45
+ cli = CLI.new(StringIO.new, error = StringIO.new)
46
+
47
+ given_cucumber_yml_defined_as({'default' => '--require from/yml', 'html_report' => '--format html'})
48
+
49
+ cli.parse_options!(%w{--profile i_do_not_exist})
50
+
51
+ expected_message = <<-END_OF_MESSAGE
52
+ Could not find profile: 'i_do_not_exist'
53
+
54
+ Defined profiles in cucumber.yml:
55
+ * default
56
+ * html_report
57
+ END_OF_MESSAGE
58
+
59
+ error.string.should == expected_message
60
+ end
61
+
62
+ it "should provide a helpful error message when a specified profile is not a String" do
63
+ cli = CLI.new(StringIO.new, error = StringIO.new)
64
+
65
+ given_cucumber_yml_defined_as({'foo' => [1,2,3]})
66
+
67
+ cli.parse_options!(%w{--profile foo})
68
+
69
+ error.string.should == "Profiles must be defined as a String. The 'foo' profile was [1, 2, 3] (Array).\n"
38
70
  end
39
71
 
72
+ it "should provide a helpful error message when no YAML file exists and a profile is specified" do
73
+ cli = CLI.new(StringIO.new, error = StringIO.new)
74
+
75
+ File.should_receive(:exist?).with('cucumber.yml').and_return(false)
76
+
77
+ cli.parse_options!(%w{--profile i_do_not_exist})
78
+
79
+ error.string.should match(/cucumber.yml was not found. Please define your 'i_do_not_exist' and other profiles in cucumber.yml./)
80
+ end
81
+
40
82
  it "should accept --no-source option" do
41
83
  cli = CLI.new
42
84
  cli.parse_options!(%w{--no-source})
85
+
86
+ cli.options[:source].should be_false
87
+ end
88
+
89
+ it "should accept --no-snippets option" do
90
+ cli = CLI.new
91
+ cli.parse_options!(%w{--no-snippets})
43
92
 
93
+ cli.options[:snippets].should be_false
94
+ end
95
+
96
+ it "should accept --quiet option" do
97
+ cli = CLI.new
98
+ cli.parse_options!(%w{--quiet})
99
+
100
+ cli.options[:snippets].should be_false
44
101
  cli.options[:source].should be_false
45
102
  end
46
103
 
@@ -49,6 +106,137 @@ module Cucumber
49
106
  File.should_receive(:open).with('jalla.txt', 'w')
50
107
  cli.parse_options!(%w{--out jalla.txt})
51
108
  end
52
-
109
+
110
+ it "should accept multiple --out options" do
111
+ cli = CLI.new
112
+ mock_file1 = stub(File, :open => nil)
113
+ mock_file2 = stub(File, :open => nil)
114
+ File.stub!(:open).and_return(mock_file1, mock_file2)
115
+
116
+ cli.parse_options!(%w{--format progress --out file1 --out file2})
117
+ cli.options[:formats].should == {'progress' => [mock_file1, mock_file2]}
118
+ end
119
+
120
+ it "should accept multiple --format options" do
121
+ cli = CLI.new
122
+ cli.parse_options!(%w{--format pretty --format progress})
123
+ cli.options[:formats].should have_key('pretty')
124
+ cli.options[:formats].should have_key('progress')
125
+ end
126
+
127
+ it "should associate --out to previous --format" do
128
+ cli = CLI.new
129
+ mock_file1 = stub(File, :open => nil)
130
+ mock_file2 = stub(File, :open => nil)
131
+ File.stub!(:open).and_return(mock_file1, mock_file2)
132
+
133
+ cli.parse_options!(%w{--format progress --out file1 --format profile --out file2})
134
+ cli.options[:formats].should == {'progress' => [mock_file1], 'profile' => [mock_file2]}
135
+ end
136
+
137
+ it "should allow a single formatter to have STDOUT and a file" do
138
+ cli = CLI.new
139
+ mock_file = stub(File, :open => nil)
140
+ File.stub!(:open).and_return(mock_file)
141
+
142
+ cli.parse_options!(%w{--format progress --format progress --out file})
143
+ cli.options[:formats].should == {'progress' => [STDOUT, mock_file]}
144
+ end
145
+
146
+ it "should register --out files with an output broadcaster" do
147
+ cli = CLI.new
148
+ mock_file = stub(File)
149
+ File.stub!(:open).and_return(mock_file)
150
+ mock_output_broadcaster = mock_broadcaster
151
+ Broadcaster.stub!(:new).and_return(mock_broadcaster, mock_output_broadcaster)
152
+
153
+ mock_output_broadcaster.should_receive(:register).with(mock_file)
154
+ cli.parse_options!(%w{--out test.file})
155
+
156
+ cli.execute!(stub('step mother'), mock_executor, stub('features'))
157
+ end
158
+
159
+ it "should register --formatters with the formatter broadcaster" do
160
+ cli = CLI.new
161
+ mock_progress_formatter = stub(Formatters::ProgressFormatter)
162
+ Formatters::ProgressFormatter.stub!(:new).and_return(mock_progress_formatter)
163
+ mock_formatter_broadcaster = mock_broadcaster
164
+ Broadcaster.stub!(:new).and_return(mock_formatter_broadcaster, mock_broadcaster)
165
+
166
+ mock_formatter_broadcaster.should_receive(:register).with(mock_progress_formatter)
167
+ cli.parse_options!(%w{--format progress})
168
+
169
+ cli.execute!(stub('step mother'), mock_executor, stub('features'))
170
+ end
171
+
172
+ it "should setup the executor with the formatter broadcaster" do
173
+ cli = CLI.new
174
+ broadcaster = Broadcaster.new
175
+ Broadcaster.stub!(:new).and_return(broadcaster)
176
+ mock_executor = mock_executor()
177
+ mock_executor.should_receive(:formatters=).with(broadcaster)
178
+ cli.parse_options!(%w{--format progress})
179
+
180
+ cli.execute!(stub('step mother'), mock_executor, stub('features'))
181
+ end
182
+
183
+ it "should accept multiple --scenario options" do
184
+ cli = CLI.new
185
+ cli.parse_options!(['--scenario', "User logs in", '--scenario', "User signs up"])
186
+ cli.options[:scenario_names].should include("User logs in")
187
+ cli.options[:scenario_names].should include("User signs up")
188
+ end
189
+
190
+ it "should register --scenario options with the executor" do
191
+ cli = CLI.new
192
+ cli.parse_options!(['--scenario', "User logs in", '--scenario', "User signs up"])
193
+ executor = mock_executor
194
+ executor.should_receive(:scenario_names=).with(["User logs in", "User signs up"])
195
+ cli.execute!(stub('step mother'), executor, stub('features'))
196
+ end
197
+
198
+ it "should accept --color option" do
199
+ cli = CLI.new
200
+ cli.parse_options!(['--color'])
201
+ cli.options[:color].should == true
202
+ Term::ANSIColor.should_receive(:coloring=).with(true)
203
+ cli.execute!(stub('step mother'), mock_executor, stub('features'))
204
+ end
205
+
206
+ it "should accept --no-color option" do
207
+ cli = CLI.new
208
+ cli.parse_options!(['--no-color'])
209
+ cli.options[:color].should == false
210
+ Term::ANSIColor.should_receive(:coloring=).with(false)
211
+ cli.execute!(stub('step mother'), mock_executor, stub('features'))
212
+ end
213
+
214
+ it "should accept --color and --no-color and use the last one" do
215
+ cli = CLI.new
216
+ cli.parse_options!(['--color', '--no-color'])
217
+ cli.options[:color].should == false
218
+ Term::ANSIColor.should_receive(:coloring=).with(false)
219
+ cli.execute!(stub('step mother'), mock_executor, stub('features'))
220
+ end
221
+
222
+ it "should use a default color setting if no option is given" do
223
+ cli = CLI.new
224
+ cli.parse_options!(['--'])
225
+ cli.options[:color].should == nil
226
+ Term::ANSIColor.should_not_receive(:coloring=)
227
+ cli.execute!(stub('step mother'), mock_executor, stub('features'))
228
+ end
229
+
230
+ it "should search for all features in the specified directory" do
231
+ cli = CLI.new
232
+
233
+ cli.parse_options!(%w{feature_directory/})
234
+ File.stub!(:directory?).and_return(true)
235
+
236
+ Dir.should_receive(:[]).with("feature_directory/**/*.feature").any_number_of_times.and_return([])
237
+
238
+ cli.execute!(stub('step mother'), mock_executor, stub('features', :<< => nil))
239
+ end
240
+
53
241
  end
54
- end
242
+ end
@@ -7,12 +7,13 @@ module Cucumber
7
7
  @io = StringIO.new
8
8
  @step_mother = StepMother.new
9
9
  @executor = Executor.new(@step_mother)
10
- @formatter = Formatters::ProgressFormatter.new(@io)
11
- @executor.formatter = @formatter
10
+ @formatters = Broadcaster.new [Formatters::ProgressFormatter.new(@io)]
11
+ @executor.formatters = @formatters
12
12
  @feature_file = File.dirname(__FILE__) + '/sell_cucumbers.feature'
13
13
  @parser = TreetopParser::FeatureParser.new
14
14
  @features = Tree::Features.new
15
- @features << @parser.parse_feature(@feature_file)
15
+ @feature = @parser.parse_feature(@feature_file)
16
+ @features << @feature
16
17
  end
17
18
 
18
19
  it "should pass when blocks are ok" do
@@ -20,12 +21,9 @@ module Cucumber
20
21
  @step_mother.register_step_proc(/I sell (\d*) cucumbers/) { |n| @n -= n.to_i }
21
22
  @step_mother.register_step_proc(/I should owe (\d*) cucumbers/) { |n| @n.should == -n.to_i }
22
23
  @executor.visit_features(@features)
23
- @formatter.dump
24
- @io.string.should == (<<-STDOUT).strip
25
- \e[0m\e[1m\e[32m.\e[0m\e[0m\e[0m\e[1m\e[32m.\e[0m\e[0m\e[0m\e[1m\e[32m.\e[0m\e[0m\e[0m\e[1m\e[31m\n\e[0m\e[0m\e[1m\e[31m
26
- \e[0m
27
- STDOUT
24
+ @formatters.dump
28
25
 
26
+ @io.string.should =~ (/\.+\n+/)
29
27
  end
30
28
 
31
29
  it "should print filtered backtrace with feature line" do
@@ -33,15 +31,13 @@ STDOUT
33
31
  @step_mother.register_step_proc(/I sell (\d*) cucumbers/) { |n| @n = n }
34
32
  @step_mother.register_step_proc(/I should owe (\d*) cucumbers/) { |n| raise "dang" }
35
33
  @executor.visit_features(@features)
36
- @io.string.should == (<<-STDOUT).strip
37
- \e[0m\e[1m\e[32m.\e[0m\e[0m\e[0m\e[1m\e[32m.\e[0m\e[0m\e[0m\e[1m\e[31mF\e[0m\e[0m\e[0m\e[1m\e[31m
34
+ @io.string.should include(%{Failed:
38
35
 
39
36
  1)
40
37
  dang
41
- #{__FILE__}:34:in `Then /I should owe (\\d*) cucumbers/'
38
+ #{__FILE__}:32:in `Then /I should owe (\\d*) cucumbers/'
42
39
  #{@feature_file}:9:in `Then I should owe 7 cucumbers'
43
- \e[0m
44
- STDOUT
40
+ })
45
41
  end
46
42
 
47
43
  # it "should allow calling of other steps from steps" do
@@ -49,7 +45,7 @@ STDOUT
49
45
  # @executor.register_step_proc("I will call you") { @executor.register_step_proc("call me please") }
50
46
  # @executor.register_step_proc(/I should owe (\d*) cucumbers/) { |n| @n.should == -n.to_i }
51
47
  # @feature.accept(@executor)
52
- # @formatter.dump
48
+ # @formatters.each { |formatter| formatter.dump }
53
49
  # @io.string.should == "...\n"
54
50
  # end
55
51
 
@@ -127,6 +123,100 @@ STDOUT
127
123
  end
128
124
 
129
125
  end
126
+
127
+ describe "visiting row scenarios" do
128
+
129
+ def mock_row_scenario(stubs = {})
130
+ @row_scenario ||= stub("row scenario", {
131
+ :row? => true,
132
+ :name => 'test',
133
+ :update_table_column_widths => nil,
134
+ :steps => [],
135
+ :pending? => true
136
+ }.merge(stubs))
137
+ end
138
+
139
+ describe "without having first run the matching regular scenario" do
140
+
141
+ before(:each) do
142
+ @scenario = Tree::Scenario.new(nil, 'test', 1)
143
+ @executor.line=5
144
+ @executor.visit_regular_scenario(@scenario)
145
+ end
146
+
147
+ it "should run the regular scenario before the row scenario" do
148
+ @scenario.should_receive(:accept)
149
+
150
+ @executor.visit_row_scenario(mock_row_scenario(:name => 'test', :at_line? => true, :accept => nil))
151
+ end
152
+
153
+ it "should run the row scenario after running the regular scenario" do
154
+ mock_row_scenario(:at_line? => true).should_receive(:accept)
155
+
156
+ @executor.visit_row_scenario(mock_row_scenario)
157
+ end
158
+
159
+ end
160
+
161
+ describe "having run matching regular scenario" do
162
+
163
+ it "should not run the regular scenario if it has already run" do
164
+ scenario = Tree::Scenario.new(nil, 'test', 1)
165
+ @executor.visit_regular_scenario(scenario)
166
+
167
+ scenario.should_not_receive(:accept)
168
+
169
+ @executor.visit_row_scenario(mock_row_scenario(:name => 'test', :at_line? => true, :accept => nil))
170
+ end
171
+
172
+ end
173
+ end
174
+
175
+ describe "caching visited scenarios" do
176
+
177
+ def mock_scenario(stubs = {})
178
+ @scenario ||= stub("scenario", {
179
+ :row? => false,
180
+ :name => 'test',
181
+ :accept => nil,
182
+ :steps => [],
183
+ :pending? => true
184
+ }.merge(stubs))
185
+ end
186
+
187
+ it "should reset cache after each feature visit" do
188
+ Tree::Scenario.stub!(:new).and_return(mock_scenario)
189
+
190
+ feature = Tree::Feature.new(nil)
191
+ feature.add_scenario(nil, nil)
192
+
193
+ @executor.visit_feature(feature)
194
+
195
+ @executor.instance_variable_get("@regular_scenario_cache").should == {}
196
+ @executor.instance_variable_get("@executed_scenarios").should == {}
197
+ end
198
+
199
+ end
200
+
201
+ describe "with specified scenarios" do
202
+ it "should only visit the specified scenarios" do
203
+ $amounts_sold = []
130
204
 
205
+ @step_mother.register_step_proc(/there are (\d*) cucumbers/) { |n| }
206
+ @step_mother.register_step_proc(/I should owe (\d*) cucumbers/) { |n| }
207
+ @step_mother.register_step_proc(/I sell (\d*) cucumbers/) { |n| $amounts_sold << n.to_i }
208
+
209
+ @executor.scenario_names = ["Sell a dozen", "Sell fifty"]
210
+ @executor.visit_features(@features)
211
+
212
+ $amounts_sold.should == [12, 50]
213
+ end
214
+
215
+ it "should only visit features with specified scenarios" do
216
+ @executor.scenario_names = ["Jump up and down"]
217
+ @feature.should_not_receive(:accept).with(@executor)
218
+ @executor.visit_features(@features)
219
+ end
220
+ end
131
221
  end
132
222
  end