aslakhellesoy-cucumber 0.2.3.1 → 0.2.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/History.txt +23 -2
  2. data/Manifest.txt +47 -47
  3. data/examples/i18n/ru/features/support/world.rb +4 -3
  4. data/examples/sinatra/features/support/env.rb +2 -6
  5. data/examples/test_unit/features/step_definitions/test_unit_steps.rb +1 -4
  6. data/lib/cucumber/ast/py_string.rb +1 -6
  7. data/lib/cucumber/ast/step.rb +3 -5
  8. data/lib/cucumber/ast/step_invocation.rb +1 -2
  9. data/lib/cucumber/ast/table.rb +0 -13
  10. data/lib/cucumber/ast/visitor.rb +12 -6
  11. data/lib/cucumber/formatter/html.rb +16 -6
  12. data/lib/cucumber/formatter/pretty.rb +9 -3
  13. data/lib/cucumber/languages.yml +4 -4
  14. data/lib/cucumber/step_mother.rb +85 -18
  15. data/lib/cucumber/version.rb +1 -1
  16. data/rails_generators/cucumber/templates/paths.rb +13 -4
  17. data/{specs → spec}/cucumber/ast/background_spec.rb +0 -0
  18. data/{specs → spec}/cucumber/ast/feature_factory.rb +0 -0
  19. data/{specs → spec}/cucumber/ast/feature_spec.rb +0 -0
  20. data/{specs → spec}/cucumber/ast/py_string_spec.rb +0 -0
  21. data/{specs → spec}/cucumber/ast/scenario_outline_spec.rb +0 -0
  22. data/{specs → spec}/cucumber/ast/scenario_spec.rb +0 -0
  23. data/{specs → spec}/cucumber/ast/step_collection_spec.rb +0 -0
  24. data/{specs → spec}/cucumber/ast/step_spec.rb +0 -0
  25. data/{specs → spec}/cucumber/ast/table_spec.rb +0 -0
  26. data/{specs → spec}/cucumber/ast/tags_spec.rb +0 -0
  27. data/{specs → spec}/cucumber/broadcaster_spec.rb +0 -0
  28. data/{specs → spec}/cucumber/cli/configuration_spec.rb +0 -0
  29. data/{specs → spec}/cucumber/cli/main_spec.rb +0 -0
  30. data/{specs → spec}/cucumber/core_ext/proc_spec.rb +1 -1
  31. data/{specs → spec}/cucumber/core_ext/string_spec.rb +0 -0
  32. data/{specs → spec}/cucumber/formatter/ansicolor_spec.rb +0 -0
  33. data/{specs → spec}/cucumber/formatter/color_io_spec.rb +0 -0
  34. data/{specs → spec}/cucumber/formatter/html/cucumber.css +0 -0
  35. data/{specs → spec}/cucumber/formatter/html/cucumber.js +0 -0
  36. data/{specs → spec}/cucumber/formatter/html/index.html +0 -0
  37. data/{specs → spec}/cucumber/formatter/html/jquery-1.3.min.js +0 -0
  38. data/{specs → spec}/cucumber/formatter/html/jquery.uitableedit.js +0 -0
  39. data/{specs → spec}/cucumber/formatters/profile_formatter_spec.rb +0 -0
  40. data/{specs → spec}/cucumber/parser/feature_parser_spec.rb +0 -0
  41. data/{specs → spec}/cucumber/parser/table_parser_spec.rb +0 -0
  42. data/{specs → spec}/cucumber/rails/stubs/mini_rails.rb +0 -0
  43. data/{specs → spec}/cucumber/rails/stubs/test_help.rb +0 -0
  44. data/{specs → spec}/cucumber/rails/world_spec.rb +0 -0
  45. data/{specs → spec}/cucumber/sell_cucumbers.feature +0 -0
  46. data/{specs → spec}/cucumber/step_definition_spec.rb +0 -0
  47. data/{specs → spec}/cucumber/step_mother_spec.rb +41 -6
  48. data/{specs → spec}/cucumber/treetop_parser/empty_feature.feature +0 -0
  49. data/{specs → spec}/cucumber/treetop_parser/empty_scenario.feature +0 -0
  50. data/{specs → spec}/cucumber/treetop_parser/empty_scenario_outline.feature +0 -0
  51. data/{specs → spec}/cucumber/treetop_parser/fit_scenario.feature +0 -0
  52. data/{specs → spec}/cucumber/treetop_parser/given_scenario.feature +0 -0
  53. data/{specs → spec}/cucumber/treetop_parser/invalid_scenario_outlines.feature +0 -0
  54. data/{specs → spec}/cucumber/treetop_parser/multiline_steps.feature +0 -0
  55. data/{specs → spec}/cucumber/treetop_parser/multiple_tables.feature +0 -0
  56. data/{specs → spec}/cucumber/treetop_parser/scenario_outline.feature +0 -0
  57. data/{specs → spec}/cucumber/treetop_parser/spaces.feature +0 -0
  58. data/{specs → spec}/cucumber/treetop_parser/test_dos.feature +0 -0
  59. data/{specs → spec}/cucumber/treetop_parser/with_comments.feature +0 -0
  60. data/{specs → spec}/cucumber/treetop_parser/with_tags.feature +0 -0
  61. data/{specs → spec}/cucumber/world/pending_spec.rb +0 -0
  62. data/{specs → spec}/spec.opts +0 -0
  63. data/{specs → spec}/spec_helper.rb +0 -0
  64. metadata +49 -49
