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,54 @@
1
+ require 'cucumber/platform'
2
+
3
+ module Cucumber
4
+ class ArityMismatchError < StandardError
5
+ end
6
+ end
7
+
8
+ class Object
9
+ def cucumber_instance_exec(check_arity, pseudo_method, *args, &block)
10
+ arity = block.arity
11
+ arity = 0 if arity == -1
12
+ cucumber_run_with_backtrace_filtering(pseudo_method) do
13
+ if check_arity && args.length != arity
14
+ instance_exec do
15
+ raise Cucumber::ArityMismatchError.new("expected #{arity} block argument(s), got #{args.length}")
16
+ end
17
+ else
18
+ instance_exec(*args, &block)
19
+ end
20
+ end
21
+ end
22
+
23
+ def cucumber_run_with_backtrace_filtering(pseudo_method)
24
+ begin
25
+ yield
26
+ rescue Exception => e
27
+ instance_exec_invocation_line = "#{__FILE__}:#{__LINE__ - 2}:in `cucumber_run_with_backtrace_filtering'"
28
+ Exception.cucumber_strip_backtrace!((e.backtrace || []), instance_exec_invocation_line, pseudo_method)
29
+ raise e
30
+ end
31
+ end
32
+
33
+ unless defined? instance_exec # 1.9
34
+ # http://eigenclass.org/hiki/bounded+space+instance_exec
35
+ module InstanceExecHelper; end
36
+ include InstanceExecHelper
37
+ def instance_exec(*args, &block)
38
+ begin
39
+ old_critical, Thread.critical = Thread.critical, true
40
+ n = 0
41
+ n += 1 while respond_to?(mname="__instance_exec#{n}")
42
+ InstanceExecHelper.module_eval{ define_method(mname, &block) }
43
+ ensure
44
+ Thread.critical = old_critical
45
+ end
46
+ begin
47
+ ret = send(mname, *args)
48
+ ensure
49
+ InstanceExecHelper.module_eval{ remove_method(mname) } rescue nil
50
+ end
51
+ ret
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,33 @@
1
+ # Proc extension to get more location info out of a proc
2
+ class Proc
3
+ PROC_PATTERN = /[\d\w]+@(.*):(.*)>/
4
+
5
+ if Proc.new{}.to_s =~ PROC_PATTERN
6
+ def to_backtrace_line(name)
7
+ "#{file_colon_line}:in `#{name}'"
8
+ end
9
+
10
+ def to_comment_line
11
+ "# #{file_colon_line}"
12
+ end
13
+
14
+ def file_colon_line
15
+ path, line = *to_s.match(PROC_PATTERN)[1..2]
16
+ path = File.expand_path(path)
17
+ pwd = Dir.pwd
18
+ path = path[pwd.length+1..-1]
19
+ "#{path}:#{line}"
20
+ end
21
+ else
22
+ # This Ruby implementation doesn't implement Proc#to_s correctly
23
+ STDERR.puts "*** THIS RUBY IMPLEMENTATION DOESN'T REPORT FILE AND LINE FOR PROCS ***"
24
+
25
+ def to_backtrace_line
26
+ nil
27
+ end
28
+
29
+ def to_comment_line
30
+ ""
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,48 @@
1
+ class String
2
+ def indent(n)
3
+ if n >= 0
4
+ gsub(/^/, ' ' * n)
5
+ else
6
+ gsub(/^ {0,#{-n}}/, "")
7
+ end
8
+ end
9
+
10
+ # re.source.gsub(/\([^)]*\)/, '$var')
11
+ # Cumulative #sub
12
+ def subs(re, *args)
13
+ args.inject(self) do |s,arg|
14
+ s.sub(re, arg)
15
+ end
16
+ end
17
+
18
+ # TODO: Use subs instead...
19
+ def gzub(regexp, format=nil, &proc)
20
+ md = match(regexp)
21
+ raise "#{self.inspect} doesn't match #{regexp.inspect}" if md.nil?
22
+
23
+ s = dup
24
+ pos = 0
25
+ md.captures.each_with_index do |m, n|
26
+ replacement = if block_given?
27
+ proc.call(m)
28
+ elsif Proc === format
29
+ format.call(m)
30
+ else
31
+ format % m
32
+ end
33
+
34
+ if md.offset(n+1)[0]
35
+ s[md.offset(n+1)[0] + pos, m.length] = replacement
36
+ pos += replacement.length - m.length
37
+ end
38
+ end
39
+ s
40
+ end
41
+
42
+ if (Cucumber::JRUBY && Cucumber::RAILS) || Cucumber::RUBY_1_9
43
+ # Workaround for http://tinyurl.com/55uu3u
44
+ alias jlength length
45
+ else
46
+ require 'jcode'
47
+ end
48
+ end
@@ -0,0 +1 @@
1
+ %w{pretty progress profile rerun}.each{|n| require "cucumber/formatter/#{n}"}
@@ -0,0 +1,106 @@
1
+ # Hack to work around Win32/Console, which bundles a licence-violating, outdated
2
+ # copy of term/ansicolor that doesn't implement Term::ANSIColor#coloring=.
3
+ # We want the official one!
4
+ gem 'term-ansicolor'
5
+ $LOAD_PATH.each{|path| $LOAD_PATH.unshift($LOAD_PATH.delete(path)) if path =~ /term-ansicolor/}
6
+ require 'term/ansicolor'
7
+
8
+ if Cucumber::WINDOWS_MRI
9
+ begin
10
+ require 'Win32/Console/ANSI'
11
+ rescue LoadError
12
+ STDERR.puts "You must gem install win32console to get coloured output on MRI/Windows"
13
+ Term::ANSIColor.coloring = false
14
+ end
15
+ end
16
+
17
+ Term::ANSIColor.coloring = false if !STDOUT.tty? || (Cucumber::WINDOWS && !Cucumber::WINDOWS_MRI)
18
+
19
+ module Cucumber
20
+ module Formatter
21
+ # Defines aliases for coloured output. You can tweak the colours by defining
22
+ # a <tt>CUCUMBER_COLORS</tt> variable in your shell, very much like you can
23
+ # tweak the familiar POSIX command <tt>ls</tt> with
24
+ # <a href="http://mipsisrisc.com/rambling/2008/06/27/lscolorsls_colors-now-with-linux-support/">$LSCOLORS/$LS_COLORS</a>
25
+ #
26
+ # The colours that you can change are:
27
+ #
28
+ # * <tt>undefined</tt> - defaults to <tt>yellow</tt>
29
+ # * <tt>pending</tt> - defaults to <tt>yellow</tt>
30
+ # * <tt>pending_param</tt> - defaults to <tt>yellow,bold</tt>
31
+ # * <tt>failed</tt> - defaults to <tt>red</tt>
32
+ # * <tt>failed_param</tt> - defaults to <tt>red,bold</tt>
33
+ # * <tt>passed</tt> - defaults to <tt>green</tt>
34
+ # * <tt>passed_param</tt> - defaults to <tt>green,bold</tt>
35
+ # * <tt>outline</tt> - defaults to <tt>cyan</tt>
36
+ # * <tt>outline_param</tt> - defaults to <tt>cyan,bold</tt>
37
+ # * <tt>skipped</tt> - defaults to <tt>cyan</tt>
38
+ # * <tt>skipped_param</tt> - defaults to <tt>cyan,bold</tt>
39
+ # * <tt>comment</tt> - defaults to <tt>grey</tt>
40
+ # * <tt>tag</tt> - defaults to <tt>blue</tt>
41
+ #
42
+ # For instance, if your shell has a black background and a green font (like the
43
+ # "Homebrew" settings for OS X' Terminal.app), you may want to override passed
44
+ # steps to be white instead of green. Examples:
45
+ #
46
+ # export CUCUMBER_COLORS="passed=white"
47
+ # export CUCUMBER_COLORS="passed=white,bold:passed_param=white,bold,underline"
48
+ #
49
+ # (If you're on Windows, use SET instead of export).
50
+ # To see what colours and effects are available, just run this in your shell:
51
+ #
52
+ # ruby -e "require 'rubygems'; require 'term/ansicolor'; puts Term::ANSIColor.attributes"
53
+ #
54
+ # Although not listed, you can also use <tt>grey</tt>
55
+ module ANSIColor
56
+ include Term::ANSIColor
57
+
58
+ # Not supported in Term::ANSIColor
59
+ def grey(m)
60
+ if ::Term::ANSIColor.coloring?
61
+ "\e[90m#{m}\e[0m"
62
+ else
63
+ m
64
+ end
65
+ end
66
+
67
+ ALIASES = Hash.new do |h,k|
68
+ if k.to_s =~ /(.*)_param/
69
+ h[$1] + ',bold'
70
+ end
71
+ end.merge({
72
+ 'undefined' => 'yellow',
73
+ 'pending' => 'yellow',
74
+ 'failed' => 'red',
75
+ 'passed' => 'green',
76
+ 'thead' => 'cyan',
77
+ 'outline' => 'cyan',
78
+ 'skipped' => 'cyan',
79
+ 'comment' => 'grey',
80
+ 'tag' => 'blue'
81
+ })
82
+
83
+ if ENV['CUCUMBER_COLORS'] # Example: export CUCUMBER_COLORS="passed=red:failed=yellow"
84
+ ENV['CUCUMBER_COLORS'].split(':').each do |pair|
85
+ a = pair.split('=')
86
+ ALIASES[a[0]] = a[1]
87
+ end
88
+ end
89
+
90
+ ALIASES.each do |method, color|
91
+ unless method =~ /.*_param/
92
+ code = <<-EOF
93
+ def #{method}(string=nil, &proc)
94
+ #{ALIASES[method].split(",").join("(") + "(string, &proc" + ")" * ALIASES[method].split(",").length}
95
+ end
96
+ # This resets the colour to the non-param colour
97
+ def #{method}_param(string=nil, &proc)
98
+ #{ALIASES[method+'_param'].split(",").join("(") + "(string, &proc" + ")" * ALIASES[method+'_param'].split(",").length} + #{ALIASES[method].split(",").join(' + ')}
99
+ end
100
+ EOF
101
+ eval(code)
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,116 @@
1
+ require 'cucumber/formatter/ansicolor'
2
+
3
+ module Cucumber
4
+ module Formatter
5
+ module Console
6
+ extend ANSIColor
7
+ FORMATS = Hash.new{|hash, format| hash[format] = method(format).to_proc}
8
+
9
+ def format_step(keyword, step_name, status, step_definition, source_indent)
10
+ line = if step_definition # nil for :outline
11
+ comment = if source_indent
12
+ c = (' # ' + step_definition.file_colon_line).indent(source_indent)
13
+ format_string(c, :comment)
14
+ else
15
+ ''
16
+ end
17
+ keyword + " " + step_definition.format_args(step_name, format_for(status, :param)) + comment
18
+ else
19
+ keyword + " " + step_name
20
+ end
21
+ format_string(line, status)
22
+ end
23
+
24
+ def format_string(string, status)
25
+ fmt = format_for(status)
26
+ if Proc === fmt
27
+ fmt.call(string)
28
+ else
29
+ fmt % string
30
+ end
31
+ end
32
+
33
+ def print_undefined_scenarios(features)
34
+ elements = features.scenarios.select{|scenario| scenario.undefined?}
35
+ print_elements(elements, :undefined, 'scenarios')
36
+ end
37
+
38
+ def print_steps(features, status)
39
+ print_elements(features.steps[status], status, 'steps')
40
+ end
41
+
42
+ def print_elements(elements, status, kind)
43
+ if elements.any?
44
+ @io.puts(format_string("(::) #{status} #{kind} (::)", status))
45
+ @io.puts
46
+ @io.flush
47
+ end
48
+
49
+ elements.each_with_index do |element, i|
50
+ if status == :failed
51
+ print_exception(element.exception, 0)
52
+ else
53
+ @io.puts(format_string(element.backtrace_line, status))
54
+ end
55
+ @io.puts
56
+ @io.flush
57
+ end
58
+ end
59
+
60
+ def print_counts(features)
61
+ @io.puts dump_count(features.scenarios.length, "scenario")
62
+
63
+ [:failed, :skipped, :undefined, :pending, :passed].each do |status|
64
+ if features.steps[status].any?
65
+ count_string = dump_count(features.steps[status].length, "step", status.to_s)
66
+ @io.puts format_string(count_string, status)
67
+ @io.flush
68
+ end
69
+ end
70
+ end
71
+
72
+ def print_exception(e, indent)
73
+ status = Cucumber::EXCEPTION_STATUS[e.class]
74
+ @io.puts(format_string("#{e.message} (#{e.class})\n#{e.backtrace.join("\n")}".indent(indent), status))
75
+ end
76
+
77
+ def print_snippets(features, options)
78
+ return unless options[:snippets]
79
+ undefined = features.steps[:undefined]
80
+ return if undefined.empty?
81
+ snippets = undefined.map do |step|
82
+ step_name = StepMother::Undefined === step.exception ? step.exception.step_name : step.name
83
+ snippet = @step_mother.snippet_text(step.actual_keyword, step_name)
84
+ snippet
85
+ end.compact.uniq
86
+
87
+ text = "\nYou can implement step definitions for missing steps with these snippets:\n\n"
88
+ text += snippets.join("\n\n")
89
+
90
+ @io.puts format_string(text, :undefined)
91
+ @io.puts
92
+ @io.flush
93
+ end
94
+
95
+ private
96
+
97
+ def with_color
98
+ c = Term::ANSIColor.coloring?
99
+ Term::ANSIColor.coloring = @io.tty?
100
+ yield
101
+ Term::ANSIColor.coloring = c
102
+ end
103
+
104
+ def dump_count(count, what, state=nil)
105
+ [count, state, "#{what}#{count == 1 ? '' : 's'}"].compact.join(" ")
106
+ end
107
+
108
+ def format_for(*keys)
109
+ key = keys.join('_').to_sym
110
+ fmt = FORMATS[key]
111
+ raise "No format for #{key.inspect}: #{FORMATS.inspect}" if fmt.nil?
112
+ fmt
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,158 @@
1
+ require 'cucumber/formatter/console'
2
+ require 'fileutils'
3
+
4
+ module Cucumber
5
+ module Formatter
6
+ # This formatter prints features to plain text - exactly how they were parsed,
7
+ # just prettier. That means with proper indentation and alignment of table columns.
8
+ #
9
+ # If the output is STDOUT (and not a file), there are bright colours to watch too.
10
+ #
11
+ class Pretty < Ast::Visitor
12
+ include FileUtils
13
+ include Console
14
+ attr_writer :indent
15
+
16
+ def initialize(step_mother, io, options, delim='|')
17
+ super(step_mother)
18
+ @io = io
19
+ @options = options
20
+ @delim = delim
21
+ end
22
+
23
+ def visit_features(features)
24
+ super
25
+ print_summary(features) unless @options[:autoformat]
26
+ end
27
+
28
+ def visit_feature(feature)
29
+ @indent = 0
30
+ if @options[:autoformat]
31
+ file = File.join(@options[:autoformat], feature.file)
32
+ dir = File.dirname(file)
33
+ mkdir_p(dir) unless File.directory?(dir)
34
+ File.open(file, Cucumber.file_mode('w')) do |io|
35
+ @io = io
36
+ with_color do
37
+ feature.accept(self)
38
+ end
39
+ end
40
+ else
41
+ with_color do
42
+ feature.accept(self)
43
+ end
44
+ end
45
+ end
46
+
47
+ def visit_comment(comment)
48
+ comment.accept(self)
49
+ end
50
+
51
+ def visit_comment_line(comment_line)
52
+ unless comment_line.blank?
53
+ @io.puts(comment_line.indent(@indent))
54
+ @io.flush
55
+ end
56
+ end
57
+
58
+ def visit_tags(tags)
59
+ tags.accept(self)
60
+ if @indent == 1
61
+ @io.puts
62
+ @io.flush
63
+ end
64
+ end
65
+
66
+ def visit_tag_name(tag_name)
67
+ tag = format_string("@#{tag_name}", :tag).indent(@indent)
68
+ @io.print(tag)
69
+ @io.flush
70
+ @indent = 1
71
+ end
72
+
73
+ def visit_feature_name(name)
74
+ @io.puts(name)
75
+ @io.puts
76
+ @io.flush
77
+ end
78
+
79
+ def visit_feature_element(feature_element)
80
+ @indent = 2
81
+ @last_undefined = feature_element.undefined?
82
+ feature_element.accept(self)
83
+ @io.puts
84
+ @io.flush
85
+ end
86
+
87
+ def visit_examples(examples)
88
+ examples.accept(self)
89
+ end
90
+
91
+ def visit_examples_name(keyword, name)
92
+ @io.puts("\n #{keyword} #{name}")
93
+ @io.flush
94
+ @indent = 4
95
+ end
96
+
97
+ def visit_scenario_name(keyword, name, file_line, source_indent)
98
+ line = " #{keyword} #{name}"
99
+ line = format_string(line, :undefined) if @last_undefined
100
+ @io.print(line)
101
+ if @options[:source]
102
+ line_comment = " # #{file_line}".indent(source_indent)
103
+ @io.print(format_string(line_comment, :comment))
104
+ end
105
+ @io.puts
106
+ @io.flush
107
+ end
108
+
109
+ def visit_step(step)
110
+ @indent = 6
111
+ exception = step.accept(self)
112
+ print_exception(exception, @indent) if exception
113
+ end
114
+
115
+ def visit_step_name(keyword, step_name, status, step_definition, source_indent)
116
+ source_indent = nil unless @options[:source]
117
+ formatted_step_name = format_step(keyword, step_name, status, step_definition, source_indent)
118
+ @io.puts(" " + formatted_step_name)
119
+ @io.flush
120
+ end
121
+
122
+ def visit_multiline_arg(multiline_arg, status)
123
+ multiline_arg.accept(self, status)
124
+ end
125
+
126
+ def visit_table_row(table_row, status)
127
+ @io.print @delim.indent(@indent)
128
+ exception = table_row.accept(self, status)
129
+ @io.puts
130
+ print_exception(exception, 6) if exception
131
+ end
132
+
133
+ def visit_py_string(string, status)
134
+ s = "\"\"\"\n#{string}\n\"\"\"".indent(@indent)
135
+ s = s.split("\n").map{|l| l =~ /^\s+$/ ? '' : l}.join("\n")
136
+ @io.puts(format_string(s, status))
137
+ @io.flush
138
+ end
139
+
140
+ def visit_table_cell(table_cell, status)
141
+ table_cell.accept(self, status)
142
+ end
143
+
144
+ def visit_table_cell_value(value, width, status)
145
+ @io.print(' ' + format_string((value || '').ljust(width), status) + " #{@delim}")
146
+ @io.flush
147
+ end
148
+
149
+ private
150
+
151
+ def print_summary(features)
152
+ print_counts(features)
153
+ print_snippets(features, @options)
154
+ end
155
+
156
+ end
157
+ end
158
+ end