bts-cucumber 0.1.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (241) hide show
  1. data/History.txt +297 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +240 -0
  4. data/README.txt +4 -0
  5. data/Rakefile +8 -0
  6. data/bin/cucumber +6 -0
  7. data/config/hoe.rb +69 -0
  8. data/config/requirements.rb +15 -0
  9. data/cucumber.yml +1 -0
  10. data/examples/calculator_ruby_features/Rakefile +6 -0
  11. data/examples/calculator_ruby_features/features/addition.rb +23 -0
  12. data/examples/calculator_ruby_features/features/step_definitons/calculator_steps.rb +43 -0
  13. data/examples/cs/README.textile +1 -0
  14. data/examples/cs/Rakefile +12 -0
  15. data/examples/cs/compile.bat +1 -0
  16. data/examples/cs/features/addition.feature +17 -0
  17. data/examples/cs/features/step_definitons/calculator_steps.rb +23 -0
  18. data/examples/cs/src/demo/Calculator.cs +20 -0
  19. data/examples/dos_line_endings/Rakefile +6 -0
  20. data/examples/dos_line_endings/features/dos_line_endings.feature +9 -0
  21. data/examples/i18n/README.textile +18 -0
  22. data/examples/i18n/Rakefile +16 -0
  23. data/examples/i18n/ar/Rakefile +6 -0
  24. data/examples/i18n/ar/features/addition.feature +17 -0
  25. data/examples/i18n/ar/features/step_definitons/calculator_steps.rb +32 -0
  26. data/examples/i18n/ar/lib/calculator.rb +10 -0
  27. data/examples/i18n/da/Rakefile +6 -0
  28. data/examples/i18n/da/features/step_definitons/kalkulator_steps.rb +22 -0
  29. data/examples/i18n/da/features/summering.feature +17 -0
  30. data/examples/i18n/da/lib/kalkulator.rb +11 -0
  31. data/examples/i18n/de/Rakefile +6 -0
  32. data/examples/i18n/de/features/addition.feature +17 -0
  33. data/examples/i18n/de/features/division.feature +10 -0
  34. data/examples/i18n/de/features/step_definitons/calculator_steps.rb +30 -0
  35. data/examples/i18n/de/lib/calculator.rb +14 -0
  36. data/examples/i18n/en/Rakefile +6 -0
  37. data/examples/i18n/en/features/addition.feature +17 -0
  38. data/examples/i18n/en/features/division.feature +10 -0
  39. data/examples/i18n/en/features/step_definitons/calculator_steps.rb +26 -0
  40. data/examples/i18n/en/lib/calculator.rb +14 -0
  41. data/examples/i18n/es/Rakefile +6 -0
  42. data/examples/i18n/es/features/adicion.feature +17 -0
  43. data/examples/i18n/es/features/step_definitons/calculador_steps.rb +22 -0
  44. data/examples/i18n/es/lib/calculador.rb +11 -0
  45. data/examples/i18n/et/Rakefile +6 -0
  46. data/examples/i18n/et/features/liitmine.feature +17 -0
  47. data/examples/i18n/et/features/step_definitions/kalkulaator_steps.rb +26 -0
  48. data/examples/i18n/et/lib/kalkulaator.rb +10 -0
  49. data/examples/i18n/fr/Rakefile +6 -0
  50. data/examples/i18n/fr/features/addition.feature +13 -0
  51. data/examples/i18n/fr/features/step_definitions/calculatrice_steps.rb +22 -0
  52. data/examples/i18n/fr/lib/calculatrice.rb +10 -0
  53. data/examples/i18n/id/Rakefile +6 -0
  54. data/examples/i18n/id/features/addition.feature +17 -0
  55. data/examples/i18n/id/features/division.feature +10 -0
  56. data/examples/i18n/id/features/step_definitons/calculator_steps.rb +31 -0
  57. data/examples/i18n/id/lib/calculator.rb +14 -0
  58. data/examples/i18n/it/Rakefile +6 -0
  59. data/examples/i18n/it/features/somma.feature +10 -0
  60. data/examples/i18n/it/features/step_definitons/calcolatrice_steps.rb +22 -0
  61. data/examples/i18n/it/lib/calcolatrice.rb +11 -0
  62. data/examples/i18n/ja/README.txt +5 -0
  63. data/examples/i18n/ja/Rakefile +6 -0
  64. data/examples/i18n/ja/features/addition.feature +17 -0
  65. data/examples/i18n/ja/features/division.feature +10 -0
  66. data/examples/i18n/ja/features/step_definitons/calculator_steps.rb +30 -0
  67. data/examples/i18n/ja/lib/calculator.rb +14 -0
  68. data/examples/i18n/lt/Rakefile +6 -0
  69. data/examples/i18n/lt/features/addition.feature +17 -0
  70. data/examples/i18n/lt/features/division.feature +10 -0
  71. data/examples/i18n/lt/features/step_definitons/calculator_steps.rb +31 -0
  72. data/examples/i18n/lt/lib/calculator.rb +14 -0
  73. data/examples/i18n/no/Rakefile +6 -0
  74. data/examples/i18n/no/features/step_definitons/kalkulator_steps.rb +22 -0
  75. data/examples/i18n/no/features/summering.feature +17 -0
  76. data/examples/i18n/no/lib/kalkulator.rb +11 -0
  77. data/examples/i18n/pt/Rakefile +6 -0
  78. data/examples/i18n/pt/features/adicao.feature +10 -0
  79. data/examples/i18n/pt/features/step_definitions/calculadora_steps.rb +22 -0
  80. data/examples/i18n/pt/lib/calculadora.rb +10 -0
  81. data/examples/i18n/ro/Rakefile +6 -0
  82. data/examples/i18n/ro/features/step_definitons/calculator_steps.rb +22 -0
  83. data/examples/i18n/ro/features/suma.feature +10 -0
  84. data/examples/i18n/ro/lib/calculator.rb +11 -0
  85. data/examples/i18n/se/Rakefile +6 -0
  86. data/examples/i18n/se/features/step_definitons/kalkulator_steps.rb +22 -0
  87. data/examples/i18n/se/features/summering.feature +17 -0
  88. data/examples/i18n/se/lib/kalkulator.rb +11 -0
  89. data/examples/i18n/zh-CN/Rakefile +6 -0
  90. data/examples/i18n/zh-CN/features/addition.feature +17 -0
  91. data/examples/i18n/zh-CN/features/step_definitons/calculator_steps.rb +24 -0
  92. data/examples/i18n/zh-CN/lib/calculator.rb +10 -0
  93. data/examples/java/README.textile +22 -0
  94. data/examples/java/Rakefile +12 -0
  95. data/examples/java/features/hello.feature +11 -0
  96. data/examples/java/features/step_definitons/hello_steps.rb +25 -0
  97. data/examples/java/features/step_definitons/tree_steps.rb +14 -0
  98. data/examples/java/features/tree.feature +9 -0
  99. data/examples/java/src/cucumber/demo/Hello.java +16 -0
  100. data/examples/selenium/Rakefile +6 -0
  101. data/examples/selenium/features/search.feature +9 -0
  102. data/examples/selenium/features/step_definitons/stories_steps.rb +41 -0
  103. data/examples/test_unit/Rakefile +6 -0
  104. data/examples/test_unit/features/step_definitions/test_unit_steps.rb +26 -0
  105. data/examples/test_unit/features/test_unit.feature +9 -0
  106. data/examples/tickets/Rakefile +11 -0
  107. data/examples/tickets/cucumber.yml +2 -0
  108. data/examples/tickets/features/step_definitons/tickets_steps.rb +32 -0
  109. data/examples/tickets/features/tickets.feature +24 -0
  110. data/examples/watir/Rakefile +6 -0
  111. data/examples/watir/features/search.feature +9 -0
  112. data/examples/watir/features/step_definitons/stories_steps.rb +51 -0
  113. data/features/see_features.feature +8 -0
  114. data/features/steps/features_steps.rb +9 -0
  115. data/gem_tasks/deployment.rake +34 -0
  116. data/gem_tasks/environment.rake +7 -0
  117. data/gem_tasks/features.rake +6 -0
  118. data/gem_tasks/fix_cr_lf.rake +10 -0
  119. data/gem_tasks/flog.rake +4 -0
  120. data/gem_tasks/gemspec.rake +6 -0
  121. data/gem_tasks/rspec.rake +35 -0
  122. data/gem_tasks/treetop.rake +41 -0
  123. data/lib/autotest/cucumber.rb +6 -0
  124. data/lib/autotest/cucumber_mixin.rb +131 -0
  125. data/lib/autotest/cucumber_rails.rb +6 -0
  126. data/lib/autotest/cucumber_rails_rspec.rb +6 -0
  127. data/lib/autotest/cucumber_rspec.rb +6 -0
  128. data/lib/autotest/discover.rb +9 -0
  129. data/lib/cucumber/broadcaster.rb +20 -0
  130. data/lib/cucumber/cli.rb +346 -0
  131. data/lib/cucumber/core_ext/proc.rb +69 -0
  132. data/lib/cucumber/core_ext/string.rb +29 -0
  133. data/lib/cucumber/executor.rb +188 -0
  134. data/lib/cucumber/formatters/ansicolor.rb +109 -0
  135. data/lib/cucumber/formatters/autotest_formatter.rb +23 -0
  136. data/lib/cucumber/formatters/cucumber.css +132 -0
  137. data/lib/cucumber/formatters/cucumber.js +11 -0
  138. data/lib/cucumber/formatters/html_formatter.rb +128 -0
  139. data/lib/cucumber/formatters/jquery.js +32 -0
  140. data/lib/cucumber/formatters/pretty_formatter.rb +234 -0
  141. data/lib/cucumber/formatters/profile_formatter.rb +92 -0
  142. data/lib/cucumber/formatters/progress_formatter.rb +58 -0
  143. data/lib/cucumber/formatters.rb +1 -0
  144. data/lib/cucumber/languages.yml +258 -0
  145. data/lib/cucumber/model/table.rb +28 -0
  146. data/lib/cucumber/model.rb +1 -0
  147. data/lib/cucumber/platform.rb +10 -0
  148. data/lib/cucumber/rails/rspec.rb +12 -0
  149. data/lib/cucumber/rails/world.rb +73 -0
  150. data/lib/cucumber/rake/task.rb +101 -0
  151. data/lib/cucumber/step_methods.rb +49 -0
  152. data/lib/cucumber/step_mother.rb +95 -0
  153. data/lib/cucumber/tree/feature.rb +63 -0
  154. data/lib/cucumber/tree/features.rb +21 -0
  155. data/lib/cucumber/tree/given_scenario.rb +13 -0
  156. data/lib/cucumber/tree/scenario.rb +175 -0
  157. data/lib/cucumber/tree/step.rb +142 -0
  158. data/lib/cucumber/tree/table.rb +26 -0
  159. data/lib/cucumber/tree/top_down_visitor.rb +23 -0
  160. data/lib/cucumber/tree.rb +16 -0
  161. data/lib/cucumber/treetop_parser/feature.treetop.erb +206 -0
  162. data/lib/cucumber/treetop_parser/feature_ar.rb +1591 -0
  163. data/lib/cucumber/treetop_parser/feature_cy.rb +1591 -0
  164. data/lib/cucumber/treetop_parser/feature_da.rb +1591 -0
  165. data/lib/cucumber/treetop_parser/feature_de.rb +1591 -0
  166. data/lib/cucumber/treetop_parser/feature_en-lol.rb +1591 -0
  167. data/lib/cucumber/treetop_parser/feature_en-tx.rb +1591 -0
  168. data/lib/cucumber/treetop_parser/feature_en.rb +1591 -0
  169. data/lib/cucumber/treetop_parser/feature_es.rb +1591 -0
  170. data/lib/cucumber/treetop_parser/feature_et.rb +1591 -0
  171. data/lib/cucumber/treetop_parser/feature_fr.rb +1591 -0
  172. data/lib/cucumber/treetop_parser/feature_id.rb +1591 -0
  173. data/lib/cucumber/treetop_parser/feature_it.rb +1591 -0
  174. data/lib/cucumber/treetop_parser/feature_ja.rb +1591 -0
  175. data/lib/cucumber/treetop_parser/feature_lt.rb +1591 -0
  176. data/lib/cucumber/treetop_parser/feature_nl.rb +1591 -0
  177. data/lib/cucumber/treetop_parser/feature_no.rb +1591 -0
  178. data/lib/cucumber/treetop_parser/feature_parser.rb +34 -0
  179. data/lib/cucumber/treetop_parser/feature_pl.rb +1591 -0
  180. data/lib/cucumber/treetop_parser/feature_pt.rb +1591 -0
  181. data/lib/cucumber/treetop_parser/feature_ro.rb +1591 -0
  182. data/lib/cucumber/treetop_parser/feature_ro2.rb +1591 -0
  183. data/lib/cucumber/treetop_parser/feature_ru.rb +1591 -0
  184. data/lib/cucumber/treetop_parser/feature_se.rb +1591 -0
  185. data/lib/cucumber/treetop_parser/feature_zh-CN.rb +1591 -0
  186. data/lib/cucumber/version.rb +9 -0
  187. data/lib/cucumber.rb +38 -0
  188. data/rails_generators/cucumber/USAGE +11 -0
  189. data/rails_generators/cucumber/cucumber_generator.rb +30 -0
  190. data/rails_generators/cucumber/templates/cucumber +7 -0
  191. data/rails_generators/cucumber/templates/cucumber.rake +7 -0
  192. data/rails_generators/cucumber/templates/env.rb +11 -0
  193. data/rails_generators/cucumber/templates/webrat_steps.rb +93 -0
  194. data/rails_generators/feature/USAGE +12 -0
  195. data/rails_generators/feature/feature_generator.rb +16 -0
  196. data/rails_generators/feature/templates/feature.erb +28 -0
  197. data/rails_generators/feature/templates/steps.erb +22 -0
  198. data/script/console +10 -0
  199. data/script/console.cmd +1 -0
  200. data/script/destroy +14 -0
  201. data/script/destroy.cmd +1 -0
  202. data/script/generate +14 -0
  203. data/script/generate.cmd +1 -0
  204. data/script/txt2html +74 -0
  205. data/script/txt2html.cmd +1 -0
  206. data/setup.rb +1585 -0
  207. data/spec/cucumber/broadcaster_spec.rb +27 -0
  208. data/spec/cucumber/cli_spec.rb +468 -0
  209. data/spec/cucumber/core_ext/proc_spec.rb +45 -0
  210. data/spec/cucumber/core_ext/string_spec.rb +34 -0
  211. data/spec/cucumber/executor_spec.rb +298 -0
  212. data/spec/cucumber/formatters/ansicolor_spec.rb +35 -0
  213. data/spec/cucumber/formatters/autotest_formatter_spec.rb +26 -0
  214. data/spec/cucumber/formatters/features.html +269 -0
  215. data/spec/cucumber/formatters/html_formatter_spec.rb +74 -0
  216. data/spec/cucumber/formatters/pretty_formatter_spec.rb +204 -0
  217. data/spec/cucumber/formatters/profile_formatter_spec.rb +192 -0
  218. data/spec/cucumber/formatters/progress_formatter_spec.rb +65 -0
  219. data/spec/cucumber/model/table_spec.rb +20 -0
  220. data/spec/cucumber/rails/stubs/mini_rails.rb +17 -0
  221. data/spec/cucumber/rails/stubs/test_help.rb +1 -0
  222. data/spec/cucumber/rails/world_spec.rb +11 -0
  223. data/spec/cucumber/sell_cucumbers.feature +19 -0
  224. data/spec/cucumber/step_mother_spec.rb +74 -0
  225. data/spec/cucumber/tree/feature_spec.rb +43 -0
  226. data/spec/cucumber/tree/row_scenario_spec.rb +55 -0
  227. data/spec/cucumber/tree/scenario_spec.rb +76 -0
  228. data/spec/cucumber/tree/step_spec.rb +50 -0
  229. data/spec/cucumber/treetop_parser/empty_feature.feature +4 -0
  230. data/spec/cucumber/treetop_parser/empty_scenario.feature +9 -0
  231. data/spec/cucumber/treetop_parser/feature_parser_spec.rb +98 -0
  232. data/spec/cucumber/treetop_parser/fit_scenario.feature +8 -0
  233. data/spec/cucumber/treetop_parser/given_scenario.feature +9 -0
  234. data/spec/cucumber/treetop_parser/multiline_steps.feature +17 -0
  235. data/spec/cucumber/treetop_parser/multiple_tables.feature +29 -0
  236. data/spec/cucumber/treetop_parser/spaces.feature +10 -0
  237. data/spec/cucumber/treetop_parser/test_dos.feature +25 -0
  238. data/spec/cucumber/treetop_parser/with_comments.feature +10 -0
  239. data/spec/spec.opts +2 -0
  240. data/spec/spec_helper.rb +20 -0
  241. metadata +333 -0