data/History.txt CHANGED
@@ -1,12 +1,33 @@
1
- == 0.2.4 (In Git)
1
+ == 0.3.0 (In Git)
2
+
3
+ This release has some minor changes to the APIs, but big enough that a new major release is in order.
4
+ The biggest change is the new semantics of the #World method. Previously you would call this method
5
+ several times, passing a Proc and extending the world object of the previous one with a Ruby module.
6
+ The problem was that there was no nice way to ensure the order in which these procs were called, which
7
+ led to some unexpected situations. In this release you can only register a single World proc. If you
8
+ want to extend a world with certain modules, you simply call the #World method with the module(s)
9
+ you wish to extend the World with. The Sinatra example illustrates how to do this.
10
+
11
+ The Visitor API (which is used for formatters) has also changed slightly. However, we have tried to
12
+ do this in a backwards compatible way, so if you have custom formatters for Cucumber 0.2 they should
13
+ still work.
2
14
 
3
15
  === New features
16
+ * Only a single World proc can be registered. World extension now happens by calling #World with ruby modules.
17
+ * Portuguese uses Funcionalidade in stead of Característica and accented words are aliased with unaccented ones (Alexandre da Silva and Felipe Coury).
4
18
  * The usage formatter also prints unused step definitions (Aslak Hellesøy)
5
19
  * Better exception if a World proc returns nil. (Aslak Hellesøy)
6
20
  * Allow Step Definitions to use |*varargs|, but only on Ruby 1.9. (Aslak Hellesøy)
