aslakhellesoy-cucumber 0.1.16.4 → 0.1.16.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/History.txt +75 -1
  2. data/Manifest.txt +58 -65
  3. data/examples/cs/features/step_definitons/calculator_steps.rb +1 -1
  4. data/examples/i18n/Rakefile +3 -3
  5. data/examples/i18n/ar/features/step_definitons/calculator_steps.rb +1 -6
  6. data/examples/i18n/da/features/step_definitons/kalkulator_steps.rb +1 -1
  7. data/examples/i18n/de/features/addition.feature +6 -6
  8. data/examples/i18n/de/features/step_definitons/calculator_steps.rb +2 -2
  9. data/examples/i18n/en/features/addition.feature +6 -6
  10. data/examples/i18n/en/features/step_definitons/calculator_steps.rb +2 -2
  11. data/examples/i18n/es/features/step_definitons/calculador_steps.rb +1 -1
  12. data/examples/i18n/et/features/liitmine.feature +7 -6
  13. data/examples/i18n/et/features/step_definitions/kalkulaator_steps.rb +1 -1
  14. data/examples/i18n/fi/features/step_definitons/laskin_steps.rb +1 -1
  15. data/examples/i18n/fi/features/yhteenlasku.feature +2 -2
  16. data/examples/i18n/fr/features/addition.feature +2 -2
  17. data/examples/i18n/fr/features/step_definitions/calculatrice_steps.rb +1 -1
  18. data/examples/i18n/id/features/addition.feature +6 -6
  19. data/examples/i18n/id/features/step_definitons/calculator_steps.rb +2 -2
  20. data/examples/i18n/it/features/step_definitons/calcolatrice_steps.rb +1 -1
  21. data/examples/i18n/ja/features/step_definitons/calculator_steps.rb +2 -3
  22. data/examples/i18n/ko/features/step_definitons/calculator_steps.rb +1 -1
  23. data/examples/i18n/lt/features/addition.feature +7 -6
  24. data/examples/i18n/lt/features/step_definitons/calculator_steps.rb +2 -2
  25. data/examples/i18n/no/features/step_definitons/kalkulator_steps.rb +7 -7
  26. data/examples/i18n/no/features/summering.feature +1 -0
  27. data/examples/i18n/pt/features/step_definitions/calculadora_steps.rb +1 -1
  28. data/examples/i18n/ro/features/step_definitons/calculator_steps.rb +1 -1
  29. data/examples/i18n/se/features/step_definitons/kalkulator_steps.rb +1 -1
  30. data/examples/i18n/zh-CN/features/step_definitons/calculator_steps.rb +2 -2
  31. data/examples/jbehave/README.textile +17 -0
  32. data/examples/jbehave/features/support/env.rb +7 -0
  33. data/examples/jbehave/features/trading.feature +24 -0
  34. data/examples/jbehave/pom.xml +48 -0
  35. data/examples/self_test/README.textile +4 -1
  36. data/examples/self_test/features/call_undefined_step_from_step_def.feature +7 -0
  37. data/examples/self_test/features/lots_of_undefined.feature +8 -0
  38. data/examples/self_test/features/outline_sample.feature +8 -5
  39. data/examples/self_test/features/sample.feature +5 -3
  40. data/examples/self_test/features/step_definitions/sample_steps.rb +15 -3
  41. data/features/cucumber_cli.feature +199 -97
  42. data/features/cucumber_cli_outlines.feature +46 -38
  43. data/features/report_called_undefined_steps.feature +31 -0
  44. data/features/step_definitions/cucumber_steps.rb +7 -3
  45. data/features/step_definitions/extra_steps.rb +1 -1
  46. data/features/support/env.rb +1 -1
  47. data/gem_tasks/features.rake +1 -1
  48. data/gem_tasks/flog.rake +1 -1
  49. data/lib/autotest/cucumber_mixin.rb +16 -23
  50. data/lib/cucumber/ast/comment.rb +26 -0
  51. data/lib/cucumber/ast/examples.rb +22 -0
  52. data/lib/cucumber/ast/feature.rb +60 -0
  53. data/lib/cucumber/ast/features.rb +39 -0
  54. data/lib/cucumber/ast/filter.rb +22 -0
  55. data/lib/cucumber/ast/outline_table.rb +49 -0
  56. data/lib/cucumber/ast/py_string.rb +52 -0
  57. data/lib/cucumber/ast/scenario.rb +91 -0
  58. data/lib/cucumber/ast/scenario_outline.rb +83 -0
  59. data/lib/cucumber/ast/step.rb +130 -0
  60. data/lib/cucumber/ast/table.rb +214 -0
  61. data/lib/cucumber/ast/tags.rb +33 -0
  62. data/lib/cucumber/ast/visitor.rb +93 -0
  63. data/lib/cucumber/ast.rb +27 -0
  64. data/lib/cucumber/broadcaster.rb +1 -6
  65. data/lib/cucumber/cli.rb +178 -128
  66. data/lib/cucumber/core_ext/exception.rb +41 -8
  67. data/lib/cucumber/core_ext/instance_exec.rb +54 -0
  68. data/lib/cucumber/core_ext/proc.rb +29 -65
  69. data/lib/cucumber/core_ext/string.rb +19 -0
  70. data/lib/cucumber/{formatters → formatter}/ansicolor.rb +11 -10
  71. data/lib/cucumber/formatter/console.rb +116 -0
  72. data/lib/cucumber/formatter/pretty.rb +158 -0
  73. data/lib/cucumber/formatter/profile.rb +77 -0
  74. data/lib/cucumber/formatter/progress.rb +68 -0
  75. data/lib/cucumber/formatter.rb +1 -0
  76. data/lib/cucumber/formatters/autotest_formatter.rb +0 -2
  77. data/lib/cucumber/formatters/html_formatter.rb +4 -3
  78. data/lib/cucumber/formatters/pretty_formatter.rb +1 -1
  79. data/lib/cucumber/formatters/unicode.rb +3 -3
  80. data/lib/cucumber/jbehave.rb +104 -0
  81. data/lib/cucumber/languages.yml +100 -73
  82. data/lib/cucumber/parser/basic.rb +0 -0
  83. data/lib/cucumber/parser/feature.rb +1694 -0
  84. data/lib/cucumber/parser/feature.tt +206 -0
  85. data/lib/cucumber/parser/file_parser.rb +50 -0
  86. data/lib/cucumber/parser/i18n.tt +26 -0
  87. data/lib/cucumber/parser/treetop_ext.rb +9 -0
  88. data/lib/cucumber/parser.rb +27 -0
  89. data/lib/cucumber/platform.rb +3 -17
  90. data/lib/cucumber/step_definition.rb +83 -0
  91. data/lib/cucumber/step_mother.rb +128 -72
  92. data/lib/cucumber/version.rb +1 -1
  93. data/lib/cucumber.rb +56 -9
  94. data/spec/cucumber/ast/feature_factory.rb +54 -0
  95. data/spec/cucumber/ast/feature_spec.rb +60 -0
  96. data/spec/cucumber/ast/py_string_spec.rb +40 -0
  97. data/spec/cucumber/ast/scenario_outline_spec.rb +64 -0
  98. data/spec/cucumber/ast/scenario_spec.rb +82 -0
  99. data/spec/cucumber/ast/step_spec.rb +45 -0
  100. data/spec/cucumber/ast/table_spec.rb +81 -0
  101. data/spec/cucumber/broadcaster_spec.rb +4 -17
  102. data/spec/cucumber/cli_spec.rb +43 -148
  103. data/spec/cucumber/core_ext/proc_spec.rb +27 -35
  104. data/spec/cucumber/core_ext/string_spec.rb +8 -0
  105. data/spec/cucumber/{formatters → formatter}/ansicolor_spec.rb +2 -2
  106. data/spec/cucumber/formatter/html/cucumber.css +37 -0
  107. data/spec/cucumber/formatter/html/cucumber.js +11 -0
  108. data/spec/cucumber/formatter/html/index.html +45 -0
  109. data/spec/cucumber/formatter/html/jquery-1.3.min.js +19 -0
  110. data/spec/cucumber/formatter/html/jquery.uitableedit.js +100 -0
  111. data/spec/cucumber/formatters/autotest_formatter_spec.rb +1 -0
  112. data/spec/cucumber/formatters/profile_formatter_spec.rb +17 -16
  113. data/spec/cucumber/parser/feature_parser_spec.rb +247 -0
  114. data/spec/cucumber/parser/table_parser_spec.rb +48 -0
  115. data/spec/cucumber/step_definition_spec.rb +62 -0
  116. data/spec/cucumber/step_mom_spec.rb +49 -0
  117. data/spec/cucumber/treetop_parser/empty_feature.feature +1 -1
  118. data/spec/cucumber/treetop_parser/spaces.feature +3 -1
  119. data/spec/cucumber/treetop_parser/with_comments.feature +1 -1
  120. data/spec/cucumber/treetop_parser/with_tags.feature +18 -0
  121. data/spec/cucumber/world/pending_spec.rb +13 -12
  122. data/spec/spec_helper.rb +1 -1
  123. metadata +59 -67
  124. data/examples/calculator_ruby_features/Rakefile +0 -6
  125. data/examples/calculator_ruby_features/features/addition.rb +0 -39
  126. data/examples/calculator_ruby_features/features/step_definitons/calculator_steps.rb +0 -43
  127. data/gem_tasks/treetop.rake +0 -41
  128. data/lib/cucumber/executor.rb +0 -205
  129. data/lib/cucumber/formatters/profile_formatter.rb +0 -92
  130. data/lib/cucumber/formatters/progress_formatter.rb +0 -61
  131. data/lib/cucumber/formatters.rb +0 -1
  132. data/lib/cucumber/model/table.rb +0 -32
  133. data/lib/cucumber/model.rb +0 -1
  134. data/lib/cucumber/step_methods.rb +0 -49
  135. data/lib/cucumber/tree/feature.rb +0 -105
  136. data/lib/cucumber/tree/features.rb +0 -21
  137. data/lib/cucumber/tree/given_scenario.rb +0 -13
  138. data/lib/cucumber/tree/scenario.rb +0 -240
  139. data/lib/cucumber/tree/step.rb +0 -173
  140. data/lib/cucumber/tree/table.rb +0 -26
  141. data/lib/cucumber/tree/top_down_visitor.rb +0 -23
  142. data/lib/cucumber/tree.rb +0 -16
  143. data/lib/cucumber/treetop_parser/feature.treetop.erb +0 -254
  144. data/lib/cucumber/treetop_parser/feature_ar.rb +0 -1951
  145. data/lib/cucumber/treetop_parser/feature_cy.rb +0 -1951
  146. data/lib/cucumber/treetop_parser/feature_da.rb +0 -1951
  147. data/lib/cucumber/treetop_parser/feature_de.rb +0 -1951
  148. data/lib/cucumber/treetop_parser/feature_en-lol.rb +0 -1951
  149. data/lib/cucumber/treetop_parser/feature_en-tx.rb +0 -1951
  150. data/lib/cucumber/treetop_parser/feature_en.rb +0 -1951
  151. data/lib/cucumber/treetop_parser/feature_es.rb +0 -1951
  152. data/lib/cucumber/treetop_parser/feature_et.rb +0 -1951
  153. data/lib/cucumber/treetop_parser/feature_fr.rb +0 -1951
  154. data/lib/cucumber/treetop_parser/feature_id.rb +0 -1951
  155. data/lib/cucumber/treetop_parser/feature_it.rb +0 -1951
  156. data/lib/cucumber/treetop_parser/feature_ja.rb +0 -1951
  157. data/lib/cucumber/treetop_parser/feature_ko.rb +0 -1951
  158. data/lib/cucumber/treetop_parser/feature_lt.rb +0 -1951
  159. data/lib/cucumber/treetop_parser/feature_nl.rb +0 -1951
  160. data/lib/cucumber/treetop_parser/feature_no.rb +0 -1951
  161. data/lib/cucumber/treetop_parser/feature_parser.rb +0 -36
  162. data/lib/cucumber/treetop_parser/feature_pl.rb +0 -1951
  163. data/lib/cucumber/treetop_parser/feature_pt.rb +0 -1951
  164. data/lib/cucumber/treetop_parser/feature_ro.rb +0 -1951
  165. data/lib/cucumber/treetop_parser/feature_ro2.rb +0 -1951
  166. data/lib/cucumber/treetop_parser/feature_ru.rb +0 -1951
  167. data/lib/cucumber/treetop_parser/feature_se.rb +0 -1951
  168. data/lib/cucumber/treetop_parser/feature_zh-CN.rb +0 -1951
  169. data/lib/cucumber/world/pending.rb +0 -22
  170. data/lib/cucumber/world.rb +0 -1
  171. data/setup.rb +0 -1585
  172. data/spec/cucumber/executor_spec.rb +0 -382
  173. data/spec/cucumber/formatters/html_formatter_spec.rb +0 -104
  174. data/spec/cucumber/formatters/pretty_formatter_spec.rb +0 -410
  175. data/spec/cucumber/formatters/progress_formatter_spec.rb +0 -81
  176. data/spec/cucumber/model/table_spec.rb +0 -32
  177. data/spec/cucumber/step_mother_spec.rb +0 -74
  178. data/spec/cucumber/tree/feature_spec.rb +0 -122
  179. data/spec/cucumber/tree/row_scenario_outline_spec.rb +0 -73
  180. data/spec/cucumber/tree/row_scenario_spec.rb +0 -55
  181. data/spec/cucumber/tree/row_step_outline_spec.rb +0 -38
  182. data/spec/cucumber/tree/scenario_outline_spec.rb +0 -50
  183. data/spec/cucumber/tree/scenario_spec.rb +0 -134
  184. data/spec/cucumber/tree/step_outline_spec.rb +0 -17
  185. data/spec/cucumber/tree/step_spec.rb +0 -59
  186. data/spec/cucumber/treetop_parser/feature_parser_spec.rb +0 -120