@@ -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
@@ -0,0 +1,468 @@
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 --no-source option" do
124
+ cli = CLI.new
125
+ cli.parse_options!(%w{--no-source})
126
+
127
+ cli.options[:source].should be_false
128
+ end
129
+
130
+ it "should accept --no-snippets option" do
131
+ cli = CLI.new
132
+ cli.parse_options!(%w{--no-snippets})
133
+
134
+ cli.options[:snippets].should be_false
135
+ end
136
+
137
+ it "should accept --quiet option" do
138
+ cli = CLI.new
139
+ cli.parse_options!(%w{--quiet})
140
+
141
+ cli.options[:snippets].should be_false
142
+ cli.options[:source].should be_false
143
+ end
144
+
145
+ it "should accept --verbose option" do
146
+ cli = CLI.new
147
+ cli.parse_options!(%w{--verbose})
148
+
149
+ cli.options[:verbose].should be_true
150
+ end
151
+
152
+ describe "verbose mode" do
153
+
154
+ before(:each) do
155
+ @out = StringIO.new
156
+ @cli = CLI.new(@out)
157
+ @cli.stub!(:require)
158
+ Dir.stub!(:[])
159
+ end
160
+
161
+ it "should show ruby files required" do
162
+ @cli.parse_options!(%w{--verbose --require example.rb})
163
+ @cli.execute!(stub('step mother'), mock_executor, mock_features)
164
+
165
+ @out.string.should include('example.rb')
166
+ end
167
+
168
+ it "should show feature files parsed" do
169
+ TreetopParser::FeatureParser.stub!(:new).and_return(mock("feature parser", :parse_feature => nil))
170
+
171
+ @cli.parse_options!(%w{--verbose example.feature})
172
+ @cli.execute!(stub('step mother'), mock_executor, mock_features)
173
+
174
+ @out.string.should include('example.feature')
175
+ end
176
+
177
+ end
178
+
179
+ it "should accept --out option" do
180
+ cli = CLI.new
181
+ File.should_receive(:open).with('jalla.txt', 'w')
182
+ cli.parse_options!(%w{--out jalla.txt})
183
+ end
184
+
185
+ it "should accept multiple --out options" do
186
+ cli = CLI.new
187
+ mock_file1 = stub(File, :open => nil)
188
+ mock_file2 = stub(File, :open => nil)
189
+ File.stub!(:open).and_return(mock_file1, mock_file2)
190
+
191
+ cli.parse_options!(%w{--format progress --out file1 --out file2})
192
+ cli.options[:formats].should == {'progress' => [mock_file1, mock_file2]}
193
+ end
194
+
195
+ it "should accept multiple --format options" do
196
+ cli = CLI.new
197
+ cli.parse_options!(%w{--format pretty --format progress})
198
+ cli.options[:formats].should have_key('pretty')
199
+ cli.options[:formats].should have_key('progress')
200
+ end
201
+
202
+ it "should associate --out to previous --format" do
203
+ cli = CLI.new
204
+ mock_file1 = stub(File, :open => nil)
205
+ mock_file2 = stub(File, :open => nil)
206
+ File.stub!(:open).and_return(mock_file1, mock_file2)
207
+
208
+ cli.parse_options!(%w{--format progress --out file1 --format profile --out file2})
209
+ cli.options[:formats].should == {'progress' => [mock_file1], 'profile' => [mock_file2]}
210
+ end
211
+
212
+ it "should allow a single formatter to have STDOUT and a file" do
213
+ cli = CLI.new
214
+ mock_file = stub(File, :open => nil)
215
+ File.stub!(:open).and_return(mock_file)
216
+
217
+ cli.parse_options!(%w{--format progress --format progress --out file})
218
+ cli.options[:formats].should == {'progress' => [STDOUT, mock_file]}
219
+ end
220
+
221
+ it "should register --out files with an output broadcaster" do
222
+ cli = CLI.new
223
+ mock_file = stub(File)
224
+ File.stub!(:open).and_return(mock_file)
225
+ mock_output_broadcaster = mock_broadcaster
226
+ Broadcaster.stub!(:new).and_return(mock_broadcaster, mock_output_broadcaster)
227
+
228
+ mock_output_broadcaster.should_receive(:register).with(mock_file)
229
+ cli.parse_options!(%w{--out test.file})
230
+
231
+ cli.execute!(stub('step mother'), mock_executor, stub('features'))
232
+ end
233
+
234
+ it "should register --formatters with the formatter broadcaster" do
235
+ cli = CLI.new
236
+ mock_progress_formatter = stub(Formatters::ProgressFormatter)
237
+ Formatters::ProgressFormatter.stub!(:new).and_return(mock_progress_formatter)
238
+ mock_formatter_broadcaster = mock_broadcaster
239
+ Broadcaster.stub!(:new).and_return(mock_formatter_broadcaster, mock_broadcaster)
240
+
241
+ mock_formatter_broadcaster.should_receive(:register).with(mock_progress_formatter)
242
+ cli.parse_options!(%w{--format progress})
243
+
244
+ cli.execute!(stub('step mother'), mock_executor, stub('features'))
245
+ end
246
+
247
+ it "should setup the executor with the formatter broadcaster" do
248
+ cli = CLI.new
249
+ broadcaster = Broadcaster.new
250
+ Broadcaster.stub!(:new).and_return(broadcaster)
251
+ mock_executor = mock_executor()
252
+ mock_executor.should_receive(:formatters=).with(broadcaster)
253
+ cli.parse_options!(%w{--format progress})
254
+
255
+ cli.execute!(stub('step mother'), mock_executor, stub('features'))
256
+ end
257
+
258
+ describe "--format with class" do
259
+
260
+ describe "in module" do
261
+
262
+ it "should resolve each module until it gets Formatter class" do
263
+ cli = CLI.new
264
+ mock_module = mock('module')
265
+ cli.parse_options!(%w{--format ZooModule::MonkeyFormatterClass})
266
+ Object.stub!(:const_defined?).and_return(true)
267
+ mock_module.stub!(:const_defined?).and_return(true)
268
+
269
+ Object.should_receive(:const_get).with('ZooModule').and_return(mock_module)
270
+ mock_module.should_receive(:const_get).with('MonkeyFormatterClass').and_return(mock('formatter class', :new => nil))
271
+
272
+ cli.execute!(stub('step mother'), mock_executor, stub('features'))
273
+ end
274
+
275
+ end
276
+
277
+ describe "exists and valid constructor" do
278
+
279
+ before(:each) do
280
+ @mock_formatter_class = mock('formatter class')
281
+ Object.stub!(:const_get).and_return(@mock_formatter_class)
282
+ Object.stub!(:const_defined?).with('magical').and_return(true)
283
+ end
284
+
285
+ it "should create the formatter" do
286
+ cli = CLI.new
287
+ mock_formatter = mock('magical formatter')
288
+ cli.parse_options!(%w{--format magical})
289
+
290
+ @mock_formatter_class.should_receive(:new)
291
+
292
+ cli.execute!(stub('step mother'), mock_executor, stub('features'))
293
+ end
294
+
295
+ it "should register the formatter with broadcaster" do
296
+ cli = CLI.new
297
+ broadcaster = Broadcaster.new
298
+ mock_formatter = mock('magical formatter')
299
+ Broadcaster.stub!(:new).and_return(broadcaster, stub("output broadcaster", :register => nil))
300
+ @mock_formatter_class.stub!(:new).and_return(mock_formatter)
301
+ cli.parse_options!(%w{--format magical})
302
+
303
+ broadcaster.should_receive(:register).with(mock_formatter)
304
+
305
+ cli.execute!(stub('step mother'), mock_executor, stub('features'))
306
+ end
307
+
308
+ end
309
+
310
+ describe "exists but invalid constructor" do
311
+
312
+ before(:each) do
313
+ @out = StringIO.new
314
+ @error = StringIO.new
315
+ @cli = CLI.new(@out, @error)
316
+
317
+ mock_formatter_class = stub('formatter class')
318
+ mock_formatter_class.stub!(:new).and_raise("No such method")
319
+ Object.stub!(:const_get).and_return(mock_formatter_class)
320
+ Object.stub!(:const_defined?).with('exists_but_evil').and_return(true)
321
+
322
+ @cli.parse_options!(%w{--format exists_but_evil})
323
+ end
324
+
325
+ it "should show exception" do
326
+ Kernel.stub!(:exit)
327
+
328
+ @cli.execute!(stub('step mother'), mock_executor, stub('features'))
329
+
330
+ @error.string.should include("No such method")
331
+ end
332
+
333
+ it "should exit" do
334
+ Kernel.should_receive(:exit)
335
+
336
+ @cli.execute!(stub('step mother'), mock_executor, stub('features'))
337
+ end
338
+
339
+ end
340
+
341
+ describe "non-existent" do
342
+
343
+ before(:each) do
344
+ @out = StringIO.new
345
+ @error = StringIO.new
346
+ @cli = CLI.new(@out, @error)
347
+
348
+ @cli.parse_options!(%w{--format invalid})
349
+ end
350
+
351
+ it "should display a format error" do
352
+ Kernel.stub!(:exit)
353
+
354
+ @cli.execute!(stub('step mother'), mock_executor, stub('features'))
355
+
356
+ @error.string.should include("Invalid format: invalid\n")
357
+ end
358
+
359
+ it "should display --help" do
360
+ Kernel.stub!(:exit)
361
+
362
+ @cli.execute!(stub('step mother'), mock_executor, stub('features'))
363
+
364
+ @out.string.should include("Usage: cucumber")
365
+ end
366
+
367
+ it "should exit" do
368
+ Kernel.should_receive(:exit)
369
+
370
+ @cli.execute!(stub('step mother'), mock_executor, stub('features'))
371
+ end
372
+
373
+ end
374
+
375
+ end
376
+
377
+ it "should accept multiple --scenario options" do
378
+ cli = CLI.new
379
+ cli.parse_options!(['--scenario', "User logs in", '--scenario', "User signs up"])
380
+ cli.options[:scenario_names].should include("User logs in")
381
+ cli.options[:scenario_names].should include("User signs up")
382
+ end
383
+
384
+ it "should register --scenario options with the executor" do
385
+ cli = CLI.new
386
+ cli.parse_options!(['--scenario', "User logs in", '--scenario', "User signs up"])
387
+ executor = mock_executor
388
+ executor.should_receive(:scenario_names=).with(["User logs in", "User signs up"])
389
+ cli.execute!(stub('step mother'), executor, stub('features'))
390
+ end
391
+
392
+ it "should accept --color option" do
393
+ cli = CLI.new
394
+ cli.parse_options!(['--color'])
395
+ cli.options[:color].should == true
396
+ Term::ANSIColor.should_receive(:coloring=).with(true)
397
+ cli.execute!(stub('step mother'), mock_executor, stub('features'))
398
+ end
399
+
400
+ it "should accept --no-color option" do
401
+ cli = CLI.new
402
+ cli.parse_options!(['--no-color'])
403
+ cli.options[:color].should == false
404
+ Term::ANSIColor.should_receive(:coloring=).with(false)
405
+ cli.execute!(stub('step mother'), mock_executor, stub('features'))
406
+ end
407
+
408
+ it "should accept --color and --no-color and use the last one" do
409
+ cli = CLI.new
410
+ cli.parse_options!(['--color', '--no-color'])
411
+ cli.options[:color].should == false
412
+ Term::ANSIColor.should_receive(:coloring=).with(false)
413
+ cli.execute!(stub('step mother'), mock_executor, stub('features'))
414
+ end
415
+
416
+ it "should use a default color setting if no option is given" do
417
+ cli = CLI.new
418
+ cli.parse_options!(['--'])
419
+ cli.options[:color].should == nil
420
+ Term::ANSIColor.should_not_receive(:coloring=)
421
+ cli.execute!(stub('step mother'), mock_executor, stub('features'))
422
+ end
423
+
424
+ describe "example.feature:line file arguments" do
425
+
426
+ it "should extract line numbers" do
427
+ cli = CLI.new
428
+ cli.parse_options!(%w{example.feature:10})
429
+
430
+ cli.options[:lines_for_features]['example.feature'].should == [10]
431
+ end
432
+
433
+ it "should remove line numbers" do
434
+ cli = CLI.new
435
+ cli.parse_options!(%w{example.feature:10})
436
+
437
+ cli.paths.should == ["example.feature"]
438
+ end
439
+
440
+ it "should support multiple feature:line numbers" do
441
+ cli = CLI.new
442
+ cli.parse_options!(%w{example.feature:11 another_example.feature:12})
443
+
444
+ cli.options[:lines_for_features].should == {'another_example.feature' => [12], 'example.feature' => [11]}
445
+ end
446
+
447
+ it "should accept multiple line numbers for a single feature" do
448
+ cli = CLI.new
449
+ cli.parse_options!(%w{example.feature:11:12})
450
+
451
+ cli.options[:lines_for_features].should == {'example.feature' => [11, 12]}
452
+ end
453
+
454
+ end
455
+
456
+ it "should search for all features in the specified directory" do
457
+ cli = CLI.new
458
+
459
+ cli.parse_options!(%w{feature_directory/})
460
+ File.stub!(:directory?).and_return(true)
461
+
462
+ Dir.should_receive(:[]).with("feature_directory/**/*.feature").any_number_of_times.and_return([])
463
+
464
+ cli.execute!(stub('step mother'), mock_executor, mock_features)
465
+ end
466
+
467
+ end
468
+ end
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ module Cucumber
4
+ module CoreExt
5
+ describe "proc extended with CallIn" do
6
+ it "should raise ArityMismatchError for too many args (expecting 0)" do
7
+ proc = lambda {}
8
+ proc.extend CallIn
9
+ lambda {
10
+ proc.call_in(Object.new, 1)
11
+ }.should raise_error(Cucumber::ArityMismatchError, "expected 0 block argument(s), got 1")
12
+ end
13
+
14
+ it "should raise ArityMismatchError for too many args (expecting 1)" do
15
+ proc = lambda {|a|}
16
+ proc.extend CallIn
17
+ lambda {
18
+ proc.call_in(Object.new, 1, 2)
19
+ }.should raise_error(Cucumber::ArityMismatchError, "expected 1 block argument(s), got 2")
20
+ end
21
+
22
+ it "should raise ArityMismatchError for too few args (expecting 1)" do
23
+ proc = lambda {|a|}
24
+ proc.extend CallIn
25
+ lambda {
26
+ proc.call_in(Object.new)
27
+ }.should raise_error(Cucumber::ArityMismatchError, "expected 1 block argument(s), got 0")
28
+ end
29
+
30
+ it "should raise ArityMismatchError for too few args (expecting 2)" do
31
+ proc = lambda {|a,b|}
32
+ proc.extend CallIn
33
+ lambda {
34
+ proc.call_in(Object.new, 1)
35
+ }.should raise_error(Cucumber::ArityMismatchError, "expected 2 block argument(s), got 1")
36
+ end
37
+
38
+ it "should remove extraneous path info for file" do
39
+ proc = lambda {|a,b|}
40
+ proc.extend CallIn
41
+ proc.file_colon_line.should == "spec/cucumber/core_ext/proc_spec.rb:39"
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/../../../lib/cucumber/core_ext/string'
2
+
3
+ describe String, "#gzub" do
4
+ it "should format groups with format string" do
5
+ "I ate 1 egg this morning".gzub(/I (\w+) (\d+) (\w+) this (\w+)/, "<span>%s</span>").should ==
6
+ "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
7
+ end
8
+
9
+ it "should format groups with format string when there are dupes" do
10
+ "I bob 1 bo this bobs".gzub(/I (\w+) (\d+) (\w+) this (\w+)/, "<span>%s</span>").should ==
11
+ "I <span>bob</span> <span>1</span> <span>bo</span> this <span>bobs</span>"
12
+ end
13
+
14
+ it "should format groups with block" do
15
+ f = "I ate 1 egg this morning".gzub(/I (\w+) (\d+) (\w+) this (\w+)/) do |m|
16
+ "<span>#{m}</span>"
17
+ end
18
+ f.should == "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
19
+ end
20
+
21
+ it "should format groups with block with not all placeholders having a value" do
22
+ f = "another member named Bob joins the group".gzub(/(a|another) (user|member) named ([^ ]+)( who is not logged in)?/) do |m|
23
+ "<span>#{m}</span>"
24
+ end
25
+ f.should == "<span>another</span> <span>member</span> named <span>Bob</span> joins the group"
26
+ end
27
+
28
+ it "should format match groups in a textile table row" do
29
+ f = "I ate 1 egg this morning".gzub(/I (\w+) (\d+) (\w+) this (\w+)/) do |m|
30
+ "<span>#{m}</span>"
31
+ end
32
+ f.should == "I <span>ate</span> <span>1</span> <span>egg</span> this <span>morning</span>"
33
+ end
34
+ end