jeffrafter-cucumber 0.1.10

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 (242) hide show
  1. data/History.txt +262 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +241 -0
  4. data/README.txt +41 -0
  5. data/Rakefile +8 -0
  6. data/TODO.txt +26 -0
  7. data/bin/cucumber +6 -0
  8. data/config/hoe.rb +69 -0
  9. data/config/requirements.rb +15 -0
  10. data/cucumber.yml +1 -0
  11. data/examples/calculator_ruby_features/Rakefile +6 -0
  12. data/examples/calculator_ruby_features/features/addition.rb +23 -0
  13. data/examples/calculator_ruby_features/features/step_definitons/calculator_steps.rb +43 -0
  14. data/examples/cs/README.textile +22 -0
  15. data/examples/cs/Rakefile +12 -0
  16. data/examples/cs/features/hello.feature +11 -0
  17. data/examples/cs/features/step_definitons/hello_steps.rb +25 -0
  18. data/examples/cs/features/step_definitons/tree_steps.rb +14 -0
  19. data/examples/cs/features/tree.feature +9 -0
  20. data/examples/cs/src/Hello.cs +18 -0
  21. data/examples/dos_line_endings/Rakefile +6 -0
  22. data/examples/dos_line_endings/features/dos_line_endings.feature +9 -0
  23. data/examples/i18n/README.textile +18 -0
  24. data/examples/i18n/Rakefile +16 -0
  25. data/examples/i18n/ar/Rakefile +6 -0
  26. data/examples/i18n/ar/features/addition.feature +17 -0
  27. data/examples/i18n/ar/features/step_definitons/calculator_steps.rb +32 -0
  28. data/examples/i18n/ar/lib/calculator.rb +10 -0
  29. data/examples/i18n/da/Rakefile +6 -0
  30. data/examples/i18n/da/features/step_definitons/kalkulator_steps.rb +22 -0
  31. data/examples/i18n/da/features/summering.feature +17 -0
  32. data/examples/i18n/da/lib/kalkulator.rb +11 -0
  33. data/examples/i18n/de/Rakefile +6 -0
  34. data/examples/i18n/de/features/addition.feature +17 -0
  35. data/examples/i18n/de/features/division.feature +10 -0
  36. data/examples/i18n/de/features/step_definitons/calculator_steps.rb +30 -0
  37. data/examples/i18n/de/lib/calculator.rb +14 -0
  38. data/examples/i18n/en/Rakefile +6 -0
  39. data/examples/i18n/en/features/addition.feature +17 -0
  40. data/examples/i18n/en/features/division.feature +10 -0
  41. data/examples/i18n/en/features/step_definitons/calculator_steps.rb +31 -0
  42. data/examples/i18n/en/lib/calculator.rb +14 -0
  43. data/examples/i18n/es/Rakefile +6 -0
  44. data/examples/i18n/es/features/adicion.feature +17 -0
  45. data/examples/i18n/es/features/step_definitons/calculador_steps.rb +22 -0
  46. data/examples/i18n/es/lib/calculador.rb +11 -0
  47. data/examples/i18n/et/Rakefile +6 -0
  48. data/examples/i18n/et/features/liitmine.feature +17 -0
  49. data/examples/i18n/et/features/step_definitions/kalkulaator_steps.rb +26 -0
  50. data/examples/i18n/et/lib/kalkulaator.rb +10 -0
  51. data/examples/i18n/fr/Rakefile +6 -0
  52. data/examples/i18n/fr/features/addition.feature +13 -0
  53. data/examples/i18n/fr/features/step_definitions/calculatrice_steps.rb +22 -0
  54. data/examples/i18n/fr/lib/calculatrice.rb +10 -0
  55. data/examples/i18n/id/Rakefile +6 -0
  56. data/examples/i18n/id/features/addition.feature +17 -0
  57. data/examples/i18n/id/features/division.feature +10 -0
  58. data/examples/i18n/id/features/step_definitons/calculator_steps.rb +31 -0
  59. data/examples/i18n/id/lib/calculator.rb +14 -0
  60. data/examples/i18n/it/Rakefile +6 -0
  61. data/examples/i18n/it/features/somma.feature +10 -0
  62. data/examples/i18n/it/features/step_definitons/calcolatrice_steps.rb +22 -0
  63. data/examples/i18n/it/lib/calcolatrice.rb +11 -0
  64. data/examples/i18n/ja/README.txt +5 -0
  65. data/examples/i18n/ja/Rakefile +6 -0
  66. data/examples/i18n/ja/features/addition.feature +17 -0
  67. data/examples/i18n/ja/features/division.feature +10 -0
  68. data/examples/i18n/ja/features/step_definitons/calculator_steps.rb +30 -0
  69. data/examples/i18n/ja/lib/calculator.rb +14 -0
  70. data/examples/i18n/lt/Rakefile +6 -0
  71. data/examples/i18n/lt/features/addition.feature +17 -0
  72. data/examples/i18n/lt/features/division.feature +10 -0
  73. data/examples/i18n/lt/features/step_definitons/calculator_steps.rb +31 -0
  74. data/examples/i18n/lt/lib/calculator.rb +14 -0
  75. data/examples/i18n/no/Rakefile +6 -0
  76. data/examples/i18n/no/features/step_definitons/kalkulator_steps.rb +22 -0
  77. data/examples/i18n/no/features/summering.feature +17 -0
  78. data/examples/i18n/no/lib/kalkulator.rb +11 -0
  79. data/examples/i18n/pt/Rakefile +6 -0
  80. data/examples/i18n/pt/features/adicao.feature +10 -0
  81. data/examples/i18n/pt/features/step_definitions/calculadora_steps.rb +22 -0
  82. data/examples/i18n/pt/lib/calculadora.rb +10 -0
  83. data/examples/i18n/ro/Rakefile +6 -0
  84. data/examples/i18n/ro/features/step_definitons/calculator_steps.rb +22 -0
  85. data/examples/i18n/ro/features/suma.feature +10 -0
  86. data/examples/i18n/ro/lib/calculator.rb +11 -0
  87. data/examples/i18n/se/Rakefile +6 -0
  88. data/examples/i18n/se/features/step_definitons/kalkulator_steps.rb +22 -0
  89. data/examples/i18n/se/features/summering.feature +17 -0
  90. data/examples/i18n/se/lib/kalkulator.rb +11 -0
  91. data/examples/i18n/zh-CN/Rakefile +6 -0
  92. data/examples/i18n/zh-CN/features/addition.feature +17 -0
  93. data/examples/i18n/zh-CN/features/step_definitons/calculator_steps.rb +24 -0
  94. data/examples/i18n/zh-CN/lib/calculator.rb +10 -0
  95. data/examples/java/README.textile +22 -0
  96. data/examples/java/Rakefile +12 -0
  97. data/examples/java/features/hello.feature +11 -0
  98. data/examples/java/features/step_definitons/hello_steps.rb +25 -0
  99. data/examples/java/features/step_definitons/tree_steps.rb +14 -0
  100. data/examples/java/features/tree.feature +9 -0
  101. data/examples/java/src/cucumber/demo/Hello.java +16 -0
  102. data/examples/selenium/Rakefile +6 -0
  103. data/examples/selenium/features/search.feature +9 -0
  104. data/examples/selenium/features/step_definitons/stories_steps.rb +41 -0
  105. data/examples/test_unit/Rakefile +6 -0
  106. data/examples/test_unit/features/step_definitions/test_unit_steps.rb +26 -0
  107. data/examples/test_unit/features/test_unit.feature +9 -0
  108. data/examples/tickets/Rakefile +11 -0
  109. data/examples/tickets/cucumber.yml +2 -0
  110. data/examples/tickets/features/step_definitons/tickets_steps.rb +32 -0
  111. data/examples/tickets/features/tickets.feature +24 -0
  112. data/examples/watir/Rakefile +6 -0
  113. data/examples/watir/features/search.feature +9 -0
  114. data/examples/watir/features/step_definitons/stories_steps.rb +51 -0
  115. data/features/see_features.feature +8 -0
  116. data/features/steps/features_steps.rb +9 -0
  117. data/gem_tasks/deployment.rake +34 -0
  118. data/gem_tasks/environment.rake +7 -0
  119. data/gem_tasks/features.rake +6 -0
  120. data/gem_tasks/fix_cr_lf.rake +10 -0
  121. data/gem_tasks/flog.rake +4 -0
  122. data/gem_tasks/gemspec.rake +6 -0
  123. data/gem_tasks/rspec.rake +35 -0
  124. data/gem_tasks/treetop.rake +41 -0
  125. data/lib/autotest/cucumber.rb +6 -0
  126. data/lib/autotest/cucumber_mixin.rb +109 -0
  127. data/lib/autotest/cucumber_rails.rb +6 -0
  128. data/lib/autotest/cucumber_rails_rspec.rb +6 -0
  129. data/lib/autotest/cucumber_rspec.rb +6 -0
  130. data/lib/autotest/discover.rb +9 -0
  131. data/lib/cucumber/broadcaster.rb +20 -0
  132. data/lib/cucumber/cli.rb +303 -0
  133. data/lib/cucumber/core_ext/proc.rb +69 -0
  134. data/lib/cucumber/core_ext/string.rb +28 -0
  135. data/lib/cucumber/executor.rb +190 -0
  136. data/lib/cucumber/formatters/ansicolor.rb +109 -0
  137. data/lib/cucumber/formatters/autotest_formatter.rb +23 -0
  138. data/lib/cucumber/formatters/cucumber.css +132 -0
  139. data/lib/cucumber/formatters/cucumber.js +11 -0
  140. data/lib/cucumber/formatters/html_formatter.rb +128 -0
  141. data/lib/cucumber/formatters/jquery.js +32 -0
  142. data/lib/cucumber/formatters/pretty_formatter.rb +234 -0
  143. data/lib/cucumber/formatters/profile_formatter.rb +92 -0
  144. data/lib/cucumber/formatters/progress_formatter.rb +58 -0
  145. data/lib/cucumber/formatters.rb +1 -0
  146. data/lib/cucumber/languages.yml +258 -0
  147. data/lib/cucumber/model/table.rb +28 -0
  148. data/lib/cucumber/model.rb +1 -0
  149. data/lib/cucumber/platform.rb +12 -0
  150. data/lib/cucumber/rails/rspec.rb +12 -0
  151. data/lib/cucumber/rails/world.rb +73 -0
  152. data/lib/cucumber/rake/task.rb +101 -0
  153. data/lib/cucumber/step_methods.rb +49 -0
  154. data/lib/cucumber/step_mother.rb +95 -0
  155. data/lib/cucumber/tree/feature.rb +63 -0
  156. data/lib/cucumber/tree/features.rb +21 -0
  157. data/lib/cucumber/tree/given_scenario.rb +13 -0
  158. data/lib/cucumber/tree/scenario.rb +174 -0
  159. data/lib/cucumber/tree/step.rb +134 -0
  160. data/lib/cucumber/tree/table.rb +26 -0
  161. data/lib/cucumber/tree/top_down_visitor.rb +23 -0
  162. data/lib/cucumber/tree.rb +18 -0
  163. data/lib/cucumber/treetop_parser/feature.treetop.erb +206 -0
  164. data/lib/cucumber/treetop_parser/feature_ar.rb +1591 -0
  165. data/lib/cucumber/treetop_parser/feature_cy.rb +1591 -0
  166. data/lib/cucumber/treetop_parser/feature_da.rb +1591 -0
  167. data/lib/cucumber/treetop_parser/feature_de.rb +1591 -0
  168. data/lib/cucumber/treetop_parser/feature_en-tx.rb +1591 -0
  169. data/lib/cucumber/treetop_parser/feature_en.rb +1591 -0
  170. data/lib/cucumber/treetop_parser/feature_es.rb +1591 -0
  171. data/lib/cucumber/treetop_parser/feature_et.rb +1591 -0
  172. data/lib/cucumber/treetop_parser/feature_fr.rb +1591 -0
  173. data/lib/cucumber/treetop_parser/feature_id.rb +1591 -0
  174. data/lib/cucumber/treetop_parser/feature_it.rb +1591 -0
  175. data/lib/cucumber/treetop_parser/feature_ja.rb +1591 -0
  176. data/lib/cucumber/treetop_parser/feature_lt.rb +1591 -0
  177. data/lib/cucumber/treetop_parser/feature_nl.rb +1591 -0
  178. data/lib/cucumber/treetop_parser/feature_no.rb +1591 -0
  179. data/lib/cucumber/treetop_parser/feature_parser.rb +34 -0
  180. data/lib/cucumber/treetop_parser/feature_pl.rb +1591 -0
  181. data/lib/cucumber/treetop_parser/feature_pt.rb +1591 -0
  182. data/lib/cucumber/treetop_parser/feature_ro.rb +1591 -0
  183. data/lib/cucumber/treetop_parser/feature_ro2.rb +1591 -0
  184. data/lib/cucumber/treetop_parser/feature_ru.rb +1591 -0
  185. data/lib/cucumber/treetop_parser/feature_se.rb +1591 -0
  186. data/lib/cucumber/treetop_parser/feature_zh-CN.rb +1591 -0
  187. data/lib/cucumber/version.rb +9 -0
  188. data/lib/cucumber.rb +38 -0
  189. data/rails_generators/cucumber/USAGE +11 -0
  190. data/rails_generators/cucumber/cucumber_generator.rb +30 -0
  191. data/rails_generators/cucumber/templates/cucumber +7 -0
  192. data/rails_generators/cucumber/templates/cucumber.rake +7 -0
  193. data/rails_generators/cucumber/templates/env.rb +8 -0
  194. data/rails_generators/cucumber/templates/webrat_steps.rb +95 -0
  195. data/rails_generators/feature/USAGE +12 -0
  196. data/rails_generators/feature/feature_generator.rb +16 -0
  197. data/rails_generators/feature/templates/feature.erb +28 -0
  198. data/rails_generators/feature/templates/steps.erb +22 -0
  199. data/script/console +10 -0
  200. data/script/console.cmd +1 -0
  201. data/script/destroy +14 -0
  202. data/script/destroy.cmd +1 -0
  203. data/script/generate +14 -0
  204. data/script/generate.cmd +1 -0
  205. data/script/txt2html +74 -0
  206. data/script/txt2html.cmd +1 -0
  207. data/setup.rb +1585 -0
  208. data/spec/cucumber/broadcaster_spec.rb +27 -0
  209. data/spec/cucumber/cli_spec.rb +412 -0
  210. data/spec/cucumber/core_ext/proc_spec.rb +45 -0
  211. data/spec/cucumber/core_ext/string_spec.rb +34 -0
  212. data/spec/cucumber/executor_spec.rb +298 -0
  213. data/spec/cucumber/formatters/ansicolor_spec.rb +35 -0
  214. data/spec/cucumber/formatters/autotest_formatter_spec.rb +26 -0
  215. data/spec/cucumber/formatters/features.html +269 -0
  216. data/spec/cucumber/formatters/html_formatter_spec.rb +74 -0
  217. data/spec/cucumber/formatters/pretty_formatter_spec.rb +204 -0
  218. data/spec/cucumber/formatters/profile_formatter_spec.rb +192 -0
  219. data/spec/cucumber/formatters/progress_formatter_spec.rb +65 -0
  220. data/spec/cucumber/model/table_spec.rb +20 -0
  221. data/spec/cucumber/rails/stubs/mini_rails.rb +17 -0
  222. data/spec/cucumber/rails/stubs/test_help.rb +1 -0
  223. data/spec/cucumber/rails/world_spec.rb +11 -0
  224. data/spec/cucumber/sell_cucumbers.feature +19 -0
  225. data/spec/cucumber/step_mother_spec.rb +74 -0
  226. data/spec/cucumber/tree/feature_spec.rb +43 -0
  227. data/spec/cucumber/tree/row_scenario_spec.rb +55 -0
  228. data/spec/cucumber/tree/scenario_spec.rb +76 -0
  229. data/spec/cucumber/tree/step_spec.rb +50 -0
  230. data/spec/cucumber/treetop_parser/empty_feature.feature +4 -0
  231. data/spec/cucumber/treetop_parser/empty_scenario.feature +9 -0
  232. data/spec/cucumber/treetop_parser/feature_parser_spec.rb +98 -0
  233. data/spec/cucumber/treetop_parser/fit_scenario.feature +8 -0
  234. data/spec/cucumber/treetop_parser/given_scenario.feature +9 -0
  235. data/spec/cucumber/treetop_parser/multiline_steps.feature +17 -0
  236. data/spec/cucumber/treetop_parser/multiple_tables.feature +29 -0
  237. data/spec/cucumber/treetop_parser/spaces.feature +10 -0
  238. data/spec/cucumber/treetop_parser/test_dos.feature +25 -0
  239. data/spec/cucumber/treetop_parser/with_comments.feature +10 -0
  240. data/spec/spec.opts +2 -0
  241. data/spec/spec_helper.rb +20 -0
  242. metadata +335 -0