data/lib/cucumber.rb CHANGED
@@ -1,19 +1,66 @@
1
1
  $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
+ require 'yaml'
4
5
  require 'cucumber/platform'
5
6
  require 'rubygems'
6
- require 'treetop/runtime'
7
- require 'treetop/ruby_extensions'
7
+ require 'cucumber/parser'
8
8
  require 'cucumber/version'
9
- require 'cucumber/step_methods'
10
- require 'cucumber/tree'
11
- require 'cucumber/model'
12
- require 'cucumber/executor'
13
9
  require 'cucumber/step_mother'
14
- require 'cucumber/formatters'
15
- require 'cucumber/treetop_parser/feature_parser'
16
10
  require 'cucumber/cli'
17
11
  require 'cucumber/broadcaster'
18
- require 'cucumber/world'
19
12
  require 'cucumber/core_ext/exception'
13
+
14
+ module Cucumber
15
+ class << self
16
+ attr_reader :lang
17
+
18
+ def load_language(lang) #:nodoc:
19
+ return if @lang
20
+ @lang = lang
21
+ alias_step_definitions(lang)
22
+ Parser.load_parser(keyword_hash)
23
+ end
24
+
25
+ # File mode that accounts for Ruby platform and current language
26
+ def file_mode(m)
27
+ Cucumber::RUBY_1_9 ? "#{m}:#{keyword_hash['encoding']}" : m
28
+ end
29
+
30
+ # Returns a Hash of the currently active
31
+ # language, or for a specific language if +lang+ is
32
+ # specified.
33
+ def keyword_hash(lang=@lang)
34
+ LANGUAGES[lang]
35
+ end
36
+
37
+ def alias_step_definitions(lang) #:nodoc:
38
+ keywords = %w{given when then and but}.map{|keyword| keyword_hash(lang)[keyword]}
39
+ alias_steps(keywords)
40
+ end
41
+
42
+ # Sets up additional aliases for Given, When and Then.
43
+ # Try adding the following to your <tt>support/env.rb</tt>:
44
+ #
45
+ # # Given When Then in Norwegian
46
+ # Cucumber.alias_steps %w{Gitt Naar Saa}
47
+ #
48
+ # You cannot use special characters here, because methods
49
+ # with special characters is not valid Ruby code
50
+ #
51
+ def alias_steps(keywords)
52
+ keywords.each do |adverb|
53
+ StepMother.class_eval do
54
+ alias_method adverb, :register_step_definition
55
+ end
56
+
57
+ StepMother::WorldMethods.class_eval do
58
+ alias_method adverb, :__cucumber_invoke
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ # Make sure we always have English aliases
65
+ alias_step_definitions('en')
66
+ end
@@ -0,0 +1,54 @@
1
+ require 'cucumber/ast'
2
+ require 'cucumber/step_mother'
3
+
4
+ module Cucumber
5
+ module Ast
6
+ module FeatureFactory
7
+ class MyWorld
8
+ def flunk
9
+ raise "I flunked"
10
+ end
11
+ end
12
+
13
+ def create_feature(step_mother)
14
+ step_mother.extend(StepMother)
15
+ step_mother.Given /^a (.*) step with an inline arg:$/ do |what, table|
16
+ end
17
+ step_mother.Given /^a (.*) step$/ do |what|
18
+ flunk if what == 'failing'
19
+ end
20
+ step_mother.World do
21
+ MyWorld.new
22
+ end
23
+
24
+ table = Ast::Table.new([
25
+ %w{1 22 333},
26
+ %w{4444 55555 666666}
27
+ ])
28
+ py_string = Ast::PyString.new(21, 22, %{
29
+ I like
30
+ Cucumber sandwich
31
+ }, 10)
32
+ f = Ast::Feature.new(
33
+ Ast::Comment.new("# My feature comment\n"),
34
+ Ast::Tags.new(6, ['one', 'two']),
35
+ "Pretty printing",
36
+ [Ast::Scenario.new(
37
+ Ast::Comment.new(" # My scenario comment \n# On two lines \n"),
38
+ Ast::Tags.new(8, ['three', 'four']),
39
+ 9,
40
+ "Scenario:", "A Scenario",
41
+ [
42
+ Step.new(10, "Given", "a passing step with an inline arg:", table),
43
+ Step.new(11, "Given", "a happy step with an inline arg:", py_string),
44
+ Step.new(12, "Given", "a failing step")
45
+ ]
46
+ )]
47
+ )
48
+ f.file = 'features/pretty_printing.feature'
49
+ f.features = Features.new(Filter.new({:tags => []}))
50
+ f
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,60 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'cucumber/ast/feature_factory'
3
+
4
+ module Cucumber
5
+ module Ast
6
+ describe Feature do
7
+ include FeatureFactory
8
+
9
+ it "should convert to sexp" do
10
+ feature = create_feature(Object.new)
11
+ feature.to_sexp.should ==
12
+ [:feature,
13
+ "Pretty printing",
14
+ [:comment, "# My feature comment\n"],
15
+ [:tag, "one"],
16
+ [:tag, "two"],
17
+ [:scenario, 9, "Scenario:",
18
+ "A Scenario",
19
+ [:comment, " # My scenario comment \n# On two lines \n"],
20
+ [:tag, "three"],
21
+ [:tag, "four"],
22
+ [:step, 10, "Given", "a passing step with an inline arg:",
23
+ [:table,
24
+ [:row,
25
+ [:cell, "1"], [:cell, "22"], [:cell, "333"]],
26
+ [:row,
27
+ [:cell, "4444"], [:cell, "55555"], [:cell, "666666"]]]],
28
+ [:step, 11, "Given", "a happy step with an inline arg:",
29
+ [:py_string, "\n I like\nCucumber sandwich\n"]],
30
+ [:step, 12, "Given", "a failing step"]]]
31
+ end
32
+
33
+ it "should only visit scenarios that match" do
34
+ s1 = mock("Scenario 1")
35
+ s2 = mock("Scenario 2")
36
+ s3 = mock("Scenario 3")
37
+ [s1, s2, s3].each{|s| s.should_receive(:feature=)}
38
+ f = Ast::Feature.new(
39
+ Ast::Comment.new(""),
40
+ Ast::Tags.new(22, []),
41
+ "My feature",
42
+ [s1, s2, s3]
43
+ )
44
+ features = mock('Features')
45
+ f.features = features
46
+
47
+ f.lines = [33]
48
+
49
+ features.should_receive(:visit?).with(s1, [33]).and_return(false)
50
+ features.should_receive(:visit?).with(s2, [33]).and_return(true)
51
+ features.should_receive(:visit?).with(s3, [33]).and_return(false)
52
+
53
+ s2.should_receive(:accept)
54
+
55
+ visitor = Visitor.new(nil)
56
+ visitor.visit_feature(f)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'cucumber/ast/py_string'
3
+
4
+ module Cucumber
5
+ module Ast
6
+ describe PyString do
7
+ it "should handle unindented" do
8
+ ps = PyString.new(10, 13, "4.1\n4.2\n", 0)
9
+ ps.to_s.should == "4.1\n4.2\n"
10
+ end
11
+
12
+ it "should handle indented" do
13
+ # """
14
+ ps = PyString.new(10, 13, " 4.1\n 4.2\n", 2)
15
+ ps.to_s.should == " 4.1\n 4.2\n"
16
+ end
17
+
18
+ describe "replacing arguments" do
19
+
20
+ before(:each) do
21
+ @ps = PyString.new(10, 13, "<book>\n<qty>\n", 0)
22
+ end
23
+
24
+ it "should return a new py_string with arguments replaced with values" do
25
+ py_string_with_replaced_arg = @ps.arguments_replaced({'<book>' => 'Life is elsewhere', '<qty>' => '5'})
26
+
27
+ py_string_with_replaced_arg.to_s.should == "Life is elsewhere\n5\n"
28
+ end
29
+
30
+ it "should not change the original py_string" do
31
+ py_string_with_replaced_arg = @ps.arguments_replaced({'<book>' => 'Life is elsewhere'})
32
+
33
+ @ps.to_s.should_not include("Life is elsewhere")
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,64 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'cucumber/step_mother'
3
+ require 'cucumber/ast'
4
+ require 'cucumber/core_ext/string'
5
+
6
+ module Cucumber
7
+ module Ast
8
+ describe ScenarioOutline do
9
+ before do
10
+ @step_mother = Object.new
11
+ @step_mother.extend(StepMother)
12
+ @step_mother.Given(/^there are (\d+) cucumbers$/) do |n|
13
+ @initial = n.to_i
14
+ end
15
+ @step_mother.When(/^I eat (\d+) cucumbers$/) do |n|
16
+ @eaten = n.to_i
17
+ end
18
+ @step_mother.Then(/^I should have (\d+) cucumbers$/) do |n|
19
+ (@initial - @eaten).should == n.to_i
20
+ end
21
+ @step_mother.Then(/^I should have (\d+) cucumbers in my belly$/) do |n|
22
+ @eaten.should == n.to_i
23
+ end
24
+
25
+ @scenario_outline = ScenarioOutline.new(
26
+ Comment.new(""),
27
+ Tags.new(18, []),
28
+ 19,
29
+ "Scenario:", "My outline",
30
+ [
31
+ Step.new(20, 'Given', 'there are <start> cucumbers'),
32
+ Step.new(21, 'When', 'I eat <eat> cucumbers'),
33
+ Step.new(22, 'Then', 'I should have <left> cucumbers'),
34
+ Step.new(23, 'And', 'I should have <eat> cucumbers in my belly')
35
+ ],
36
+ [
37
+ [
38
+ 24,
39
+ 'Examples:',
40
+ 'First table',
41
+ [
42
+ %w{start eat left},
43
+ %w{12 5 7},
44
+ %w{20 6 14}
45
+ ]
46
+ ]
47
+ ]
48
+ )
49
+ end
50
+
51
+ it "should replace all variables and call outline once for each table row" do
52
+ visitor = Visitor.new(@step_mother)
53
+ visitor.should_receive(:visit_table_row).exactly(3).times
54
+ visitor.visit_feature_element(@scenario_outline)
55
+ end
56
+
57
+ it "should pretty print" do
58
+ require 'cucumber/formatter/pretty'
59
+ visitor = Formatter::Pretty.new(@step_mother, STDOUT, {:source => true})
60
+ visitor.visit_feature_element(@scenario_outline)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,82 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'cucumber/step_mother'
3
+ require 'cucumber/ast'
4
+
5
+ module Cucumber
6
+ module Ast
7
+ describe Scenario do
8
+ before do
9
+ @step_mother = Object.new
10
+ @step_mother.extend(StepMother)
11
+ $x = $y = nil
12
+ @step_mother.Before do
13
+ $x = 3
14
+ end
15
+ @step_mother.Given /y is (\d+)/ do |n|
16
+ $y = n.to_i
17
+ end
18
+ @visitor = Visitor.new(@step_mother)
19
+ @visitor.options = {}
20
+ end
21
+
22
+ it "should execute Before blocks before steps" do
23
+ scenario = Scenario.new(
24
+ comment=Comment.new(""),
25
+ tags=Tags.new(98,[]),
26
+ line=99,
27
+ keyword="",
28
+ name="",
29
+ steps=[
30
+ Step.new(7, "Given", "y is 5")
31
+ ])
32
+ @visitor.visit_feature_element(scenario)
33
+ $x.should == 3
34
+ $y.should == 5
35
+ end
36
+
37
+ it "should skip steps when previous is not passed" do
38
+ scenario = Scenario.new(
39
+ comment=Comment.new(""),
40
+ tags=Tags.new(98, []),
41
+ line=99,
42
+ keyword="",
43
+ name="",
44
+ steps=[
45
+ Step.new(7, "Given", "this is missing"),
46
+ Step.new(8, "Given", "y is 5")
47
+ ])
48
+ @visitor.visit_feature_element(scenario)
49
+
50
+ $x.should == 3
51
+ $y.should == nil
52
+ end
53
+
54
+ it "should be at exact line" do
55
+ s = Scenario.new(comment=Comment.new(""),
56
+ tags=Tags.new(44, []), 45, keyword="", name="", steps=[])
57
+
58
+ s.should be_at_lines([44])
59
+ s.should be_at_lines([45])
60
+ end
61
+
62
+ it "should be at line if tags or steps are" do
63
+ s = Scenario.new(
64
+ comment=Comment.new(""),
65
+ tags=Tags.new(43, []),
66
+ line=45,
67
+ keyword="",
68
+ name="",
69
+ steps=[
70
+ Step.new(46, "Given", ""),
71
+ Step.new(47, "Given", ""),
72
+ Step.new(48, "Given", ""),
73
+ ]
74
+ )
75
+
76
+ s.should be_at_lines([43])
77
+ s.should be_at_lines([47])
78
+ s.should_not be_at_lines([49])
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'cucumber/step_mother'
3
+ require 'cucumber/ast'
4
+ require 'cucumber/core_ext/string'
5
+
6
+ module Cucumber
7
+ module Ast
8
+ describe StepMother do
9
+ it "should calculate comment padding" do
10
+ scenario = Scenario.new(comment=nil, tags=nil, line=nil, keyword='Given', name='Gazpacho', steps=[
11
+ Step.new(22, "Given", "tøtal 13"),
12
+ Step.new(23, "And", "the total 15")
13
+ ])
14
+ step1, step2 = *scenario.instance_variable_get('@steps')
15
+
16
+ step1.source_indent.should == 2
17
+ step2.source_indent.should == 0
18
+ end
19
+ end
20
+
21
+ describe Step do
22
+ describe "execute step with arguments" do
23
+
24
+ it "should replace arguments in multiline args" do
25
+ mock_multiline_arg = mock('multiline arg')
26
+ step = Step.new(23, 'Given', '<test>', mock_multiline_arg)
27
+
28
+ mock_multiline_arg.should_receive(:arguments_replaced).with({'<test>' => '10'}).and_return(mock_multiline_arg)
29
+
30
+ step.execute_with_arguments({'test' => '10'}, stub('world'), :passed, visitor=nil, line=-1)
31
+ end
32
+
33
+ it "should invoke step with replaced multiline args" do
34
+ mock_step_definition = mock('step definition')
35
+ mock_multiline_arg_replaced = mock('multiline arg replaced')
36
+ mock_multiline_arg = mock('multiline arg', :arguments_replaced => mock_multiline_arg_replaced)
37
+ step = Step.new(45, 'Given', '<test>', mock_multiline_arg)
38
+
39
+ step.execute_with_arguments({'test' => '10'}, stub('world'), :passed, visitor=nil, line=-1)
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,81 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'cucumber/ast/table'
3
+
4
+ module Cucumber
5
+ module Ast
6
+ describe Table do
7
+ before do
8
+ @table = Table.new([
9
+ %w{1 22 333},
10
+ %w{4444 55555 666666}
11
+ ])
12
+ @table.extend(Module.new{
13
+ attr_reader :raw
14
+ })
15
+ def @table.rows; super; end
16
+ def @table.columns; super; end
17
+ end
18
+
19
+ it "should have rows" do
20
+ @table.rows[0].map{|cell| cell.value}.should == %w{1 22 333}
21
+ end
22
+
23
+ it "should have columns" do
24
+ @table.columns[1].map{|cell| cell.value}.should == %w{22 55555}
25
+ end
26
+
27
+ it "should have same cell objects in rows and columns" do
28
+ # 666666
29
+ @table.rows[1].__send__(:[], 2).should equal(@table.columns[2].__send__(:[], 1))
30
+ end
31
+
32
+ it "should know about max width of a row" do
33
+ @table.columns[1].__send__(:width).should == 5
34
+ end
35
+
36
+ it "should be convertible to an array of hashes" do
37
+ @table.hashes.should == [
38
+ {'1' => '4444', '22' => '55555', '333' => '666666'}
39
+ ]
40
+ end
41
+
42
+ describe "replacing arguments" do
43
+
44
+ before(:each) do
45
+ @table = table = Table.new([
46
+ %w{qty book},
47
+ %w{<qty> <book>}
48
+ ])
49
+ end
50
+
51
+ it "should return a new table with arguments replaced with values" do
52
+ table_with_replaced_args = @table.arguments_replaced({'<book>' => 'Unbearable lightness of being', '<qty>' => '5'})
53
+
54
+ table_with_replaced_args.hashes[0]['book'].should == 'Unbearable lightness of being'
55
+ table_with_replaced_args.hashes[0]['qty'].should == '5'
56
+ end
57
+
58
+ it "should not change the original table" do
59
+ table_with_replaced_args = @table.arguments_replaced({'<book>' => 'Unbearable lightness of being'})
60
+
61
+ @table.hashes[0]['book'].should_not == 'Unbearable lightness of being'
62
+ end
63
+
64
+ end
65
+
66
+ it "should convert to sexp" do
67
+ @table.to_sexp.should ==
68
+ [:table,
69
+ [:row,
70
+ [:cell, "1"],
71
+ [:cell, "22"],
72
+ [:cell, "333"]
73
+ ],
74
+ [:row,
75
+ [:cell, "4444"],
76
+ [:cell, "55555"],
77
+ [:cell, "666666"]]]
78
+ end
79
+ end
80
+ end
81
+ end
@@ -4,24 +4,11 @@ module Cucumber
4
4
  describe Broadcaster do
5
5
 
6
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)
7
+ receiver = mock('receiver')
8
+ broadcaster = Broadcaster.new([receiver])
19
9
 
20
- mock_receiver.should_not_receive(:konbanwa)
21
- broadcaster.register(mock_receiver)
22
-
23
- broadcaster.konbanwa()
10
+ receiver.should_receive(:konbanwa).with('good evening')
11
+ broadcaster.konbanwa('good evening')
24
12
  end
25
-
26
13
  end
27
14
  end