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,131 @@
1
+ require 'autotest'
2
+ require 'tempfile'
3
+ require File.dirname(__FILE__) + '/../cucumber/platform'
4
+
5
+ module Autotest::CucumberMixin
6
+ def self.included(receiver)
7
+ receiver::ALL_HOOKS << [:run_features, :ran_features]
8
+ end
9
+
10
+ attr_accessor :scenarios_to_run
11
+
12
+ def initialize
13
+ super
14
+ reset_features
15
+ end
16
+
17
+ def run
18
+ hook :initialize
19
+ reset
20
+ reset_features
21
+ add_sigint_handler
22
+
23
+ self.last_mtime = Time.now if $f
24
+
25
+ loop do # ^c handler
26
+ begin
27
+ get_to_green
28
+ if self.tainted then
29
+ rerun_all_tests
30
+ rerun_all_features if all_good
31
+ else
32
+ hook :all_good
33
+ end
34
+ wait_for_changes
35
+ # Once tests and features are green, reset features every
36
+ # time a file is changed to see if anything breaks.
37
+ reset_features
38
+ rescue Interrupt
39
+ break if self.wants_to_quit
40
+ reset
41
+ reset_features
42
+ end
43
+ end
44
+ hook :quit
45
+ end
46
+
47
+ def all_features_good
48
+ scenarios_to_run == []
49
+ end
50
+
51
+ def get_to_green
52
+ begin
53
+ super
54
+ run_features
55
+ wait_for_changes unless all_features_good
56
+ end until all_features_good
57
+ end
58
+
59
+ def rerun_all_features
60
+ reset_features
61
+ run_features
62
+ end
63
+
64
+ def reset_features
65
+ self.scenarios_to_run = :all
66
+ end
67
+
68
+ def run_features
69
+ hook :run_features
70
+ Tempfile.open('autotest-cucumber') do |dirty_scenarios_file|
71
+ cmd = self.make_cucumber_cmd self.scenarios_to_run, dirty_scenarios_file.path
72
+ return if cmd.empty?
73
+ puts cmd unless $q
74
+ old_sync = $stdout.sync
75
+ $stdout.sync = true
76
+ self.results = []
77
+ line = []
78
+ begin
79
+ open("| #{cmd}", "r") do |f|
80
+ until f.eof? do
81
+ c = f.getc
82
+ putc c
83
+ line << c
84
+ if c == ?\n then
85
+ self.results << if RUBY_VERSION >= "1.9" then
86
+ line.join
87
+ else
88
+ line.pack "c*"
89
+ end
90
+ line.clear
91
+ end
92
+ end
93
+ end
94
+ ensure
95
+ $stdout.sync = old_sync
96
+ end
97
+ self.scenarios_to_run = dirty_scenarios_file.readlines.map { |l| l.chomp }
98
+ self.tainted = true unless self.scenarios_to_run == []
99
+ end
100
+ hook :ran_features
101
+ end
102
+
103
+ def make_cucumber_cmd(scenarios_to_run, dirty_scenarios_filename)
104
+ return '' if scenarios_to_run == []
105
+
106
+ profiles = YAML.load_file("cucumber.yml").keys rescue []
107
+
108
+ profile ||= "autotest-all" if profiles.include?("autotest-all") and scenarios_to_run == :all
109
+ profile ||= "autotest" if profiles.include?("autotest")
110
+ profile ||= nil
111
+
112
+ if profile
113
+ args = ["--profile", profile]
114
+ else
115
+ args = %w{features --format} << (scenarios_to_run == :all ? "progress" : "pretty")
116
+ end
117
+ args += %w{--format autotest --color --out} << dirty_scenarios_filename
118
+ args = args.join(' ')
119
+
120
+ if scenarios_to_run == :all
121
+ scenario_args = nil
122
+ else
123
+ scenario_args = scenarios_to_run.map { |s| "-s '#{s}'" }.join(' ')
124
+ end
125
+ return "#{$CUCUMBER_RUBY} #{cucumber} #{args} #{scenario_args}"
126
+ end
127
+
128
+ def cucumber
129
+ File.file?("script/cucumber") ? "script/cucumber" : "cucumber"
130
+ end
131
+ end
@@ -0,0 +1,6 @@
1
+ require 'autotest/rails'
2
+ require 'autotest/cucumber_mixin'
3
+
4
+ class Autotest::CucumberRails < Autotest::Rails
5
+ include CucumberMixin
6
+ end
@@ -0,0 +1,6 @@
1
+ require 'autotest/cucumber_mixin'
2
+ require 'autotest/rails_rspec'
3
+
4
+ class Autotest::CucumberRailsRspec < Autotest::RailsRspec
5
+ include CucumberMixin
6
+ end
@@ -0,0 +1,6 @@
1
+ require 'autotest/cucumber_mixin'
2
+ require 'autotest/rspec'
3
+
4
+ class Autotest::CucumberRspec < Autotest::Rspec
5
+ include CucumberMixin
6
+ end
@@ -0,0 +1,9 @@
1
+ Autotest.add_discovery do
2
+ if File.directory?('features')
3
+ if ENV['AUTOFEATURE'] =~ /true/i
4
+ "cucumber"
5
+ else
6
+ puts "(Not running features. To run features in autotest, set AUTOFEATURE=true.)"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ module Cucumber
2
+ class Broadcaster
3
+
4
+ def initialize(receivers = [])
5
+ @receivers = receivers
6
+ end
7
+
8
+ def register(receiver)
9
+ @receivers << receiver
10
+ end
11
+
12
+ def method_missing(method_name, *args)
13
+ @receivers.each do |receiver|
14
+ r = (receiver == STDOUT) ? Kernel : receiver # Needed to make colors work on Windows
15
+ r.__send__(method_name, *args) if receiver.respond_to?(method_name)
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,346 @@
1
+ require 'optparse'
2
+ require 'cucumber'
3
+
4
+ module Cucumber
5
+ class YmlLoadError < StandardError; end
6
+
7
+ class CLI
8
+ class << self
9
+ attr_writer :step_mother, :executor, :features
10
+
11
+ def execute
12
+ @execute_called = true
13
+ parse(ARGV).execute!(@step_mother, @executor, @features)
14
+ end
15
+
16
+ def execute_called?
17
+ @execute_called
18
+ end
19
+
20
+ def parse(args)
21
+ cli = new
22
+ cli.parse_options!(args)
23
+ cli
24
+ end
25
+ end
26
+
27
+ attr_reader :options, :paths
28
+ FORMATS = %w{pretty profile progress html autotest}
29
+ DEFAULT_FORMAT = 'pretty'
30
+
31
+ def initialize(out_stream = STDOUT, error_stream = STDERR)
32
+ @out_stream = out_stream
33
+ @error_stream = error_stream
34
+ @paths = []
35
+ @options = {
36
+ :require => nil,
37
+ :lang => 'en',
38
+ :dry_run => false,
39
+ :source => true,
40
+ :snippets => true,
41
+ :formats => {},
42
+ :excludes => [],
43
+ :scenario_names => nil
44
+ }
45
+ @active_format = DEFAULT_FORMAT
46
+ end
47
+
48
+ def parse_options!(args)
49
+ return parse_args_from_profile('default') if args.empty?
50
+ args.extend(OptionParser::Arguable)
51
+
52
+ args.options do |opts|
53
+ opts.banner = ["Usage: cucumber [options] [[FILE[:LINE[:LINE]*]] | [FILES|DIRS]]", "",
54
+ "Examples:",
55
+ "cucumber examples/i18n/en/features",
56
+ "cucumber --language it examples/i18n/it/features/somma.feature:6:98:113", "", ""
57
+ ].join("\n")
58
+ opts.on("-r LIBRARY|DIR", "--require LIBRARY|DIR", "Require files before executing the features.",
59
+ "If this option is not specified, all *.rb files that",
60
+ "are siblings or below the features will be autorequired",
61
+ "This option can be specified multiple times.") do |v|
62
+ @options[:require] ||= []
63
+ @options[:require] << v
64
+ end
65
+ opts.on("-s SCENARIO", "--scenario SCENARIO", "Only execute the scenario with the given name.",
66
+ "If this option is given more than once, run all",
67
+ "the specified scenarios.") do |v|
68
+ @options[:scenario_names] ||= []
69
+ @options[:scenario_names] << v
70
+ end
71
+ opts.on("-l LANG", "--language LANG", "Specify language for features (Default: #{@options[:lang]})",
72
+ "Available languages: #{Cucumber.languages.join(", ")}",
73
+ "Look at #{Cucumber::LANGUAGE_FILE} for keywords") do |v|
74
+ @options[:lang] = v
75
+ end
76
+ opts.on("-f FORMAT", "--format FORMAT", "How to format features (Default: #{DEFAULT_FORMAT})",
77
+ "Available formats: #{FORMATS.join(", ")}",
78
+ "You can also provide your own formatter classes as long as they have been",
79
+ "previously required using --require or if they are in the folder",
80
+ "structure such that cucumber will require them automatically.",
81
+ "This option can be specified multiple times.") do |v|
82
+
83
+ @options[:formats][v] ||= []
84
+ @options[:formats][v] << @out_stream
85
+ @active_format = v
86
+ end
87
+ opts.on("-o", "--out FILE", "Write output to a file instead of @out_stream.",
88
+ "This option can be specified multiple times, and applies to the previously",
89
+ "specified --format.") do |v|
90
+ @options[:formats][@active_format] ||= []
91
+ if @options[:formats][@active_format].last == @out_stream
92
+ @options[:formats][@active_format][-1] = File.open(v, 'w')
93
+ else
94
+ @options[:formats][@active_format] << File.open(v, 'w')
95
+ end
96
+ end
97
+ opts.on("-c", "--[no-]color", "Use ANSI color in the output, if formatters use it. If",
98
+ "these options are given multiple times, the last one is",
99
+ "used. If neither --color or --no-color is given cucumber",
100
+ "decides based on your platform and the output destination") do |v|
101
+ @options[:color] = v
102
+ end
103
+ opts.on("-e", "--exclude PATTERN", "Don't run features matching a pattern") do |v|
104
+ @options[:excludes] << v
105
+ end
106
+ opts.on("-p", "--profile PROFILE", "Pull commandline arguments from cucumber.yml.") do |v|
107
+ parse_args_from_profile(v)
108
+ end
109
+ opts.on("-d", "--dry-run", "Invokes formatters without executing the steps.") do
110
+ @options[:dry_run] = true
111
+ end
112
+ opts.on("-n", "--no-source", "Don't show the file and line of the step definition with the steps.") do
113
+ @options[:source] = false
114
+ end
115
+ opts.on("-i", "--no-snippets", "Don't show the snippets for pending steps") do
116
+ @options[:snippets] = false
117
+ end
118
+ opts.on("-q", "--quiet", "Don't show any development aid information") do
119
+ @options[:snippets] = false
120
+ @options[:source] = false
121
+ end
122
+ opts.on("-v", "--verbose", "Show the files and features loaded") do
123
+ @options[:verbose] = true
124
+ end
125
+ opts.on_tail("--version", "Show version") do
126
+ @out_stream.puts VERSION::STRING
127
+ Kernel.exit
128
+ end
129
+ opts.on_tail("--help", "You're looking at it") do
130
+ @out_stream.puts opts.help
131
+ Kernel.exit
132
+ end
133
+ end.parse!
134
+
135
+ if @options[:formats].empty?
136
+ @options[:formats][DEFAULT_FORMAT] = [@out_stream]
137
+ end
138
+
139
+ # Whatever is left after option parsing is the FILE arguments
140
+ args = extract_and_store_line_numbers(args)
141
+ @paths += args
142
+ end
143
+
144
+
145
+ def execute!(step_mother, executor, features)
146
+ Term::ANSIColor.coloring = @options[:color] unless @options[:color].nil?
147
+ Cucumber.load_language(@options[:lang])
148
+ require_files
149
+ executor.formatters = build_formatter_broadcaster(step_mother)
150
+ load_plain_text_features(features)
151
+ executor.lines_for_features = @options[:lines_for_features]
152
+ executor.scenario_names = @options[:scenario_names] if @options[:scenario_names]
153
+ executor.visit_features(features)
154
+ exit 1 if executor.failed
155
+ end
156
+
157
+ private
158
+
159
+ def extract_and_store_line_numbers(file_arguments)
160
+ @options[:lines_for_features] = Hash.new{|k,v| k[v] = []}
161
+ file_arguments.map do |arg|
162
+ _, file, lines = */^([\w\W]*?):([\d:]+)$/.match(arg)
163
+ unless file.nil?
164
+ @options[:lines_for_features][file] += lines.split(':').map { |line| line.to_i }
165
+ arg = file
166
+ end
167
+ arg
168
+ end
169
+ end
170
+
171
+ def cucumber_yml
172
+ return @cucumber_yml if @cucumber_yml
173
+ unless File.exist?('cucumber.yml')
174
+ raise(YmlLoadError,"cucumber.yml was not found. Please refer to cucumber's documentaion on defining profiles in cucumber.yml. You must define a 'default' profile to use the cucumber command without any arguments.\nType 'cucumber --help' for usage.\n")
175
+ end
176
+
177
+ require 'yaml'
178
+ begin
179
+ @cucumber_yml = YAML::load(IO.read('cucumber.yml'))
180
+ rescue Exception => e
181
+ raise(YmlLoadError,"cucumber.yml was found, but could not be parsed. Please refer to cucumber's documentaion on correct profile usage.\n")
182
+ end
183
+
184
+ if @cucumber_yml.nil? || !@cucumber_yml.is_a?(Hash)
185
+ raise(YmlLoadError,"cucumber.yml was found, but was blank or malformed. Please refer to cucumber's documentaion on correct profile usage.\n")
186
+ end
187
+
188
+ return @cucumber_yml
189
+ end
190
+
191
+ def parse_args_from_profile(profile)
192
+ unless cucumber_yml.has_key?(profile)
193
+ return(exit_with_error <<-END_OF_ERROR)
194
+ Could not find profile: '#{profile}'
195
+
196
+ Defined profiles in cucumber.yml:
197
+ * #{cucumber_yml.keys.join("\n * ")}
198
+ END_OF_ERROR
199
+ end
200
+
201
+ args_from_yml = cucumber_yml[profile] || ''
202
+
203
+ if !args_from_yml.is_a?(String)
204
+ exit_with_error "Profiles must be defined as a String. The '#{profile}' profile was #{args_from_yml.inspect} (#{args_from_yml.class}).\n"
205
+ elsif args_from_yml =~ /^\s*$/
206
+ exit_with_error "The 'foo' profile in cucumber.yml was blank. Please define the command line arguments for the 'foo' profile in cucumber.yml.\n"
207
+ else
208
+ parse_options!(args_from_yml.split(' '))
209
+ end
210
+
211
+ rescue YmlLoadError => e
212
+ exit_with_error(e.message)
213
+ end
214
+
215
+
216
+ # Requires files - typically step files and ruby feature files.
217
+ def require_files
218
+ ARGV.clear # Shut up RSpec
219
+ require "cucumber/treetop_parser/feature_#{@options[:lang]}"
220
+ require "cucumber/treetop_parser/feature_parser"
221
+
222
+ verbose_log("Ruby files required:")
223
+ files_to_require.each do |lib|
224
+ begin
225
+ require lib
226
+ verbose_log(" * #{lib}")
227
+ rescue LoadError => e
228
+ e.message << "\nFailed to load #{lib}"
229
+ raise e
230
+ end
231
+ end
232
+ verbose_log("\n")
233
+ end
234
+
235
+ def files_to_require
236
+ requires = @options[:require] || feature_dirs
237
+ requires.map do |path|
238
+ path = path.gsub(/\\/, '/') # In case we're on windows. Globs don't work with backslashes.
239
+ File.directory?(path) ? Dir["#{path}/**/*.rb"] : path
240
+ end.flatten.uniq
241
+ end
242
+
243
+ def feature_files
244
+ potential_feature_files = @paths.map do |path|
245
+ path = path.gsub(/\\/, '/') # In case we're on windows. Globs don't work with backslashes.
246
+ path = path.chomp('/')
247
+ File.directory?(path) ? Dir["#{path}/**/*.feature"] : path
248
+ end.flatten.uniq
249
+
250
+ @options[:excludes].each do |exclude|
251
+ potential_feature_files.reject! do |path|
252
+ path =~ /#{Regexp.escape(exclude)}/
253
+ end
254
+ end
255
+
256
+ potential_feature_files
257
+ end
258
+
259
+ def feature_dirs
260
+ feature_files.map{|f| File.directory?(f) ? f : File.dirname(f)}.uniq
261
+ end
262
+
263
+ def load_plain_text_features(features)
264
+ parser = TreetopParser::FeatureParser.new
265
+
266
+ verbose_log("Features:")
267
+ feature_files.each do |f|
268
+ features << parser.parse_feature(f)
269
+ verbose_log(" * #{f}")
270
+ end
271
+ verbose_log("\n"*2)
272
+ end
273
+
274
+ def build_formatter_broadcaster(step_mother)
275
+ formatter_broadcaster = Broadcaster.new
276
+ @options[:formats].each do |format, output_list|
277
+ output_broadcaster = build_output_broadcaster(output_list)
278
+ case format
279
+ when 'pretty'
280
+ formatter_broadcaster.register(Formatters::PrettyFormatter.new(output_broadcaster, step_mother, @options))
281
+ when 'progress'
282
+ formatter_broadcaster.register(Formatters::ProgressFormatter.new(output_broadcaster))
283
+ when 'profile'
284
+ formatter_broadcaster.register(Formatters::ProfileFormatter.new(output_broadcaster, step_mother))
285
+ when 'html'
286
+ formatter_broadcaster.register(Formatters::HtmlFormatter.new(output_broadcaster, step_mother))
287
+ when 'autotest'
288
+ formatter_broadcaster.register(Formatters::AutotestFormatter.new(output_broadcaster))
289
+ else
290
+ begin
291
+ formatter_class = constantize(format)
292
+ formatter_broadcaster.register(formatter_class.new(output_broadcaster, step_mother, @options))
293
+ rescue NameError => e
294
+ @error_stream.puts "Invalid format: #{format}\n"
295
+ exit_with_help
296
+ rescue Exception => e
297
+ exit_with_error("Error creating formatter: #{format}\n#{e}\n")
298
+ end
299
+ end
300
+ end
301
+ formatter_broadcaster
302
+ end
303
+
304
+ def build_output_broadcaster(output_list)
305
+ output_broadcaster = Broadcaster.new
306
+ output_list.each do |output|
307
+ output_broadcaster.register(output)
308
+ end
309
+ output_broadcaster
310
+ end
311
+
312
+ private
313
+
314
+ def constantize(camel_cased_word)
315
+ names = camel_cased_word.split('::')
316
+ names.shift if names.empty? || names.first.empty?
317
+
318
+ constant = Object
319
+ names.each do |name|
320
+ constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
321
+ end
322
+ constant
323
+ end
324
+
325
+ def verbose_log(string)
326
+ @out_stream.puts(string) if @options[:verbose]
327
+ end
328
+
329
+ def exit_with_help
330
+ parse_options!(%w{--help})
331
+ end
332
+
333
+ def exit_with_error(error_message)
334
+ @error_stream << error_message
335
+ Kernel.exit 1
336
+ end
337
+
338
+ end
339
+ end
340
+
341
+ extend Cucumber::StepMethods
342
+ Cucumber::CLI.step_mother = step_mother
343
+ Cucumber::CLI.executor = executor
344
+
345
+ extend Cucumber::Tree
346
+ Cucumber::CLI.features = features
@@ -0,0 +1,69 @@
1
+ module Cucumber
2
+ class ArityMismatchError < StandardError
3
+ end
4
+
5
+ module CoreExt
6
+ # Proc extension that allows a proc to be called in the context of any object.
7
+ # Also makes it possible to tack a name onto a Proc.
8
+ module CallIn
9
+ PROC_PATTERN = /[\d\w]+@(.*):(.*)>/
10
+
11
+ if Proc.new{}.to_s =~ PROC_PATTERN
12
+ def to_backtrace_line
13
+ "#{file_colon_line}:in `#{name}'"
14
+ end
15
+
16
+ def to_comment_line
17
+ "# #{file_colon_line}"
18
+ end
19
+
20
+ def file_colon_line
21
+ path, line = *to_s.match(PROC_PATTERN)[1..2]
22
+ path = File.expand_path(path)
23
+ pwd = Dir.pwd
24
+ path = path[pwd.length+1..-1]
25
+ "#{path}:#{line}"
26
+ end
27
+ else
28
+ # This Ruby implementation doesn't implement Proc#to_s correctly
29
+ STDERR.puts "*** THIS RUBY IMPLEMENTATION DOESN'T REPORT FILE AND LINE FOR PROCS ***"
30
+
31
+ def to_backtrace_line
32
+ nil
33
+ end
34
+
35
+ def to_comment_line
36
+ ""
37
+ end
38
+ end
39
+
40
+ attr_accessor :name
41
+
42
+ def call_in(obj, *args)
43
+ obj.extend(mod)
44
+ if self != StepMother::PENDING && args.length != arity2
45
+ # We have to manually raise when the block has arity -1 (no pipes)
46
+ raise ArityMismatchError.new("expected #{arity2} block argument(s), got #{args.length}")
47
+ else
48
+ obj.__send__(meth, *args)
49
+ end
50
+ end
51
+
52
+ def arity2
53
+ arity == -1 ? 0 : arity
54
+ end
55
+
56
+ def meth
57
+ @meth ||= "__cucumber_#{object_id}"
58
+ end
59
+
60
+ def mod
61
+ p = self
62
+ m = meth
63
+ @mod ||= Module.new do
64
+ define_method(m, &p)
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,29 @@
1
+ class String
2
+ def gzub(regexp, format=nil, &proc)
3
+ md = match(regexp)
4
+ raise "#{self.inspect} doesn't match #{regexp.inspect}" if md.nil?
5
+
6
+ s = dup
7
+ pos = 0
8
+ md.captures.each_with_index do |m, n|
9
+ replacement = if block_given?
10
+ proc.call(m)
11
+ else
12
+ format % m
13
+ end
14
+
15
+ if md.offset(n+1)[0]
16
+ s[md.offset(n+1)[0] + pos, m.length] = replacement
17
+ pos += replacement.length - m.length
18
+ end
19
+ end
20
+ s
21
+ end
22
+
23
+ if $CUCUMBER_JRUBY && $CUCUMBER_RAILS
24
+ # Workaround for http://tinyurl.com/55uu3u
25
+ alias jlength length
26
+ else
27
+ require 'jcode'
28
+ end
29
+ end