@@ -0,0 +1,204 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ module Cucumber
4
+ module Formatters
5
+ describe PrettyFormatter do
6
+
7
+ def mock_step(stubs={})
8
+ stub('step', {
9
+ :keyword => 'Given',
10
+ :format => 'formatted yes',
11
+ :name => 'example',
12
+ :error => nil,
13
+ :padding_length => 2,
14
+ :file => 'test',
15
+ :line => 1,
16
+ :row? => false}.merge(stubs))
17
+ end
18
+
19
+ def mock_scenario(stubs={})
20
+ stub('scenario', {
21
+ :name => 'test',
22
+ :row? => false,
23
+ :pending? => false,
24
+ :file => 'file',
25
+ :line => 1,
26
+ :padding_length => 2}.merge(stubs))
27
+ end
28
+
29
+ def mock_feature(stubs={})
30
+ stub("feature", stubs)
31
+ end
32
+
33
+ def mock_error(stubs={})
34
+ stub('error', {
35
+ :message => 'failed',
36
+ :backtrace => 'example backtrace'}.merge(stubs))
37
+ end
38
+
39
+ def mock_proc
40
+ stub(Proc, :to_comment_line => '# steps/example_steps.rb:11')
41
+ end
42
+
43
+ it "should print step file and line when passed" do
44
+ io = StringIO.new
45
+ formatter = PrettyFormatter.new io, StepMother.new
46
+ step = stub('step',
47
+ :error => nil, :row? => false, :keyword => 'Given', :format => 'formatted yes'
48
+ )
49
+ formatter.step_passed(step, nil, nil)
50
+ io.string.should == " Given formatted yes\n"
51
+ end
52
+
53
+ describe "scenario without any steps" do
54
+ before :each do
55
+ @io = StringIO.new
56
+ @formatter = PrettyFormatter.new(@io, StepMother.new)
57
+ @scenario = mock_scenario(:name => "title", :pending? => true)
58
+ end
59
+
60
+ it "should display as pending when executing" do
61
+ @formatter.should_receive(:pending).with(" Scenario: title")
62
+ @formatter.scenario_executing(@scenario)
63
+ end
64
+
65
+ it "should display as pending in the dump" do
66
+ @formatter.scenario_executing(@scenario)
67
+ @formatter.dump
68
+ @io.string.should include("1 scenarios pending")
69
+ end
70
+ end
71
+
72
+ it "should put a line between last row scenario and new scenario" do
73
+ io = StringIO.new
74
+ formatter = PrettyFormatter.new io, mock('step_mother'), :source => true
75
+ scenario = mock_scenario(:row? => true)
76
+
77
+ formatter.scenario_executing(scenario)
78
+ formatter.scenario_executed(scenario)
79
+ formatter.scenario_executing(mock_scenario(:name => 'spacey', :row? => false))
80
+
81
+ io.string.should =~ /\n\n Scenario: spacey/
82
+ end
83
+
84
+ {'should' => true, 'should not' => false}.each do |should_or_should_not, show_snippet|
85
+ describe "snippets option #{show_snippet}" do
86
+
87
+ it "#{should_or_should_not} show snippet for pending step" do
88
+ @io = StringIO.new
89
+ step_mother = mock('step_mother', :has_step_definition? => false)
90
+ @formatter = PrettyFormatter.new @io, step_mother, :snippets => show_snippet
91
+
92
+ @formatter.step_pending(mock_step(:actual_keyword => 'Given', :name => 'pending step snippet'), nil, nil)
93
+ @formatter.dump
94
+
95
+ @io.string.send(should_or_should_not.gsub(' ','_').to_sym, include("Given /^pending step snippet$/ do"))
96
+ end
97
+
98
+ end
99
+ end
100
+
101
+ it "should escape snippets which have special regular expression characters" do
102
+ @io = StringIO.new
103
+ step_mother = mock('step_mother', :has_step_definition? => false)
104
+ @formatter = PrettyFormatter.new @io, step_mother, :snippets => true
105
+
106
+ @formatter.step_pending(mock_step(:actual_keyword => 'Given', :name => "$1 millon /'s"), nil, nil)
107
+ @formatter.dump
108
+
109
+ @io.string.should include("Given /^\\$1 millon \\/'s$/ do")
110
+ end
111
+
112
+ it "should not show the snippet for a step which already has a step definition" do
113
+ @io = StringIO.new
114
+ step_mother = mock('step_mother', :has_step_definition? => true)
115
+ @formatter = PrettyFormatter.new @io, step_mother, :snippets => true
116
+
117
+ @formatter.step_pending(mock_step(:actual_keyword => 'Given', :name => 'pending step snippet'), nil, nil)
118
+ @formatter.dump
119
+
120
+ @io.string.should_not include("Given /^pending step snippet$/ do")
121
+ end
122
+
123
+ describe "show source option true" do
124
+
125
+ before(:each) do
126
+ @io = StringIO.new
127
+ step_mother = mock('step_mother')
128
+ @formatter = PrettyFormatter.new @io, step_mother, :source => true
129
+ end
130
+
131
+ %w{passed failed skipped}.each do |result|
132
+ it "should display step source for #{result} step" do
133
+ @formatter.send("step_#{result}".to_sym, mock_step(:regexp_args_proc => [nil, nil, mock_proc], :error => StandardError.new, :padding_length => 2), nil, nil)
134
+
135
+ @io.string.should include("Given formatted yes # steps/example_steps.rb:11")
136
+ end
137
+ end
138
+
139
+ it "should display feature file and line for pending step" do
140
+ @formatter.step_pending(mock_step(:name => 'test', :file => 'features/example.feature', :line => 5, :padding_length => 2), nil, nil)
141
+
142
+ @io.string.should include("Given test # features/example.feature:5")
143
+ end
144
+
145
+ it "should display file and line for scenario" do
146
+ @formatter.scenario_executing(mock_scenario(:name => "title", :file => 'features/example.feature', :line => 2 , :padding_length => 2, :pending? => false))
147
+
148
+ @io.string.should include("Scenario: title # features/example.feature:2")
149
+ end
150
+
151
+ it "should display file for feature" do
152
+ @formatter.feature_executing(mock_feature(:file => 'features/example.feature', :padding_length => 2))
153
+ @formatter.header_executing("Feature: test\n In order to ...\n As a ...\n I want to ...\n")
154
+
155
+ @io.string.should include("Feature: test # features/example.feature\n")
156
+ @io.string.should include("In order to ...\n")
157
+ @io.string.should include("As a ...\n")
158
+ @io.string.should include("I want to ...\n")
159
+ end
160
+
161
+ it "should align step comments" do
162
+ step_1 = mock_step(:regexp_args_proc => [nil, nil, mock_proc], :format => "1", :padding_length => 10)
163
+ step_4 = mock_step(:regexp_args_proc => [nil, nil, mock_proc], :format => "4444", :padding_length => 7)
164
+ step_9 = mock_step(:regexp_args_proc => [nil, nil, mock_proc], :format => "999999999", :padding_length => 2)
165
+
166
+ @formatter.step_passed(step_1, nil, nil)
167
+ @formatter.step_passed(step_4, nil, nil)
168
+ @formatter.step_passed(step_9, nil, nil)
169
+
170
+ @io.string.should include("Given 1 # steps/example_steps.rb:11")
171
+ @io.string.should include("Given 4444 # steps/example_steps.rb:11")
172
+ @io.string.should include("Given 999999999 # steps/example_steps.rb:11")
173
+ end
174
+
175
+ it "should align step comments with respect to their scenario's comment" do
176
+ step = mock_step(:regexp_args_proc => [nil, nil, mock_proc], :error => StandardError.new, :padding_length => 6)
177
+
178
+ @formatter.scenario_executing(mock_scenario(:name => "very long title", :file => 'features/example.feature', :line => 5, :steps => [step], :padding_length => 2, :pending? => false))
179
+ @formatter.step_passed(step, nil, nil)
180
+
181
+ @io.string.should include("Scenario: very long title # features/example.feature:5")
182
+ @io.string.should include(" Given formatted yes # steps/example_steps.rb:11")
183
+ end
184
+
185
+ end
186
+
187
+ it "should reset the column count correctly" do
188
+ io = StringIO.new
189
+ formatter = PrettyFormatter.new io, mock('step_mother'), :source => true
190
+
191
+ large_scenario = mock_scenario(:row? => false, :table_column_widths => [3,3,5,4,4], :table_header => %w(one two three four five))
192
+ formatter.scenario_executing(large_scenario)
193
+ formatter.scenario_executed(large_scenario)
194
+
195
+ small_scenario = mock_scenario(:row? => false, :table_column_widths => [3,3], :table_header => %w(one two))
196
+ formatter.scenario_executing(small_scenario)
197
+ lambda {
198
+ formatter.scenario_executed(small_scenario)
199
+ }.should_not raise_error(TypeError)
200
+ end
201
+
202
+ end
203
+ end
204
+ end
@@ -0,0 +1,192 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ module Cucumber
4
+ module Formatters
5
+ describe ProfileFormatter do
6
+ attr_reader :io, :formatter
7
+
8
+ def mock_proc(stubs={})
9
+ stub(Proc, {:to_comment_line => '# steps/example_steps.rb:11'}.merge(stubs))
10
+ end
11
+
12
+ def mock_step(stubs={})
13
+ stub('step', {:keyword => 'Given',
14
+ :actual_keyword => 'Given',
15
+ :format => 'test',
16
+ :row? => false,
17
+ :file => 'test.feature',
18
+ :line => 5,
19
+ :regexp_args_proc => [nil, nil, mock_proc]}.merge(stubs))
20
+ end
21
+
22
+ before(:each) do
23
+ @io = StringIO.new
24
+ step_mother = stub('step_mother')
25
+ @formatter = ProfileFormatter.new(io, step_mother)
26
+ end
27
+
28
+ it "should print a heading" do
29
+ formatter.visit_features(nil)
30
+
31
+ io.string.should eql("Profiling enabled.\n")
32
+ end
33
+
34
+ it "should record the current time when starting a new step" do
35
+ now = Time.now
36
+ Time.stub!(:now).and_return(now)
37
+ formatter.step_executing('should foo', nil, nil)
38
+
39
+ formatter.instance_variable_get("@step_time").should == now
40
+ end
41
+
42
+ describe "grouping recorded passed steps" do
43
+
44
+ before(:each) do
45
+ now = Time.now
46
+ formatter.instance_variable_set("@step_time", now)
47
+ Time.stub!(:now).and_return(now, now)
48
+ end
49
+
50
+ it "should group by regular expressions and actual keyword" do
51
+ step_1 = mock_step(:actual_keyword => 'Given')
52
+ step_2 = mock_step(:actual_keyword => 'Given')
53
+
54
+ formatter.step_passed(step_1, /nihon/, nil)
55
+ formatter.step_passed(step_2, /ichiban/, nil)
56
+
57
+ step_times = formatter.instance_variable_get("@step_times")
58
+
59
+ step_times.has_key?('Given /nihon/').should be_true
60
+ step_times.has_key?('Given /ichiban/').should be_true
61
+ end
62
+
63
+ it "should use a previous step's keyword when recording row steps" do
64
+ step = mock_step(:actual_keyword => 'Given')
65
+ step_row = mock_step(:row? => true)
66
+
67
+ formatter.step_passed(step, /nihon/, [])
68
+ formatter.step_passed(step_row, /nihon/, [])
69
+
70
+ step_times = formatter.instance_variable_get("@step_times")
71
+
72
+ step_times['Given /nihon/'].length.should == 2
73
+ end
74
+
75
+ end
76
+
77
+ it "should correctly record a passed step" do
78
+ formatter.step_executing(nil, nil, nil)
79
+ formatter.step_passed(mock_step(:format => 'she doth teach the torches to burn bright', :actual_keyword => 'Given'), nil, nil)
80
+ formatter.dump
81
+
82
+ io.string.should include('Given she doth teach the torches to burn bright')
83
+ end
84
+
85
+ it "should correctly record a passed step row" do
86
+ formatter.step_executing(nil, nil, nil)
87
+ formatter.step_passed(mock_step(:row? => true), /example/, ['fitty'])
88
+ formatter.dump
89
+
90
+ io.string.should include('fitty')
91
+ end
92
+
93
+ it "should calculate the mean step execution time" do
94
+ now = Time.now
95
+ Time.stub!(:now).and_return(now, now+5, now, now+1)
96
+
97
+ 2.times do
98
+ formatter.step_executing(mock_step, nil, nil)
99
+ formatter.step_passed(mock_step, nil, nil)
100
+ end
101
+
102
+ formatter.dump
103
+
104
+ io.string.should include('3.0000000')
105
+ end
106
+
107
+ it "should display file and line comment for step invocation" do
108
+ step = mock_step(:format => 'test', :actual_keyword => 'Given', :file => 'test.feature', :line => 5)
109
+
110
+ formatter.step_executing(step, nil, nil)
111
+ formatter.step_passed(step, nil, nil)
112
+ formatter.dump
113
+
114
+ @io.string.should include("# test.feature:5")
115
+ end
116
+
117
+ it "should display file and line comment for step definition" do
118
+ step = mock_step(:format => 'test', :actual_keyword => 'Given',
119
+ :regexp_args_proc => [/test/, nil, mock_proc(:to_comment_line => '# steps/example_steps.rb:11')])
120
+
121
+ formatter.step_executing(step, nil, nil)
122
+ formatter.step_passed(step, nil, nil)
123
+ formatter.dump
124
+
125
+ @io.string.should include("# steps/example_steps.rb:11")
126
+ end
127
+
128
+ it "should show the performance times of the step invocations for a step definition" do
129
+ now = Time.now
130
+ Time.stub!(:now).and_return(now, now+5, now, now+1)
131
+
132
+ step = mock_step(:format => 'step invocation', :actual_keyword => 'Given')
133
+
134
+ 2.times do
135
+ formatter.step_executing(step, /example/, nil)
136
+ formatter.step_passed(step, /example/, nil)
137
+ end
138
+
139
+ formatter.dump
140
+
141
+ io.string.should include("3.0000000 Given /example/")
142
+ io.string.should include("5.0000000 Given step invocation")
143
+ io.string.should include("1.0000000 Given step invocation")
144
+ end
145
+
146
+ it "should sort the step invocations in descending order" do
147
+ now = Time.now
148
+ Time.stub!(:now).and_return(now, now+1, now, now+5)
149
+
150
+ step = mock_step(:format => 'step invocation', :actual_keyword => 'Given')
151
+
152
+ 2.times do
153
+ formatter.step_executing(step, /example 1/, nil)
154
+ formatter.step_passed(step, /example 1/, nil)
155
+ end
156
+
157
+ formatter.dump
158
+ io_string_lines = io.string.split("\n")
159
+
160
+ io_string_lines.at(-2).should include('5.0000000')
161
+ io_string_lines.at(-1).should include('1.0000000')
162
+ end
163
+
164
+ it "should print the top average 10 step results" do
165
+ formatter.instance_variable_set("@step_time", Time.now)
166
+
167
+ 11.times do |test_number|
168
+ step_regexp = Regexp.new "unique_test_#{test_number}"
169
+ formatter.step_passed(mock_step(:format => 'test', :actual_keyword => 'Given',
170
+ :regexp_args_proc => [step_regexp, nil, mock_proc]), step_regexp, nil)
171
+ end
172
+
173
+ formatter.dump
174
+
175
+ io.string.scan(/unique_test_\d+/).length.should == 10
176
+ end
177
+
178
+ it "should print the top 5 step invocations for step definition" do
179
+ formatter.instance_variable_set("@step_time", Time.now)
180
+
181
+ 10.times do |test_number|
182
+ formatter.step_passed(mock_step(:format => 'please invocate me', :actual_keyword => 'Given'), nil, nil)
183
+ end
184
+
185
+ formatter.dump
186
+
187
+ io.string.scan(/please invocate me/).length.should == 5
188
+ end
189
+
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,65 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ module Cucumber
4
+ module Formatters
5
+ describe ProgressFormatter do
6
+ it "should print . when passed" do
7
+ io = StringIO.new
8
+ formatter = ProgressFormatter.new io
9
+ step = stub('step',
10
+ :error => nil
11
+ )
12
+ formatter.step_passed(step,nil,nil)
13
+ io.string.should =~ /^\.$/
14
+ end
15
+
16
+ it "should print F when failed" do
17
+ io = StringIO.new
18
+ formatter = ProgressFormatter.new io
19
+ step = stub('step',
20
+ :error => StandardError.new
21
+ )
22
+ formatter.step_failed(step,nil,nil)
23
+ io.string.should =~ /^\F$/
24
+ end
25
+
26
+ it "should print P when pending" do
27
+ io = StringIO.new
28
+ formatter = ProgressFormatter.new io
29
+ step = stub('step',
30
+ :error => Pending.new,
31
+ :scenario => mock('scenario')
32
+ )
33
+ formatter.step_pending(step,nil,nil)
34
+ io.string.should =~ /^\P$/
35
+ end
36
+
37
+ it "should print _ when skipped" do
38
+ io = StringIO.new
39
+ formatter = ProgressFormatter.new io
40
+ formatter.step_skipped(nil,nil,nil)
41
+ io.string.should =~ /^_$/
42
+ end
43
+
44
+ describe "scenario without any steps" do
45
+ before :each do
46
+ @io = StringIO.new
47
+ @formatter = ProgressFormatter.new(@io)
48
+ @feature = stub("feature", :header => "Feature Header")
49
+ @scenario = stub("scenario", :feature => @feature, :name => "Scenario Title", :row? => false, :pending? => true)
50
+ end
51
+
52
+ it "should print a P when executing" do
53
+ @formatter.should_receive(:pending).with("P")
54
+ @formatter.scenario_executing(@scenario)
55
+ end
56
+
57
+ it "should display as pending in the dump" do
58
+ @formatter.scenario_executing(@scenario)
59
+ @formatter.dump
60
+ @io.string.should include("Feature Header (Scenario Title)")
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ module Cucumber
4
+ module Model
5
+ describe Table do
6
+ it "should convert into hash-array" do
7
+ raw = [
8
+ %w{name gender},
9
+ %w{aslak male},
10
+ %w{patty female},
11
+ ]
12
+ ha = Table.new(raw).hashes
13
+ ha.should == [
14
+ {'name' => 'aslak', 'gender' => 'male'},
15
+ {'name' => 'patty', 'gender' => 'female'}
16
+ ]
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ # Define some stubs to fake Rails...
2
+ module ActiveRecord
3
+ class Base
4
+ end
5
+ end
6
+
7
+ module ActionController
8
+ class Base
9
+ end
10
+ class IntegrationTest
11
+ def self.use_transactional_fixtures=(x)
12
+ end
13
+ end
14
+ end
15
+
16
+ module Dispatcher
17
+ end
@@ -0,0 +1 @@
1
+ # This file is loaded by rails/world.rb
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ $:.unshift(File.dirname(__FILE__) + '/stubs')
3
+
4
+ describe "Rails world" do
5
+
6
+ it "should run without Test::Unit.run defined" do
7
+ require "mini_rails"
8
+ require "cucumber/rails/world"
9
+ end
10
+
11
+ end
@@ -0,0 +1,19 @@
1
+ Feature: Sell cucumbers
2
+ As a cucumber farmer
3
+ I want to sell cucumbers
4
+ So that I buy meat
5
+
6
+ Scenario: Sell a dozen
7
+ Given there are 5 cucumbers
8
+ When I sell 12 cucumbers
9
+ Then I should owe 7 cucumbers
10
+
11
+ Scenario: Sell twenty
12
+ Given there are 5 cucumbers
13
+ When I sell 20 cucumbers
14
+ Then I should owe 15 cucumbers
15
+
16
+ Scenario: Sell fifty
17
+ Given there are 5 cucumbers
18
+ When I sell 50 cucumbers
19
+ Then I should owe 45 cucumbers
@@ -0,0 +1,74 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module Cucumber
4
+ describe StepMother do
5
+ it "should report file and line numbers for both duplicate step definitions" do
6
+ m = StepMother.new
7
+
8
+ m.register_step_proc /Three (.*) mice/ do |disability|
9
+ end
10
+
11
+ begin
12
+ m.register_step_proc /Three (.*) mice/ do |disability|
13
+ end
14
+ violated("Should raise error")
15
+ rescue => e
16
+ e.message.should =~ %r{Duplicate step definitions:.+step_mother_spec\.rb:8:in `/Three \(\.\*\) mice/'.+step_mother_spec\.rb\:12:in `/Three \(\.\*\) mice/'}m
17
+
18
+ end
19
+ end
20
+
21
+ it "should report file and line numbers for multiple step definitions" do
22
+ m = StepMother.new
23
+
24
+ m.register_step_proc /Three (.*) mice/ do |disability|
25
+ end
26
+
27
+ m.register_step_proc /Three blind (.*)/ do |animal|
28
+ end
29
+
30
+ begin
31
+ m.regexp_args_proc('Three blind mice')
32
+ violated("Should raise error")
33
+ rescue => e
34
+ e.message.should =~ %r{Multiple step definitions match "Three blind mice":
35
+
36
+ .+step_mother_spec\.rb:24:in `/Three \(\.\*\) mice/'
37
+ .+step_mother_spec\.rb:27:in `/Three blind \(\.\*\)/'
38
+
39
+ }m
40
+ end
41
+ end
42
+
43
+ it "should mark step as pending when it doesn't match any procs" do
44
+ pending "think some more about what to expect here" do
45
+ m = StepMother.new
46
+ step = mock('step')
47
+ step.should_receive(:pending!)
48
+ raise "FIXME"
49
+ m.execute(step)
50
+ end
51
+ end
52
+
53
+ it "should report that a step has a definition if the step is registered" do
54
+ m = StepMother.new
55
+ m.register_step_proc /I am a real step definition/ do end
56
+
57
+ m.has_step_definition?('I am a real step definition').should be_true
58
+ end
59
+
60
+ it "should report that a step does not have a definition if it has not been registered" do
61
+ m = StepMother.new
62
+
63
+ m.has_step_definition?('I am a step without a definition').should be_false
64
+ end
65
+
66
+ it "should explain to the programmer that step definitions always need a proc" do
67
+ m = StepMother.new
68
+ lambda do
69
+ m.register_step_proc(/no milk today/)
70
+ end.should raise_error(MissingProc, "Step definitions must always have a proc")
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ module Cucumber
4
+ module Tree
5
+ describe Feature do
6
+
7
+ it "should have padding_length 2 when alone" do
8
+ feature = Feature.new('header')
9
+ feature.padding_length.should == 2
10
+ end
11
+
12
+ describe "creating a Scenario" do
13
+
14
+ it "should create a new scenario for a feature" do
15
+ feature = Feature.new('header')
16
+
17
+ Scenario.should_receive(:new).with(feature, 'test scenario', "19")
18
+
19
+ feature.Scenario('test scenario') {}
20
+ end
21
+
22
+ end
23
+
24
+ describe "creating a Table" do
25
+
26
+ it "should set the table header of the template scenario" do
27
+ feature = Feature.new('header')
28
+ mock_scenario = mock("scenario", :update_table_column_widths => nil)
29
+ Scenario.stub!(:new).and_return(mock_scenario)
30
+ feature.add_scenario('scenario', 5)
31
+
32
+ mock_scenario.should_receive(:table_header=).with(["input_1", "input_2"])
33
+
34
+ feature.Table do |t|
35
+ t | "input_1" | "input_2" | t
36
+ t | 1 | 2 | t
37
+ end
38
+ end
39
+
40
+ end
41
+ end
42
+ end
43
+ end