7
- * Snippets for steps that use Step Tables or Pystrings include block param and object type hint comment (#247 Joseph Wilk)
21
+ * Snippets for steps that use Step Tables or PyStrings include block param and object type hint comment (#247 Joseph Wilk)
8
22
  * Support description string for Backgrounds (#271 Joseph Wilk)
9
23
 
24
+ === Removed/changed features
25
+ * The visitor API has changed slightly:
26
+ ** #visit_step_name, #visit_multiline_arg and #visit_exception are no longer official API methods.
27
+ ** #visit_step_result replaces those 3 methods.
28
+ ** Table and PyString no longer hold status information. Each visitor subclass should store state in @state if needed.
29
+ ** #visit_py_string no longer takes a status argument.
30
+
10
31
  == 0.2.3 2009-03-30
11
32
 
12
33
  This release sports 4 updated languages, slightly better help with snippets if you "quote" arguments
data/Manifest.txt CHANGED
@@ -286,50 +286,50 @@ rails_generators/feature/USAGE
286
286
  rails_generators/feature/feature_generator.rb
287
287
  rails_generators/feature/templates/feature.erb
288
288
  rails_generators/feature/templates/steps.erb
289
- specs/cucumber/ast/background_spec.rb
290
- specs/cucumber/ast/feature_factory.rb
291
- specs/cucumber/ast/feature_spec.rb
292
- specs/cucumber/ast/py_string_spec.rb
293
- specs/cucumber/ast/scenario_outline_spec.rb
294
- specs/cucumber/ast/scenario_spec.rb
295
- specs/cucumber/ast/step_collection_spec.rb
296
- specs/cucumber/ast/step_spec.rb
297
- specs/cucumber/ast/table_spec.rb
298
- specs/cucumber/ast/tags_spec.rb
299
- specs/cucumber/broadcaster_spec.rb
300
- specs/cucumber/cli/configuration_spec.rb
301
- specs/cucumber/cli/main_spec.rb
302
- specs/cucumber/core_ext/proc_spec.rb
303
- specs/cucumber/core_ext/string_spec.rb
304
- specs/cucumber/formatter/ansicolor_spec.rb
305
- specs/cucumber/formatter/color_io_spec.rb
306
- specs/cucumber/formatter/html/cucumber.css
307
- specs/cucumber/formatter/html/cucumber.js
308
- specs/cucumber/formatter/html/index.html
309
- specs/cucumber/formatter/html/jquery-1.3.min.js
310
- specs/cucumber/formatter/html/jquery.uitableedit.js
311
- specs/cucumber/formatters/profile_formatter_spec.rb
312
- specs/cucumber/parser/feature_parser_spec.rb
313
- specs/cucumber/parser/table_parser_spec.rb
314
- specs/cucumber/rails/stubs/mini_rails.rb
315
- specs/cucumber/rails/stubs/test_help.rb
316
- specs/cucumber/rails/world_spec.rb
317
- specs/cucumber/sell_cucumbers.feature
318
- specs/cucumber/step_definition_spec.rb
319
- specs/cucumber/step_mother_spec.rb
320
- specs/cucumber/treetop_parser/empty_feature.feature
321
- specs/cucumber/treetop_parser/empty_scenario.feature
322
- specs/cucumber/treetop_parser/empty_scenario_outline.feature
323
- specs/cucumber/treetop_parser/fit_scenario.feature
324
- specs/cucumber/treetop_parser/given_scenario.feature
325
- specs/cucumber/treetop_parser/invalid_scenario_outlines.feature
326
- specs/cucumber/treetop_parser/multiline_steps.feature
327
- specs/cucumber/treetop_parser/multiple_tables.feature
328
- specs/cucumber/treetop_parser/scenario_outline.feature
329
- specs/cucumber/treetop_parser/spaces.feature
330
- specs/cucumber/treetop_parser/test_dos.feature
331
- specs/cucumber/treetop_parser/with_comments.feature
332
- specs/cucumber/treetop_parser/with_tags.feature
333
- specs/cucumber/world/pending_spec.rb
334
- specs/spec.opts
335
- specs/spec_helper.rb
289
+ spec/cucumber/ast/background_spec.rb
290
+ spec/cucumber/ast/feature_factory.rb
291
+ spec/cucumber/ast/feature_spec.rb
292
+ spec/cucumber/ast/py_string_spec.rb
293
+ spec/cucumber/ast/scenario_outline_spec.rb
294
+ spec/cucumber/ast/scenario_spec.rb
295
+ spec/cucumber/ast/step_collection_spec.rb
296
+ spec/cucumber/ast/step_spec.rb
297
+ spec/cucumber/ast/table_spec.rb
298
+ spec/cucumber/ast/tags_spec.rb
299
+ spec/cucumber/broadcaster_spec.rb
300
+ spec/cucumber/cli/configuration_spec.rb
301
+ spec/cucumber/cli/main_spec.rb
302
+ spec/cucumber/core_ext/proc_spec.rb
303
+ spec/cucumber/core_ext/string_spec.rb
304
+ spec/cucumber/formatter/ansicolor_spec.rb
305
+ spec/cucumber/formatter/color_io_spec.rb
306
+ spec/cucumber/formatter/html/cucumber.css
307
+ spec/cucumber/formatter/html/cucumber.js
308
+ spec/cucumber/formatter/html/index.html
309
+ spec/cucumber/formatter/html/jquery-1.3.min.js
310
+ spec/cucumber/formatter/html/jquery.uitableedit.js
311
+ spec/cucumber/formatters/profile_formatter_spec.rb
312
+ spec/cucumber/parser/feature_parser_spec.rb
313
+ spec/cucumber/parser/table_parser_spec.rb
314
+ spec/cucumber/rails/stubs/mini_rails.rb
315
+ spec/cucumber/rails/stubs/test_help.rb
316
+ spec/cucumber/rails/world_spec.rb
317
+ spec/cucumber/sell_cucumbers.feature
318
+ spec/cucumber/step_definition_spec.rb
319
+ spec/cucumber/step_mother_spec.rb
320
+ spec/cucumber/treetop_parser/empty_feature.feature
321
+ spec/cucumber/treetop_parser/empty_scenario.feature
322
+ spec/cucumber/treetop_parser/empty_scenario_outline.feature
323
+ spec/cucumber/treetop_parser/fit_scenario.feature
324
+ spec/cucumber/treetop_parser/given_scenario.feature
325
+ spec/cucumber/treetop_parser/invalid_scenario_outlines.feature
326
+ spec/cucumber/treetop_parser/multiline_steps.feature
327
+ spec/cucumber/treetop_parser/multiple_tables.feature
328
+ spec/cucumber/treetop_parser/scenario_outline.feature
329
+ spec/cucumber/treetop_parser/spaces.feature
330
+ spec/cucumber/treetop_parser/test_dos.feature
331
+ spec/cucumber/treetop_parser/with_comments.feature
332
+ spec/cucumber/treetop_parser/with_tags.feature
333
+ spec/cucumber/world/pending_spec.rb
334
+ spec/spec.opts
335
+ spec/spec_helper.rb
@@ -1,7 +1,8 @@
1
1
  # encoding: utf-8
2
-
3
- World do
2
+ module LazyCalc
4
3
  def calc
5
4
  @calc ||= Calculator.new
6
5
  end
7
- end
6
+ end
7
+
8
+ World(LazyCalc)
@@ -16,9 +16,5 @@ Webrat.configure do |config|
16
16
  config.mode = :sinatra
17
17
  end
18
18
 
19
- World do
20
- session = Webrat::SinatraSession.new
21
- session.extend(Webrat::Matchers)
22
- session.extend(Webrat::HaveTagMatcher)
23
- session
24
- end
19
+ World{Webrat::SinatraSession.new}
20
+ World(Webrat::Matchers, Webrat::HaveTagMatcher)
@@ -1,8 +1,5 @@
1
1
  require 'test/unit/assertions'
2
- World do |o|
3
- o.extend(Test::Unit::Assertions)
4
- o
5
- end
2
+ World(Test::Unit::Assertions)
6
3
 
7
4
  Given /^(\w+) = (\w+)$/ do |var, value|
8
5
  instance_variable_set("@#{var}", value)
@@ -25,11 +25,6 @@ module Cucumber
25
25
  def initialize(start_line, end_line, string, quotes_indent)
26
26
  @start_line, @end_line = start_line, end_line
27
27
  @string, @quotes_indent = string.gsub(/\\"/, '"'), quotes_indent
28
- @status = :passed
29
- end
30
-
31
- def status=(status)
32
- @status = status
33
28
  end
34
29
 
35
30
  def to_s
@@ -41,7 +36,7 @@ module Cucumber
41
36
  end
42
37
 
43
38
  def accept(visitor)
44
- visitor.visit_py_string(to_s, @status)
39
+ visitor.visit_py_string(to_s)
45
40
  end
46
41
 
47
42
  def arguments_replaced(arguments) #:nodoc:
@@ -33,13 +33,11 @@ module Cucumber
33
33
  def accept(visitor)
34
34
  # The only time a Step is visited is when it is in a ScenarioOutline.
35
35
  # Otherwise it's always StepInvocation that gest visited instead.
36
- visit_step_details(visitor, first_match(visitor), @multiline_arg, :skipped, nil, nil)
36
+ visit_step_result(visitor, first_match(visitor), @multiline_arg, :skipped, nil, nil)
37
37
  end
38
38
 
39
- def visit_step_details(visitor, step_match, multiline_arg, status, exception, background)
40
- visitor.visit_step_name(@keyword, step_match, status, source_indent, background)
41
- visitor.visit_multiline_arg(@multiline_arg) if @multiline_arg
42
- visitor.visit_exception(exception, status) if exception
39
+ def visit_step_result(visitor, step_match, multiline_arg, status, exception, background)
40
+ visitor.visit_step_result(@keyword, step_match, @multiline_arg, status, exception, source_indent, background)
43
41
  end
44
42
 
45
43
  def first_match(visitor)
@@ -20,7 +20,7 @@ module Cucumber
20
20
 
21
21
  def accept(visitor)
22
22
  invoke(visitor.step_mother, visitor.options)
23
- @step.visit_step_details(visitor, @step_match, @multiline_arg, @status, @exception, @background)
23
+ @step.visit_step_result(visitor, @step_match, @multiline_arg, @status, @exception, @background)
24
24
  end
25
25
 
26
26
  def invoke(step_mother, options)
@@ -68,7 +68,6 @@ module Cucumber
68
68
 
69
69
  def status!(status)
70
70
  @status = status
71
- @multiline_arg.status = status if @multiline_arg
72
71
  @matched_cells.each do |cell|
73
72
  cell.status = status
74
73
  end
@@ -116,12 +116,6 @@ module Cucumber
116
116
  nil
117
117
  end
118
118
 
119
- def status=(status)
120
- cells_rows.each do |row|
121
- row.status = status
122
- end
123
- end
124
-
125
119
  # For testing only
126
120
  def to_sexp #:nodoc:
127
121
  [:table, *cells_rows.map{|row| row.to_sexp}]
@@ -293,12 +287,6 @@ module Cucumber
293
287
  "row_#{line}"
294
288
  end
295
289
 
296
- def status=(status)
297
- each do |cell|
298
- cell.status = status
299
- end
300
- end
301
-
302
290
  private
303
291
 
304
292
  def index
@@ -320,7 +308,6 @@ module Cucumber
320
308
 
321
309
  def initialize(value, table, row, col, line)
322
310
  @value, @table, @row, @col, @line = value, table, row, col, line
323
- @status = :passed
324
311
  end
325
312
 
326
313
  def accept(visitor)
@@ -93,14 +93,23 @@ module Cucumber
93
93
  step.accept(self)
94
94
  end
95
95
 
96
- def visit_step_name(keyword, step_match, status, source_indent, background)
96
+ def visit_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background)
97
+ visit_step_name(keyword, step_match, status, source_indent, background)
98
+ visit_multiline_arg(multiline_arg) if multiline_arg
99
+ visit_exception(exception, status) if exception
97
100
  end
98
101
 
99
- def visit_multiline_arg(multiline_arg)
102
+ def visit_step_name(keyword, step_match, status, source_indent, background) #:nodoc:
103
+ end
104
+
105
+ def visit_multiline_arg(multiline_arg) #:nodoc:
100
106
  multiline_arg.accept(self)
101
107
  end
102
108
 
103
- def visit_py_string(string, status)
109
+ def visit_exception(exception, status) #:nodoc:
110
+ end
111
+
112
+ def visit_py_string(string)
104
113
  end
105
114
 
106
115
  def visit_table_row(table_row)
@@ -114,9 +123,6 @@ module Cucumber
114
123
  def visit_table_cell_value(value, width, status)
115
124
  end
116
125
 
117
- def visit_exception(exception, status)
118
- end
119
-
120
126
  def announce(announcement)
121
127
  end
122
128
 
@@ -1,3 +1,4 @@
1
+ require 'erb'
1
2
  begin
2
3
  require 'builder'
3
4
  rescue LoadError
@@ -8,6 +9,8 @@ end
8
9
  module Cucumber
9
10
  module Formatter
10
11
  class Html < Ast::Visitor
12
+ include ERB::Util # for the #h method
13
+
11
14
  def initialize(step_mother, io, options)
12
15
  super(step_mother)
13
16
  @builder = Builder::XmlMarkup.new(:target => io, :indent => 2)
@@ -93,7 +96,12 @@ module Cucumber
93
96
 
94
97
  def visit_step(step)
95
98
  @step_id = step.dom_id
96
- @builder.li(:id => @step_id) do
99
+ super
100
+ end
101
+
102
+ def visit_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background)
103
+ @status = status
104
+ @builder.li(:id => @step_id, :class => status) do
97
105
  super
98
106
  end
99
107
  end
@@ -105,8 +113,8 @@ module Cucumber
105
113
 
106
114
  unless @skip_step
107
115
  step_name = step_match.format_args(lambda{|param| "<span>#{param}</span>"})
108
- @builder.div(:class => status) do |div|
109
- div << "#{keyword} #{step_name}"
116
+ @builder.div do |div|
117
+ div << h("#{keyword} #{step_name}")
110
118
  end
111
119
  end
112
120
  end
@@ -126,8 +134,8 @@ module Cucumber
126
134
  end
127
135
  end
128
136
 
129
- def visit_py_string(string, status)
130
- @builder.pre(:class => status) do |pre|
137
+ def visit_py_string(string)
138
+ @builder.pre(:class => @status) do |pre|
131
139
  pre << string
132
140
  end
133
141
  end
@@ -152,7 +160,9 @@ module Cucumber
152
160
 
153
161
  def visit_table_cell_value(value, width, status)
154
162
  cell_type = @outline_row == 0 ? :th : :td
155
- @builder.__send__(cell_type, value, :class => status, :id => "#{@row_id}_#{@col_index}")
163
+ attributes = {:id => "#{@row_id}_#{@col_index}"}
164
+ attributes[:class] = status if status
165
+ @builder.__send__(cell_type, value, attributes)
156
166
  @col_index += 1
157
167
  end
158
168
 
@@ -119,6 +119,11 @@ module Cucumber
119
119
  super
120
120
  end
121
121
 
122
+ def visit_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background)
123
+ @status = status
124
+ super
125
+ end
126
+
122
127
  def visit_step_name(keyword, step_match, status, source_indent, background)
123
128
  @step_matches ||= []
124
129
  non_failed_background_step_outside_background = !@in_background && background && (status != :failed)
@@ -150,14 +155,15 @@ module Cucumber
150
155
  print_exception(table_row.exception, :failed, @indent) if table_row.exception
151
156
  end
152
157
 
153
- def visit_py_string(string, status)
154
- s = "\"\"\"\n#{string}\n\"\"\"".indent(@indent)
158
+ def visit_py_string(string)
159
+ s = %{"""\n#{string}\n"""}.indent(@indent)
155
160
  s = s.split("\n").map{|l| l =~ /^\s+$/ ? '' : l}.join("\n")
156
- @io.puts(format_string(s, status))
161
+ @io.puts(format_string(s, @status))
157
162
  @io.flush
158
163
  end
159
164
 
160
165
  def visit_table_cell_value(value, width, status)
166
+ status ||= @status || :passed
161
167
  @io.print(' ' + format_string((value.to_s || '').ljust(width), status) + " #{@delim}")
162
168
  @io.flush
163
169
  end
@@ -311,13 +311,13 @@
311
311
  native: português
312
312
  encoding: UTF-8
313
313
  background: Contexto
314
- feature: Característica
315
- scenario: Cenário
316
- scenario_outline: Esquema do Cenário
314
+ feature: Funcionalidade
315
+ scenario: Cenário|Cenario
316
+ scenario_outline: Esquema do Cenário|Esquema do Cenario
317
317
  examples: Exemplos
318
318
  given: Dado
319
319
  when: Quando
320
- then: Então
320
+ then: Então|Entao
321
321
  and: E
322
322
  but: Mas
323
323
  space_after_keyword: true
@@ -51,6 +51,17 @@ module Cucumber
51
51
  end
52
52
  end
53
53
 
54
+ class MultipleWorld < StandardError
55
+ def initialize(first_proc, second_proc)
56
+ message = "You can only pass a proc to #World once, but it's happening\n"
57
+ message << "in 2 places:\n\n"
58
+ message << first_proc.backtrace_line('World') << "\n"
59
+ message << second_proc.backtrace_line('World') << "\n\n"
60
+ message << "Use Ruby modules instead to extend your worlds. See the #World RDoc.\n\n"
61
+ super(message)
62
+ end
63
+ end
64
+
54
65
  # This is the main interface for registering step definitions, which is done
55
66
  # from <tt>*_steps.rb</tt> files. This module is included right at the top-level
56
67
  # so #register_step_definition (and more interestingly - its aliases) are
@@ -111,10 +122,46 @@ module Cucumber
111
122
  (@after_procs ||= []).unshift(proc)
112
123
  end
113
124
 
114
- # Registers a World proc. You can call this method as many times as you
115
- # want (typically from ruby scripts under <tt>support</tt>).
116
- def World(&proc)
117
- (@world_procs ||= []) << proc
125
+ # Registers any number of +world_modules+ (Ruby Modules) and/or a Proc.
126
+ # The +proc+ will be executed once before each scenario to create an
127
+ # Object that the scenario's steps will run within. Any +world_modules+
128
+ # will be mixed into this Object (via Object#extend).
129
+ #
130
+ # This method is typically called from one or more Ruby scripts under
131
+ # <tt>features/support</tt>. You can call this method as many times as you
132
+ # like (to register more modules), but if you try to register more than
133
+ # one Proc you will get an error.
134
+ #
135
+ # Cucumber will not yield anything to the +proc+ (like it used to do before v0.3).
136
+ #
137
+ # In earlier versions of Cucumber (before 0.3) you could not register
138
+ # any +world_modules+. Instead you would register several Proc objects (by
139
+ # calling the method several times). The result of each +proc+ would be yielded
140
+ # to the next +proc+. Example:
141
+ #
142
+ # World do |world| # NOT SUPPORTED FROM 0.3
143
+ # MyClass.new
144
+ # end
145
+ #
146
+ # World do |world| # NOT SUPPORTED FROM 0.3
147
+ # world.extend(MyModule)
148
+ # end
149
+ #
150
+ # From Cucumber 0.3 the recommended way to do this is:
151
+ #
152
+ # World do
153
+ # MyClass.new
154
+ # end
155
+ #
156
+ # World(MyModule)
157
+ #
158
+ def World(*world_modules, &proc)
159
+ if(proc)
160
+ raise MultipleWorld.new(@world_proc, proc) if @world_proc
161
+ @world_proc = proc
162
+ end
163
+ @world_modules ||= []
164
+ @world_modules += world_modules
118
165
  end
119
166
 
120
167
  def current_world
@@ -174,26 +221,46 @@ module Cucumber
174
221
 
175
222
  # Creates a new world instance
176
223
  def new_world!
177
- @current_world = Object.new
178
- (@world_procs ||= []).each do |proc|
179
- @current_world = proc.call(@current_world)
180
- if @current_world.nil?
181
- begin
182
- raise NilWorld.new
183
- rescue NilWorld => e
184
- e.backtrace.clear
185
- e.backtrace.push(proc.backtrace_line("World"))
186
- raise e
187
- end
188
- end
224
+ create_world!
225
+ extend_world
226
+ connect_world
227
+ @current_world
228
+ end
229
+
230
+ def create_world!
231
+ if(@world_proc)
232
+ @current_world = @world_proc.call
233
+ check_nil(@current_world, @world_proc)
234
+ else
235
+ @current_world = Object.new
189
236
  end
237
+ end
190
238
 
239
+ def extend_world
191
240
  @current_world.extend(World)
241
+ @current_world.extend(::Spec::Matchers) if defined?(::Spec::Matchers)
242
+ (@world_modules || []).each do |mod|
243
+ @current_world.extend(mod)
244
+ end
245
+ end
246
+
247
+ def connect_world
192
248
  @current_world.__cucumber_step_mother = self
193
249
  @current_world.__cucumber_visitor = @visitor
250
+ end
194
251
 
195
- @current_world.extend(::Spec::Matchers) if defined?(::Spec::Matchers)
196
- @current_world
252
+ def check_nil(o, proc)
253
+ if o.nil?
254
+ begin
255
+ raise NilWorld.new
256
+ rescue NilWorld => e
257
+ e.backtrace.clear
258
+ e.backtrace.push(proc.backtrace_line("World"))
259
+ raise e
260
+ end
261
+ else
262
+ o
263
+ end
197
264
  end
198
265
 
199
266
  def nil_world!
@@ -3,7 +3,7 @@ module Cucumber #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
5
  TINY = 3
6
- PATCH = 1 # Set to nil for official release
6
+ PATCH = 2 # Set to nil for official release
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
9
9
  end
@@ -1,4 +1,16 @@
1
1
  module NavigationHelpers
2
+ # Maps a static name to a static route.
3
+ #
4
+ # This method is *not* designed to map from a dynamic name to a
5
+ # dynamic route like <tt>post_comments_path(post)</tt>. For dynamic
6
+ # routes like this you should *not* rely on #path_to, but write
7
+ # your own step definitions instead. Example:
8
+ #
9
+ # Given /I am on the comments page for the "(.+)" post/ |name|
10
+ # post = Post.find_by_name(name)
11
+ # visit post_comments_path(post)
12
+ # end
13
+ #
2
14
  def path_to(page_name)
3
15
  case page_name
4
16
 
@@ -14,7 +26,4 @@ module NavigationHelpers
14
26
  end
15
27
  end
16
28
 
17
- World do |world|
18
- world.extend NavigationHelpers
19
- world
20
- end
29
+ World(NavigationHelpers)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -4,7 +4,7 @@ require 'cucumber/core_ext/instance_exec'
4
4
  describe Proc do
5
5
  it "should remove extraneous path info for file" do
6
6
  proc = lambda {|a,b|}
7
- proc.file_colon_line.should =~ /^specs\/cucumber\/core_ext\/proc_spec\.rb:6/
7
+ proc.file_colon_line.should =~ /^spec\/cucumber\/core_ext\/proc_spec\.rb:6/
8
8
  end
9
9
 
10
10
  it "should raise ArityMismatchError for too many args (expecting 0)" do
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -27,8 +27,8 @@ module Cucumber
27
27
  @step_mother.step_match("Three blind mice")
28
28
  end.should raise_error(Ambiguous, %{Ambiguous match of "Three blind mice":
29
29
 
30
- specs/cucumber/step_mother_spec.rb:23:in `/Three (.*) mice/'
31
- specs/cucumber/step_mother_spec.rb:24:in `/Three blind (.*)/'
30
+ spec/cucumber/step_mother_spec.rb:23:in `/Three (.*) mice/'
31
+ spec/cucumber/step_mother_spec.rb:24:in `/Three blind (.*)/'
32
32
 
33
33
  You can run again with --guess to make Cucumber be more smart about it
34
34
  })
@@ -43,8 +43,8 @@ You can run again with --guess to make Cucumber be more smart about it
43
43
  @step_mother.step_match("Three cute mice")
44
44
  end.should raise_error(Ambiguous, %{Ambiguous match of "Three cute mice":
45
45
 
46
- specs/cucumber/step_mother_spec.rb:39:in `/Three (.*) mice/'
47
- specs/cucumber/step_mother_spec.rb:40:in `/Three cute (.*)/'
46
+ spec/cucumber/step_mother_spec.rb:39:in `/Three (.*) mice/'
47
+ spec/cucumber/step_mother_spec.rb:40:in `/Three cute (.*)/'
48
48
 
49
49
  })
50
50
  end
@@ -93,10 +93,45 @@ specs/cucumber/step_mother_spec.rb:40:in `/Three cute (.*)/'
93
93
  begin
94
94
  @step_mother.before_and_after(nil)
95
95
  raise "Should fail"
96
- rescue => e
96
+ rescue NilWorld => e
97
97
  e.message.should == "World procs should never return nil"
98
- e.backtrace.should == ["specs/cucumber/step_mother_spec.rb:90:in `World'"]
98
+ e.backtrace.should == ["spec/cucumber/step_mother_spec.rb:90:in `World'"]
99
99
  end
100
100
  end
101
+
102
+ module ModuleOne
103
+ end
104
+
105
+ module ModuleTwo
106
+ end
107
+
108
+ class ClassOne
109
+ end
110
+
111
+ it "should implicitly extend world with modules" do
112
+ @step_mother.World(ModuleOne, ModuleTwo)
113
+
114
+ w = @step_mother.__send__(:new_world!)
115
+ class << w
116
+ included_modules.index(ModuleOne).should_not == nil
117
+ included_modules.index(ModuleTwo).should_not == nil
118
+ end
119
+ w.class.should == Object
120
+ end
121
+
122
+ it "should raise error when we try to register more than one World proc" do
123
+ @step_mother.World { Hash.new }
124
+ lambda do
125
+ @step_mother.World { Array.new }
126
+ end.should raise_error(MultipleWorld, %{You can only pass a proc to #World once, but it's happening
127
+ in 2 places:
128
+
129
+ spec/cucumber/step_mother_spec.rb:123:in `World'
130
+ spec/cucumber/step_mother_spec.rb:125:in `World'
131
+
132
+ Use Ruby modules instead to extend your worlds. See the #World RDoc.
133
+
134
+ })
135
+ end
101
136
  end
102
137
  end
File without changes
File without changes
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aslakhellesoy-cucumber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3.1
4
+ version: 0.2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Aslak Helles\xC3\xB8y"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-02 00:00:00 -07:00
12
+ date: 2009-04-06 00:00:00 -07:00
13
13
  default_executable: cucumber
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -373,53 +373,53 @@ files:
373
373
  - rails_generators/feature/feature_generator.rb
374
374
  - rails_generators/feature/templates/feature.erb
375
375
  - rails_generators/feature/templates/steps.erb
376
- - specs/cucumber/ast/background_spec.rb
377
- - specs/cucumber/ast/feature_factory.rb
378
- - specs/cucumber/ast/feature_spec.rb
379
- - specs/cucumber/ast/py_string_spec.rb
380
- - specs/cucumber/ast/scenario_outline_spec.rb
381
- - specs/cucumber/ast/scenario_spec.rb
382
- - specs/cucumber/ast/step_collection_spec.rb
383
- - specs/cucumber/ast/step_spec.rb
384
- - specs/cucumber/ast/table_spec.rb
385
- - specs/cucumber/ast/tags_spec.rb
386
- - specs/cucumber/broadcaster_spec.rb
387
- - specs/cucumber/cli/configuration_spec.rb
388
- - specs/cucumber/cli/main_spec.rb
389
- - specs/cucumber/core_ext/proc_spec.rb
390
- - specs/cucumber/core_ext/string_spec.rb
391
- - specs/cucumber/formatter/ansicolor_spec.rb
392
- - specs/cucumber/formatter/color_io_spec.rb
393
- - specs/cucumber/formatter/html/cucumber.css
394
- - specs/cucumber/formatter/html/cucumber.js
395
- - specs/cucumber/formatter/html/index.html
396
- - specs/cucumber/formatter/html/jquery-1.3.min.js
397
- - specs/cucumber/formatter/html/jquery.uitableedit.js
398
- - specs/cucumber/formatters/profile_formatter_spec.rb
399
- - specs/cucumber/parser/feature_parser_spec.rb
400
- - specs/cucumber/parser/table_parser_spec.rb
401
- - specs/cucumber/rails/stubs/mini_rails.rb
402
- - specs/cucumber/rails/stubs/test_help.rb
403
- - specs/cucumber/rails/world_spec.rb
404
- - specs/cucumber/sell_cucumbers.feature
405
- - specs/cucumber/step_definition_spec.rb
406
- - specs/cucumber/step_mother_spec.rb
407
- - specs/cucumber/treetop_parser/empty_feature.feature
408
- - specs/cucumber/treetop_parser/empty_scenario.feature
409
- - specs/cucumber/treetop_parser/empty_scenario_outline.feature
410
- - specs/cucumber/treetop_parser/fit_scenario.feature
411
- - specs/cucumber/treetop_parser/given_scenario.feature
412
- - specs/cucumber/treetop_parser/invalid_scenario_outlines.feature
413
- - specs/cucumber/treetop_parser/multiline_steps.feature
414
- - specs/cucumber/treetop_parser/multiple_tables.feature
415
- - specs/cucumber/treetop_parser/scenario_outline.feature
416
- - specs/cucumber/treetop_parser/spaces.feature
417
- - specs/cucumber/treetop_parser/test_dos.feature
418
- - specs/cucumber/treetop_parser/with_comments.feature
419
- - specs/cucumber/treetop_parser/with_tags.feature
420
- - specs/cucumber/world/pending_spec.rb
421
- - specs/spec.opts
422
- - specs/spec_helper.rb
376
+ - spec/cucumber/ast/background_spec.rb
377
+ - spec/cucumber/ast/feature_factory.rb
378
+ - spec/cucumber/ast/feature_spec.rb
379
+ - spec/cucumber/ast/py_string_spec.rb
380
+ - spec/cucumber/ast/scenario_outline_spec.rb
381
+ - spec/cucumber/ast/scenario_spec.rb
382
+ - spec/cucumber/ast/step_collection_spec.rb
383
+ - spec/cucumber/ast/step_spec.rb
384
+ - spec/cucumber/ast/table_spec.rb
385
+ - spec/cucumber/ast/tags_spec.rb
386
+ - spec/cucumber/broadcaster_spec.rb
387
+ - spec/cucumber/cli/configuration_spec.rb
388
+ - spec/cucumber/cli/main_spec.rb
389
+ - spec/cucumber/core_ext/proc_spec.rb
390
+ - spec/cucumber/core_ext/string_spec.rb
391
+ - spec/cucumber/formatter/ansicolor_spec.rb
392
+ - spec/cucumber/formatter/color_io_spec.rb
393
+ - spec/cucumber/formatter/html/cucumber.css
394
+ - spec/cucumber/formatter/html/cucumber.js
395
+ - spec/cucumber/formatter/html/index.html
396
+ - spec/cucumber/formatter/html/jquery-1.3.min.js
397
+ - spec/cucumber/formatter/html/jquery.uitableedit.js
398
+ - spec/cucumber/formatters/profile_formatter_spec.rb
399
+ - spec/cucumber/parser/feature_parser_spec.rb
400
+ - spec/cucumber/parser/table_parser_spec.rb
401
+ - spec/cucumber/rails/stubs/mini_rails.rb
402
+ - spec/cucumber/rails/stubs/test_help.rb
403
+ - spec/cucumber/rails/world_spec.rb
404
+ - spec/cucumber/sell_cucumbers.feature
405
+ - spec/cucumber/step_definition_spec.rb
406
+ - spec/cucumber/step_mother_spec.rb
407
+ - spec/cucumber/treetop_parser/empty_feature.feature
408
+ - spec/cucumber/treetop_parser/empty_scenario.feature
409
+ - spec/cucumber/treetop_parser/empty_scenario_outline.feature
410
+ - spec/cucumber/treetop_parser/fit_scenario.feature
411
+ - spec/cucumber/treetop_parser/given_scenario.feature
412
+ - spec/cucumber/treetop_parser/invalid_scenario_outlines.feature
413
+ - spec/cucumber/treetop_parser/multiline_steps.feature
414
+ - spec/cucumber/treetop_parser/multiple_tables.feature
415
+ - spec/cucumber/treetop_parser/scenario_outline.feature
416
+ - spec/cucumber/treetop_parser/spaces.feature
417
+ - spec/cucumber/treetop_parser/test_dos.feature
418
+ - spec/cucumber/treetop_parser/with_comments.feature
419
+ - spec/cucumber/treetop_parser/with_tags.feature
420
+ - spec/cucumber/world/pending_spec.rb
421
+ - spec/spec.opts
422
+ - spec/spec_helper.rb
423
423
  has_rdoc: true
424
424
  homepage: http://cukes.info
425
425
  post_install_message: