aslakhellesoy-cucumber 0.1.99.4 → 0.1.99.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (254) hide show
  1. data/History.txt +4 -1
  2. data/Manifest.txt +2 -10
  3. data/cucumber.yml +1 -0
  4. data/examples/cs/README.textile +1 -0
  5. data/examples/cs/Rakefile +12 -0
  6. data/examples/cs/compile.bat +1 -0
  7. data/examples/cs/features/addition.feature +16 -0
  8. data/examples/cs/features/step_definitons/calculator_steps.rb +19 -0
  9. data/examples/cs/src/demo/Calculator.cs +20 -0
  10. data/examples/dos_line_endings/Rakefile +6 -0
  11. data/examples/dos_line_endings/features/dos_line_endings.feature +9 -0
  12. data/examples/i18n/README.textile +18 -0
  13. data/examples/i18n/Rakefile +32 -0
  14. data/examples/i18n/ar/Rakefile +6 -0
  15. data/examples/i18n/ar/features/addition.feature +17 -0
  16. data/examples/i18n/ar/features/step_definitons/calculator_steps.rb +28 -0
  17. data/examples/i18n/ar/lib/calculator.rb +10 -0
  18. data/examples/i18n/da/Rakefile +6 -0
  19. data/examples/i18n/da/features/step_definitons/kalkulator_steps.rb +24 -0
  20. data/examples/i18n/da/features/summering.feature +17 -0
  21. data/examples/i18n/da/lib/kalkulator.rb +11 -0
  22. data/examples/i18n/de/Rakefile +6 -0
  23. data/examples/i18n/de/features/addition.feature +16 -0
  24. data/examples/i18n/de/features/division.feature +9 -0
  25. data/examples/i18n/de/features/step_definitons/calculator_steps.rb +24 -0
  26. data/examples/i18n/de/lib/calculator.rb +14 -0
  27. data/examples/i18n/en/Rakefile +6 -0
  28. data/examples/i18n/en/features/addition.feature +16 -0
  29. data/examples/i18n/en/features/division.feature +9 -0
  30. data/examples/i18n/en/features/step_definitons/calculator_steps.rb +24 -0
  31. data/examples/i18n/en/lib/calculator.rb +14 -0
  32. data/examples/i18n/es/Rakefile +6 -0
  33. data/examples/i18n/es/features/adicion.feature +17 -0
  34. data/examples/i18n/es/features/step_definitons/calculador_steps.rb +24 -0
  35. data/examples/i18n/es/lib/calculador.rb +11 -0
  36. data/examples/i18n/et/Rakefile +6 -0
  37. data/examples/i18n/et/features/liitmine.feature +17 -0
  38. data/examples/i18n/et/features/step_definitions/kalkulaator_steps.rb +24 -0
  39. data/examples/i18n/et/lib/kalkulaator.rb +10 -0
  40. data/examples/i18n/fi/Rakefile +6 -0
  41. data/examples/i18n/fi/features/jakolasku.feature +9 -0
  42. data/examples/i18n/fi/features/step_definitons/laskin_steps.rb +24 -0
  43. data/examples/i18n/fi/features/yhteenlasku.feature +16 -0
  44. data/examples/i18n/fi/lib/laskin.rb +14 -0
  45. data/examples/i18n/fr/Rakefile +6 -0
  46. data/examples/i18n/fr/features/addition.feature +15 -0
  47. data/examples/i18n/fr/features/step_definitions/calculatrice_steps.rb +27 -0
  48. data/examples/i18n/fr/lib/calculatrice.rb +10 -0
  49. data/examples/i18n/id/Rakefile +6 -0
  50. data/examples/i18n/id/features/addition.feature +16 -0
  51. data/examples/i18n/id/features/division.feature +9 -0
  52. data/examples/i18n/id/features/step_definitons/calculator_steps.rb +24 -0
  53. data/examples/i18n/id/lib/calculator.rb +14 -0
  54. data/examples/i18n/it/Rakefile +6 -0
  55. data/examples/i18n/it/features/somma.feature +10 -0
  56. data/examples/i18n/it/features/step_definitons/calcolatrice_steps.rb +24 -0
  57. data/examples/i18n/it/lib/calcolatrice.rb +11 -0
  58. data/examples/i18n/ja/README.txt +5 -0
  59. data/examples/i18n/ja/Rakefile +6 -0
  60. data/examples/i18n/ja/features/addition.feature +16 -0
  61. data/examples/i18n/ja/features/division.feature +9 -0
  62. data/examples/i18n/ja/features/step_definitons/calculator_steps.rb +24 -0
  63. data/examples/i18n/ja/lib/calculator.rb +14 -0
  64. data/examples/i18n/ko/Rakefile +6 -0
  65. data/examples/i18n/ko/features/addition.feature +16 -0
  66. data/examples/i18n/ko/features/division.feature +10 -0
  67. data/examples/i18n/ko/features/step_definitons/calculator_steps.rb +24 -0
  68. data/examples/i18n/ko/lib/calculator.rb +14 -0
  69. data/examples/i18n/lt/Rakefile +6 -0
  70. data/examples/i18n/lt/features/addition.feature +17 -0
  71. data/examples/i18n/lt/features/division.feature +9 -0
  72. data/examples/i18n/lt/features/step_definitons/calculator_steps.rb +24 -0
  73. data/examples/i18n/lt/lib/calculator.rb +14 -0
  74. data/examples/i18n/no/Rakefile +6 -0
  75. data/examples/i18n/no/features/step_definitons/kalkulator_steps.rb +24 -0
  76. data/examples/i18n/no/features/summering.feature +18 -0
  77. data/examples/i18n/no/lib/kalkulator.rb +11 -0
  78. data/examples/i18n/pt/Rakefile +6 -0
  79. data/examples/i18n/pt/features/adicao.feature +10 -0
  80. data/examples/i18n/pt/features/step_definitions/calculadora_steps.rb +24 -0
  81. data/examples/i18n/pt/lib/calculadora.rb +10 -0
  82. data/examples/i18n/ro/Rakefile +6 -0
  83. data/examples/i18n/ro/features/step_definitons/calculator_steps.rb +24 -0
  84. data/examples/i18n/ro/features/suma.feature +10 -0
  85. data/examples/i18n/ro/lib/calculator.rb +11 -0
  86. data/examples/i18n/se/Rakefile +6 -0
  87. data/examples/i18n/se/features/step_definitons/kalkulator_steps.rb +24 -0
  88. data/examples/i18n/se/features/summering.feature +17 -0
  89. data/examples/i18n/se/lib/kalkulator.rb +11 -0
  90. data/examples/i18n/zh-CN/Rakefile +6 -0
  91. data/examples/i18n/zh-CN/features/addition.feature +17 -0
  92. data/examples/i18n/zh-CN/features/step_definitons/calculator_steps.rb +26 -0
  93. data/examples/i18n/zh-CN/lib/calculator.rb +10 -0
  94. data/examples/java/README.textile +22 -0
  95. data/examples/java/Rakefile +12 -0
  96. data/examples/java/features/hello.feature +11 -0
  97. data/examples/java/features/step_definitons/hello_steps.rb +25 -0
  98. data/examples/java/features/step_definitons/tree_steps.rb +14 -0
  99. data/examples/java/features/tree.feature +9 -0
  100. data/examples/java/src/cucumber/demo/Hello.java +16 -0
  101. data/examples/jbehave/README.textile +17 -0
  102. data/examples/jbehave/features/support/env.rb +7 -0
  103. data/examples/jbehave/features/trading.feature +24 -0
  104. data/examples/jbehave/pom.xml +48 -0
  105. data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/converters/TraderConverter.java +32 -0
  106. data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/model/Stock.java +42 -0
  107. data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/model/Trader.java +29 -0
  108. data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/persistence/TraderPersister.java +22 -0
  109. data/examples/jbehave/src/main/java/cukes/jbehave/examples/trader/scenarios/TraderSteps.java +65 -0
  110. data/examples/selenium/Rakefile +6 -0
  111. data/examples/selenium/features/search.feature +9 -0
  112. data/examples/selenium/features/step_definitons/stories_steps.rb +40 -0
  113. data/examples/self_test/README.textile +6 -0
  114. data/examples/self_test/features/call_undefined_step_from_step_def.feature +7 -0
  115. data/examples/self_test/features/lots_of_undefined.feature +8 -0
  116. data/examples/self_test/features/outline_sample.feature +15 -0
  117. data/examples/self_test/features/sample.feature +16 -0
  118. data/examples/self_test/features/step_definitions/sample_steps.rb +25 -0
  119. data/examples/test_unit/Rakefile +6 -0
  120. data/examples/test_unit/features/step_definitions/test_unit_steps.rb +26 -0
  121. data/examples/test_unit/features/test_unit.feature +9 -0
  122. data/examples/tickets/Rakefile +11 -0
  123. data/examples/tickets/cucumber.yml +2 -0
  124. data/examples/tickets/features/lib/eatting_machine.rb +18 -0
  125. data/examples/tickets/features/lib/pantry.rb +20 -0
  126. data/examples/tickets/features/scenario_outline.feature +95 -0
  127. data/examples/tickets/features/step_definitons/scenario_outline_steps.rb +42 -0
  128. data/examples/tickets/features/step_definitons/tickets_steps.rb +60 -0
  129. data/examples/tickets/features/tickets.feature +28 -0
  130. data/examples/watir/README.textile +16 -0
  131. data/examples/watir/Rakefile +6 -0
  132. data/examples/watir/features/search.feature +9 -0
  133. data/examples/watir/features/step_definitons/search_steps.rb +24 -0
  134. data/examples/watir/features/support/env.rb +32 -0
  135. data/features/cucumber_cli.feature +331 -0
  136. data/features/cucumber_cli_outlines.feature +90 -0
  137. data/features/report_called_undefined_steps.feature +32 -0
  138. data/features/step_definitions/cucumber_steps.rb +31 -0
  139. data/features/step_definitions/extra_steps.rb +2 -0
  140. data/features/support/env.rb +7 -0
  141. data/gem_tasks/deployment.rake +11 -0
  142. data/gem_tasks/environment.rake +7 -0
  143. data/gem_tasks/features.rake +6 -0
  144. data/gem_tasks/fix_cr_lf.rake +10 -0
  145. data/gem_tasks/flog.rake +4 -0
  146. data/gem_tasks/gemspec.rake +10 -0
  147. data/gem_tasks/rspec.rake +35 -0
  148. data/gem_tasks/yard.rake +8 -0
  149. data/lib/autotest/cucumber.rb +6 -0
  150. data/lib/autotest/cucumber_mixin.rb +124 -0
  151. data/lib/autotest/cucumber_rails.rb +6 -0
  152. data/lib/autotest/cucumber_rails_rspec.rb +6 -0
  153. data/lib/autotest/cucumber_rspec.rb +6 -0
  154. data/lib/autotest/discover.rb +9 -0
  155. data/lib/cucumber.rb +72 -0
  156. data/lib/cucumber/ast.rb +27 -0
  157. data/lib/cucumber/ast/comment.rb +26 -0
  158. data/lib/cucumber/ast/examples.rb +22 -0
  159. data/lib/cucumber/ast/feature.rb +60 -0
  160. data/lib/cucumber/ast/features.rb +39 -0
  161. data/lib/cucumber/ast/filter.rb +22 -0
  162. data/lib/cucumber/ast/outline_table.rb +49 -0
  163. data/lib/cucumber/ast/py_string.rb +52 -0
  164. data/lib/cucumber/ast/scenario.rb +95 -0
  165. data/lib/cucumber/ast/scenario_outline.rb +83 -0
  166. data/lib/cucumber/ast/step.rb +139 -0
  167. data/lib/cucumber/ast/table.rb +214 -0
  168. data/lib/cucumber/ast/tags.rb +33 -0
  169. data/lib/cucumber/ast/visitor.rb +93 -0
  170. data/lib/cucumber/broadcaster.rb +15 -0
  171. data/lib/cucumber/cli.rb +414 -0
  172. data/lib/cucumber/core_ext/exception.rb +53 -0
  173. data/lib/cucumber/core_ext/instance_exec.rb +54 -0
  174. data/lib/cucumber/core_ext/proc.rb +33 -0
  175. data/lib/cucumber/core_ext/string.rb +48 -0
  176. data/lib/cucumber/formatter.rb +1 -0
  177. data/lib/cucumber/formatter/ansicolor.rb +106 -0
  178. data/lib/cucumber/formatter/console.rb +116 -0
  179. data/lib/cucumber/formatter/pretty.rb +158 -0
  180. data/lib/cucumber/formatter/profile.rb +77 -0
  181. data/lib/cucumber/formatter/progress.rb +68 -0
  182. data/lib/cucumber/formatter/rerun.rb +35 -0
  183. data/lib/cucumber/formatters/unicode.rb +2 -0
  184. data/lib/cucumber/jbehave.rb +104 -0
  185. data/lib/cucumber/languages.yml +314 -0
  186. data/lib/cucumber/parser.rb +24 -0
  187. data/lib/cucumber/parser/basic.rb +0 -0
  188. data/lib/cucumber/parser/feature.rb +1351 -0
  189. data/lib/cucumber/parser/feature.tt +160 -0
  190. data/lib/cucumber/parser/i18n.tt +27 -0
  191. data/lib/cucumber/parser/table.rb +396 -0
  192. data/lib/cucumber/parser/table.tt +53 -0
  193. data/lib/cucumber/parser/treetop_ext.rb +67 -0
  194. data/lib/cucumber/platform.rb +18 -0
  195. data/lib/cucumber/rails/rspec.rb +5 -0
  196. data/lib/cucumber/rails/world.rb +73 -0
  197. data/lib/cucumber/rake/task.rb +106 -0
  198. data/lib/cucumber/step_definition.rb +87 -0
  199. data/lib/cucumber/step_mother.rb +164 -0
  200. data/lib/cucumber/version.rb +10 -0
  201. data/pretty.txt +486 -0
  202. data/rails_generators/cucumber/USAGE +11 -0
  203. data/rails_generators/cucumber/cucumber_generator.rb +31 -0
  204. data/rails_generators/cucumber/templates/cucumber +8 -0
  205. data/rails_generators/cucumber/templates/cucumber.rake +7 -0
  206. data/rails_generators/cucumber/templates/env.rb +16 -0
  207. data/rails_generators/cucumber/templates/paths.rb +12 -0
  208. data/rails_generators/cucumber/templates/webrat_steps.rb +99 -0
  209. data/rails_generators/feature/USAGE +12 -0
  210. data/rails_generators/feature/feature_generator.rb +36 -0
  211. data/rails_generators/feature/templates/feature.erb +31 -0
  212. data/rails_generators/feature/templates/steps.erb +24 -0
  213. data/spec/cucumber/ast/feature_factory.rb +54 -0
  214. data/spec/cucumber/ast/feature_spec.rb +60 -0
  215. data/spec/cucumber/ast/py_string_spec.rb +40 -0
  216. data/spec/cucumber/ast/scenario_outline_spec.rb +64 -0
  217. data/spec/cucumber/ast/scenario_spec.rb +82 -0
  218. data/spec/cucumber/ast/step_spec.rb +45 -0
  219. data/spec/cucumber/ast/table_spec.rb +81 -0
  220. data/spec/cucumber/broadcaster_spec.rb +14 -0
  221. data/spec/cucumber/cli_spec.rb +416 -0
  222. data/spec/cucumber/core_ext/proc_spec.rb +37 -0
  223. data/spec/cucumber/core_ext/string_spec.rb +42 -0
  224. data/spec/cucumber/formatter/ansicolor_spec.rb +35 -0
  225. data/spec/cucumber/formatter/html/cucumber.css +37 -0
  226. data/spec/cucumber/formatter/html/cucumber.js +13 -0
  227. data/spec/cucumber/formatter/html/index.html +45 -0
  228. data/spec/cucumber/formatter/html/jquery-1.3.min.js +19 -0
  229. data/spec/cucumber/formatter/html/jquery.uitableedit.js +100 -0
  230. data/spec/cucumber/formatters/profile_formatter_spec.rb +198 -0
  231. data/spec/cucumber/parser/feature_parser_spec.rb +247 -0
  232. data/spec/cucumber/parser/table_parser_spec.rb +48 -0
  233. data/spec/cucumber/rails/stubs/mini_rails.rb +18 -0
  234. data/spec/cucumber/rails/stubs/test_help.rb +1 -0
  235. data/spec/cucumber/rails/world_spec.rb +11 -0
  236. data/spec/cucumber/sell_cucumbers.feature +19 -0
  237. data/spec/cucumber/step_definition_spec.rb +62 -0
  238. data/spec/cucumber/treetop_parser/empty_feature.feature +4 -0
  239. data/spec/cucumber/treetop_parser/empty_scenario.feature +9 -0
  240. data/spec/cucumber/treetop_parser/empty_scenario_outline.feature +3 -0
  241. data/spec/cucumber/treetop_parser/fit_scenario.feature +8 -0
  242. data/spec/cucumber/treetop_parser/given_scenario.feature +9 -0
  243. data/spec/cucumber/treetop_parser/invalid_scenario_outlines.feature +7 -0
  244. data/spec/cucumber/treetop_parser/multiline_steps.feature +17 -0
  245. data/spec/cucumber/treetop_parser/multiple_tables.feature +27 -0
  246. data/spec/cucumber/treetop_parser/scenario_outline.feature +16 -0
  247. data/spec/cucumber/treetop_parser/spaces.feature +12 -0
  248. data/spec/cucumber/treetop_parser/test_dos.feature +25 -0
  249. data/spec/cucumber/treetop_parser/with_comments.feature +10 -0
  250. data/spec/cucumber/treetop_parser/with_tags.feature +18 -0
  251. data/spec/cucumber/world/pending_spec.rb +47 -0
  252. data/spec/spec.opts +2 -0
  253. data/spec/spec_helper.rb +21 -0
  254. metadata +7 -1
@@ -0,0 +1,64 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'cucumber/step_mother'
3
+ require 'cucumber/ast'
4
+ require 'cucumber/core_ext/string'
5
+
6
+ module Cucumber
7
+ module Ast
8
+ describe ScenarioOutline do
9
+ before do
10
+ @step_mother = Object.new
11
+ @step_mother.extend(StepMother)
12
+ @step_mother.Given(/^there are (\d+) cucumbers$/) do |n|
13
+ @initial = n.to_i
14
+ end
15
+ @step_mother.When(/^I eat (\d+) cucumbers$/) do |n|
16
+ @eaten = n.to_i
17
+ end
18
+ @step_mother.Then(/^I should have (\d+) cucumbers$/) do |n|
19
+ (@initial - @eaten).should == n.to_i
20
+ end
21
+ @step_mother.Then(/^I should have (\d+) cucumbers in my belly$/) do |n|
22
+ @eaten.should == n.to_i
23
+ end
24
+
25
+ @scenario_outline = ScenarioOutline.new(
26
+ Comment.new(""),
27
+ Tags.new(18, []),
28
+ 19,
29
+ "Scenario:", "My outline",
30
+ [
31
+ Step.new(20, 'Given', 'there are <start> cucumbers'),
32
+ Step.new(21, 'When', 'I eat <eat> cucumbers'),
33
+ Step.new(22, 'Then', 'I should have <left> cucumbers'),
34
+ Step.new(23, 'And', 'I should have <eat> cucumbers in my belly')
35
+ ],
36
+ [
37
+ [
38
+ 24,
39
+ 'Examples:',
40
+ 'First table',
41
+ [
42
+ %w{start eat left},
43
+ %w{12 5 7},
44
+ %w{20 6 14}
45
+ ]
46
+ ]
47
+ ]
48
+ )
49
+ end
50
+
51
+ it "should replace all variables and call outline once for each table row" do
52
+ visitor = Visitor.new(@step_mother)
53
+ visitor.should_receive(:visit_table_row).exactly(3).times
54
+ visitor.visit_feature_element(@scenario_outline)
55
+ end
56
+
57
+ it "should pretty print" do
58
+ require 'cucumber/formatter/pretty'
59
+ visitor = Formatter::Pretty.new(@step_mother, STDOUT, {:source => true})
60
+ visitor.visit_feature_element(@scenario_outline)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,82 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'cucumber/step_mother'
3
+ require 'cucumber/ast'
4
+
5
+ module Cucumber
6
+ module Ast
7
+ describe Scenario do
8
+ before do
9
+ @step_mother = Object.new
10
+ @step_mother.extend(StepMother)
11
+ $x = $y = nil
12
+ @step_mother.Before do
13
+ $x = 3
14
+ end
15
+ @step_mother.Given /y is (\d+)/ do |n|
16
+ $y = n.to_i
17
+ end
18
+ @visitor = Visitor.new(@step_mother)
19
+ @visitor.options = {}
20
+ end
21
+
22
+ it "should execute Before blocks before steps" do
23
+ scenario = Scenario.new(
24
+ comment=Comment.new(""),
25
+ tags=Tags.new(98,[]),
26
+ line=99,
27
+ keyword="",
28
+ name="",
29
+ steps=[
30
+ Step.new(7, "Given", "y is 5")
31
+ ])
32
+ @visitor.visit_feature_element(scenario)
33
+ $x.should == 3
34
+ $y.should == 5
35
+ end
36
+
37
+ it "should skip steps when previous is not passed" do
38
+ scenario = Scenario.new(
39
+ comment=Comment.new(""),
40
+ tags=Tags.new(98, []),
41
+ line=99,
42
+ keyword="",
43
+ name="",
44
+ steps=[
45
+ Step.new(7, "Given", "this is missing"),
46
+ Step.new(8, "Given", "y is 5")
47
+ ])
48
+ @visitor.visit_feature_element(scenario)
49
+
50
+ $x.should == 3
51
+ $y.should == nil
52
+ end
53
+
54
+ it "should be at exact line" do
55
+ s = Scenario.new(comment=Comment.new(""),
56
+ tags=Tags.new(44, []), 45, keyword="", name="", steps=[])
57
+
58
+ s.should be_at_lines([44])
59
+ s.should be_at_lines([45])
60
+ end
61
+
62
+ it "should be at line if tags or steps are" do
63
+ s = Scenario.new(
64
+ comment=Comment.new(""),
65
+ tags=Tags.new(43, []),
66
+ line=45,
67
+ keyword="",
68
+ name="",
69
+ steps=[
70
+ Step.new(46, "Given", ""),
71
+ Step.new(47, "Given", ""),
72
+ Step.new(48, "Given", ""),
73
+ ]
74
+ )
75
+
76
+ s.should be_at_lines([43])
77
+ s.should be_at_lines([47])
78
+ s.should_not be_at_lines([49])
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'cucumber/step_mother'
3
+ require 'cucumber/ast'
4
+ require 'cucumber/core_ext/string'
5
+
6
+ module Cucumber
7
+ module Ast
8
+ describe StepMother do
9
+ it "should calculate comment padding" do
10
+ scenario = Scenario.new(comment=nil, tags=nil, line=nil, keyword='Given', name='Gazpacho', steps=[
11
+ Step.new(22, "Given", "tøtal 13"),
12
+ Step.new(23, "And", "the total 15")
13
+ ])
14
+ step1, step2 = *scenario.instance_variable_get('@steps')
15
+
16
+ step1.source_indent.should == 2
17
+ step2.source_indent.should == 0
18
+ end
19
+ end
20
+
21
+ describe Step do
22
+ describe "execute step with arguments" do
23
+
24
+ it "should replace arguments in multiline args" do
25
+ mock_multiline_arg = mock('multiline arg')
26
+ step = Step.new(23, 'Given', '<test>', mock_multiline_arg)
27
+
28
+ mock_multiline_arg.should_receive(:arguments_replaced).with({'<test>' => '10'}).and_return(mock_multiline_arg)
29
+
30
+ step.execute_with_arguments({'test' => '10'}, stub('world'), :passed, visitor=nil, line=-1)
31
+ end
32
+
33
+ it "should invoke step with replaced multiline args" do
34
+ mock_step_definition = mock('step definition')
35
+ mock_multiline_arg_replaced = mock('multiline arg replaced')
36
+ mock_multiline_arg = mock('multiline arg', :arguments_replaced => mock_multiline_arg_replaced)
37
+ step = Step.new(45, 'Given', '<test>', mock_multiline_arg)
38
+
39
+ step.execute_with_arguments({'test' => '10'}, stub('world'), :passed, visitor=nil, line=-1)
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,81 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'cucumber/ast/table'
3
+
4
+ module Cucumber
5
+ module Ast
6
+ describe Table do
7
+ before do
8
+ @table = Table.new([
9
+ %w{1 22 333},
10
+ %w{4444 55555 666666}
11
+ ])
12
+ @table.extend(Module.new{
13
+ attr_reader :raw
14
+ })
15
+ def @table.rows; super; end
16
+ def @table.columns; super; end
17
+ end
18
+
19
+ it "should have rows" do
20
+ @table.rows[0].map{|cell| cell.value}.should == %w{1 22 333}
21
+ end
22
+
23
+ it "should have columns" do
24
+ @table.columns[1].map{|cell| cell.value}.should == %w{22 55555}
25
+ end
26
+
27
+ it "should have same cell objects in rows and columns" do
28
+ # 666666
29
+ @table.rows[1].__send__(:[], 2).should equal(@table.columns[2].__send__(:[], 1))
30
+ end
31
+
32
+ it "should know about max width of a row" do
33
+ @table.columns[1].__send__(:width).should == 5
34
+ end
35
+
36
+ it "should be convertible to an array of hashes" do
37
+ @table.hashes.should == [
38
+ {'1' => '4444', '22' => '55555', '333' => '666666'}
39
+ ]
40
+ end
41
+
42
+ describe "replacing arguments" do
43
+
44
+ before(:each) do
45
+ @table = table = Table.new([
46
+ %w{qty book},
47
+ %w{<qty> <book>}
48
+ ])
49
+ end
50
+
51
+ it "should return a new table with arguments replaced with values" do
52
+ table_with_replaced_args = @table.arguments_replaced({'<book>' => 'Unbearable lightness of being', '<qty>' => '5'})
53
+
54
+ table_with_replaced_args.hashes[0]['book'].should == 'Unbearable lightness of being'
55
+ table_with_replaced_args.hashes[0]['qty'].should == '5'
56
+ end
57
+
58
+ it "should not change the original table" do
59
+ table_with_replaced_args = @table.arguments_replaced({'<book>' => 'Unbearable lightness of being'})
60
+
61
+ @table.hashes[0]['book'].should_not == 'Unbearable lightness of being'
62
+ end
63
+
64
+ end
65
+
66
+ it "should convert to sexp" do
67
+ @table.to_sexp.should ==
68
+ [:table,
69
+ [:row,
70
+ [:cell, "1"],
71
+ [:cell, "22"],
72
+ [:cell, "333"]
73
+ ],
74
+ [:row,
75
+ [:cell, "4444"],
76
+ [:cell, "55555"],
77
+ [:cell, "666666"]]]
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,14 @@
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
+ receiver = mock('receiver')
8
+ broadcaster = Broadcaster.new([receiver])
9
+
10
+ receiver.should_receive(:konbanwa).with('good evening')
11
+ broadcaster.konbanwa('good evening')
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,416 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'yaml'
3
+
4
+ module Cucumber
5
+ describe CLI do
6
+
7
+ def mock_executor(stubs = {})
8
+ stub('executor', {:visit_features => nil, :lines_for_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
+ def mock_features(stubs ={})
16
+ stub('features', {:<< => nil}.merge(stubs))
17
+ end
18
+
19
+ before(:each) do
20
+ Kernel.stub!(:exit).and_return(nil)
21
+ end
22
+
23
+ def given_cucumber_yml_defined_as(hash_or_string)
24
+ File.stub!(:exist?).and_return(true)
25
+ cucumber_yml = hash_or_string.is_a?(Hash) ? hash_or_string.to_yaml : hash_or_string
26
+ IO.stub!(:read).with('cucumber.yml').and_return(cucumber_yml)
27
+ end
28
+
29
+ it "should expand args from YAML file" do
30
+ cli = CLI.new
31
+
32
+ given_cucumber_yml_defined_as({'bongo' => '--require from/yml'})
33
+
34
+ cli.parse_options!(%w{--format progress --profile bongo})
35
+ cli.options[:formats].should == {'progress' => STDOUT}
36
+ cli.options[:require].should == ['from/yml']
37
+ end
38
+
39
+ it "should expand args from YAML file's default if there are no args" do
40
+ cli = CLI.new
41
+
42
+ given_cucumber_yml_defined_as({'default' => '--require from/yml'})
43
+
44
+ cli.parse_options!([])
45
+ cli.options[:require].should == ['from/yml']
46
+ end
47
+
48
+ it "should provide a helpful error message when a specified profile does not exists in YAML file" do
49
+ cli = CLI.new(StringIO.new, error = StringIO.new)
50
+
51
+ given_cucumber_yml_defined_as({'default' => '--require from/yml', 'html_report' => '--format html'})
52
+
53
+ cli.parse_options!(%w{--profile i_do_not_exist})
54
+
55
+ expected_message = <<-END_OF_MESSAGE
56
+ Could not find profile: 'i_do_not_exist'
57
+
58
+ Defined profiles in cucumber.yml:
59
+ * default
60
+ * html_report
61
+ END_OF_MESSAGE
62
+
63
+ error.string.should == expected_message
64
+ end
65
+
66
+ it "should provide a helpful error message when a specified profile is not a String" do
67
+ cli = CLI.new(StringIO.new, error = StringIO.new)
68
+
69
+ given_cucumber_yml_defined_as({'foo' => [1,2,3]})
70
+
71
+ cli.parse_options!(%w{--profile foo})
72
+
73
+ error.string.should == "Profiles must be defined as a String. The 'foo' profile was [1, 2, 3] (Array).\n"
74
+ end
75
+
76
+ it "should provide a helpful error message when a specified profile exists but is nil or blank" do
77
+ [nil, ' '].each do |bad_input|
78
+ cli = CLI.new(StringIO.new, error = StringIO.new)
79
+
80
+ given_cucumber_yml_defined_as({'foo' => bad_input})
81
+
82
+ cli.parse_options!(%w{--profile foo})
83
+
84
+ error.string.should match(/The 'foo' profile in cucumber.yml was blank. Please define the command line arguments for the 'foo' profile in cucumber.yml./)
85
+ end
86
+ end
87
+
88
+ it "should provide a helpful error message when no YAML file exists and a profile is specified" do
89
+ cli = CLI.new(StringIO.new, error = StringIO.new)
90
+
91
+ File.should_receive(:exist?).with('cucumber.yml').and_return(false)
92
+
93
+ cli.parse_options!(%w{--profile i_do_not_exist})
94
+
95
+ error.string.should match(/cucumber.yml was not found. Please refer to cucumber's documentaion on defining profiles in cucumber.yml./)
96
+ end
97
+
98
+ it "should provide a helpful error message when cucumber.yml is blank or malformed" do
99
+ expected_error_message = /cucumber.yml was found, but was blank or malformed. Please refer to cucumber's documentaion on correct profile usage./
100
+
101
+ ['', 'sfsadfs', "--- \n- an\n- array\n", "---dddfd"].each do |bad_input|
102
+ cli = CLI.new(StringIO.new, error = StringIO.new)
103
+
104
+ given_cucumber_yml_defined_as(bad_input)
105
+ cli.parse_options!([])
106
+
107
+ error.string.should match(expected_error_message)
108
+ end
109
+ end
110
+
111
+ it "should procide a helpful error message when the YAML can not be parsed" do
112
+ expected_error_message = /cucumber.yml was found, but could not be parsed. Please refer to cucumber's documentaion on correct profile usage./
113
+ cli = CLI.new(StringIO.new, error = StringIO.new)
114
+
115
+ given_cucumber_yml_defined_as("input that causes an exception in YAML loading")
116
+ YAML.should_receive(:load).and_raise Exception
117
+
118
+ cli.parse_options!([])
119
+
120
+ error.string.should match(expected_error_message)
121
+ end
122
+
123
+ it "should accept --dry-run option" do
124
+ cli = CLI.new(StringIO.new)
125
+ cli.parse_options!(%w{--dry-run})
126
+ cli.options[:dry_run].should be_true
127
+ cli.execute!(stub('step mother'))
128
+ end
129
+
130
+ it "should accept --no-source option" do
131
+ cli = CLI.new
132
+ cli.parse_options!(%w{--no-source})
133
+
134
+ cli.options[:source].should be_false
135
+ end
136
+
137
+ it "should accept --no-snippets option" do
138
+ cli = CLI.new
139
+ cli.parse_options!(%w{--no-snippets})
140
+
141
+ cli.options[:snippets].should be_false
142
+ end
143
+
144
+ it "should set snippets and source to false with --quiet option" do
145
+ cli = CLI.new
146
+ cli.parse_options!(%w{--quiet})
147
+
148
+ cli.options[:snippets].should be_nil
149
+ cli.options[:source].should be_nil
150
+ end
151
+
152
+ it "should accept --verbose option" do
153
+ cli = CLI.new
154
+ cli.parse_options!(%w{--verbose})
155
+
156
+ cli.options[:verbose].should be_true
157
+ end
158
+
159
+ it "should require files in support paths first" do
160
+ File.stub!(:directory?).and_return(true)
161
+ Dir.stub!(:[]).and_return(["/features/step_definitions/foo.rb","/features/support/env.rb"])
162
+
163
+ cli = CLI.new(StringIO.new)
164
+ cli.parse_options!(%w{--require /features})
165
+
166
+ cli.should_receive(:require).with("/features/support/env.rb").ordered
167
+ cli.should_receive(:require).with("/features/step_definitions/foo.rb").ordered
168
+ cli.should_receive(:require).with("spec/expectations/differs/default").ordered
169
+
170
+ cli.execute!(stub('step mother'))
171
+ end
172
+
173
+ describe "verbose mode" do
174
+
175
+ before(:each) do
176
+ @out = StringIO.new
177
+ @cli = CLI.new(@out)
178
+ @cli.stub!(:require)
179
+ @empty_feature = Ast::Feature.new(Ast::Comment.new(''), Ast::Tags.new(2, []), "Feature", [])
180
+ Dir.stub!(:[])
181
+ end
182
+
183
+ it "should show ruby files required" do
184
+ @cli.parse_options!(%w{--verbose --require example.rb})
185
+ @cli.execute!(stub('step mother'))
186
+
187
+ @out.string.should include('example.rb')
188
+ end
189
+
190
+ it "should show feature files parsed" do
191
+ Parser::FeatureParser.stub!(:new).and_return(mock("feature parser", :parse_file => @empty_feature))
192
+
193
+ @cli.parse_options!(%w{--verbose example.feature})
194
+ @cli.execute!(stub('step mother'))
195
+
196
+ @out.string.should include('example.feature')
197
+ end
198
+
199
+ end
200
+
201
+ it "should accept --out option" do
202
+ cli = CLI.new(StringIO.new)
203
+ cli.parse_options!(%w{--out jalla.txt})
204
+ cli.options[:formats]['pretty'].should == 'jalla.txt'
205
+ end
206
+
207
+ it "should accept multiple --out options" do
208
+ cli = CLI.new(StringIO.new)
209
+ cli.parse_options!(%w{--format progress --out file1 --out file2})
210
+ cli.options[:formats].should == {'progress' => 'file2'}
211
+ end
212
+
213
+ it "should accept multiple --format options" do
214
+ cli = CLI.new(StringIO.new)
215
+ cli.parse_options!(%w{--format pretty --format progress})
216
+ cli.options[:formats].should have_key('pretty')
217
+ cli.options[:formats].should have_key('progress')
218
+ end
219
+
220
+ it "should associate --out to previous --format" do
221
+ cli = CLI.new(StringIO.new)
222
+ cli.parse_options!(%w{--format progress --out file1 --format profile --out file2})
223
+ cli.options[:formats].should == {"profile"=>"file2", "progress"=>"file1"}
224
+ end
225
+
226
+ describe "--format with class" do
227
+
228
+ describe "in module" do
229
+
230
+ it "should resolve each module until it gets Formatter class" do
231
+ cli = CLI.new(nil)
232
+ mock_module = mock('module')
233
+ cli.parse_options!(%w{--format ZooModule::MonkeyFormatterClass})
234
+ Object.stub!(:const_defined?).and_return(true)
235
+ mock_module.stub!(:const_defined?).and_return(true)
236
+
237
+ f = stub('formatter', :null_object => true)
238
+
239
+ Object.should_receive(:const_get).with('ZooModule').and_return(mock_module)
240
+ mock_module.should_receive(:const_get).with('MonkeyFormatterClass').and_return(mock('formatter class', :new => f))
241
+
242
+ cli.execute!(stub('step mother'))
243
+ end
244
+
245
+ end
246
+
247
+ describe "exists and valid constructor" do
248
+
249
+ before(:each) do
250
+ @mock_formatter_class = mock('formatter class')
251
+ Object.stub!(:const_get).and_return(@mock_formatter_class)
252
+ Object.stub!(:const_defined?).with('magical').and_return(true)
253
+ end
254
+
255
+ xit "should create the formatter" do
256
+ cli = CLI.new
257
+ mock_formatter = mock('magical formatter')
258
+ cli.parse_options!(%w{--format magical})
259
+
260
+ @mock_formatter_class.should_receive(:new)
261
+
262
+ cli.execute!(stub('step mother'), mock_executor, stub('features'))
263
+ end
264
+
265
+ xit "should register the formatter with broadcaster" do
266
+ cli = CLI.new
267
+ broadcaster = Broadcaster.new
268
+ mock_formatter = mock('magical formatter')
269
+ Broadcaster.stub!(:new).and_return(broadcaster, stub("output broadcaster", :register => nil))
270
+ @mock_formatter_class.stub!(:new).and_return(mock_formatter)
271
+ cli.parse_options!(%w{--format magical})
272
+
273
+ broadcaster.should_receive(:register).with(mock_formatter)
274
+
275
+ cli.execute!(stub('step mother'), mock_executor, stub('features'))
276
+ end
277
+
278
+ end
279
+
280
+ describe "exists but invalid constructor" do
281
+
282
+ before(:each) do
283
+ @out = StringIO.new
284
+ @error = StringIO.new
285
+ @cli = CLI.new(@out, @error)
286
+
287
+ mock_formatter_class = stub('formatter class')
288
+ mock_formatter_class.stub!(:new).and_raise("No such method")
289
+ Object.stub!(:const_get).and_return(mock_formatter_class)
290
+ Object.stub!(:const_defined?).with('exists_but_evil').and_return(true)
291
+
292
+ @cli.parse_options!(%w{--format exists_but_evil})
293
+ end
294
+
295
+ xit "should show exception" do
296
+ Kernel.stub!(:exit)
297
+
298
+ @cli.execute!(stub('step mother'))
299
+
300
+ @error.string.should include("No such method")
301
+ end
302
+
303
+ xit "should exit" do
304
+ Kernel.should_receive(:exit)
305
+
306
+ @cli.execute!(stub('step mother'), mock_executor, stub('features'))
307
+ end
308
+
309
+ end
310
+
311
+ describe "non-existent" do
312
+
313
+ before(:each) do
314
+ @out = StringIO.new
315
+ @error = StringIO.new
316
+ @cli = CLI.new(@out, @error)
317
+
318
+ @cli.parse_options!(%w{--format invalid})
319
+ end
320
+
321
+ xit "should display a format error" do
322
+ Kernel.stub!(:exit)
323
+
324
+ @cli.execute!(stub('step mother'), mock_executor, stub('features'))
325
+
326
+ @error.string.should include("Invalid format: invalid\n")
327
+ end
328
+
329
+ xit "should display --help" do
330
+ Kernel.stub!(:exit)
331
+
332
+ @cli.execute!(stub('step mother'))
333
+
334
+ @out.string.should include("Usage: cucumber")
335
+ end
336
+
337
+ xit "should exit" do
338
+ Kernel.should_receive(:exit)
339
+
340
+ @cli.execute!(stub('step mother'), mock_executor, stub('features'))
341
+ end
342
+
343
+ end
344
+
345
+ end
346
+
347
+ it "should accept multiple --scenario options" do
348
+ cli = CLI.new
349
+ cli.parse_options!(['--scenario', "User logs in", '--scenario', "User signs up"])
350
+ cli.options[:scenario_names].should include("User logs in")
351
+ cli.options[:scenario_names].should include("User signs up")
352
+ end
353
+
354
+ xit "should register --scenario options with the executor" do
355
+ cli = CLI.new
356
+ cli.parse_options!(['--scenario', "User logs in", '--scenario', "User signs up"])
357
+ executor = mock_executor
358
+ executor.should_receive(:scenario_names=).with(["User logs in", "User signs up"])
359
+ cli.execute!(stub('step mother'), executor, stub('features'))
360
+ end
361
+
362
+ it "should accept --color option" do
363
+ cli = CLI.new(StringIO.new)
364
+ Term::ANSIColor.should_receive(:coloring=).with(true)
365
+ cli.parse_options!(['--color'])
366
+ end
367
+
368
+ it "should accept --no-color option" do
369
+ cli = CLI.new(StringIO.new)
370
+ Term::ANSIColor.should_receive(:coloring=).with(false)
371
+ cli.parse_options!(['--no-color'])
372
+ end
373
+
374
+ describe "--backtrace" do
375
+ before do
376
+ Exception.cucumber_full_backtrace = false
377
+ end
378
+
379
+ it "should show full backtrace when --backtrace is present" do
380
+ cli = CLI.new
381
+ cli.parse_options!(['--backtrace'])
382
+ begin
383
+ "x".should == "y"
384
+ rescue => e
385
+ e.backtrace[0].should_not == "#{__FILE__}:#{__LINE__ - 2}"
386
+ end
387
+ end
388
+
389
+ xit "should strip gems when --backtrace is absent" do
390
+ cli = CLI.new
391
+ cli.parse_options!(['--'])
392
+ begin
393
+ "x".should == "y"
394
+ rescue => e
395
+ e.backtrace[0].should == "#{__FILE__}:#{__LINE__ - 2}"
396
+ end
397
+ end
398
+
399
+ after do
400
+ Exception.cucumber_full_backtrace = false
401
+ end
402
+ end
403
+
404
+ it "should search for all features in the specified directory" do
405
+ cli = CLI.new(StringIO.new)
406
+
407
+ cli.parse_options!(%w{feature_directory/})
408
+ File.stub!(:directory?).and_return(true)
409
+
410
+ Dir.should_receive(:[]).with("feature_directory/**/*.feature").any_number_of_times.and_return([])
411
+
412
+ cli.execute!(stub('step mother'))
413
+ end
414
+
415
+ end
416
+ end