rspec 1.2.9 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. data/History.rdoc +51 -1
  2. data/License.txt +1 -1
  3. data/Manifest.txt +11 -4
  4. data/README.rdoc +10 -24
  5. data/Rakefile +17 -13
  6. data/Upgrade.rdoc +63 -2
  7. data/examples/passing/shared_example_group_example.rb +0 -36
  8. data/examples/passing/simple_matcher_example.rb +3 -3
  9. data/features/formatters/nested_formatter.feature +32 -0
  10. data/features/interop/cucumber_stubs_dont_leak.feature +11 -0
  11. data/features/interop/test_but_not_test_unit.feature +1 -1
  12. data/features/interop/test_case_with_should_methods.feature +1 -1
  13. data/features/matchers/define_matcher_with_fluent_interface.feature +21 -0
  14. data/features/matchers/define_wrapped_matcher.feature +28 -1
  15. data/features/matchers/match_unless_raises.feature +60 -0
  16. data/features/matchers/match_unless_raises_unexpected_error.feature +39 -0
  17. data/features/mocks/block_local_expectations.feature +62 -0
  18. data/features/step_definitions/running_rspec_steps.rb +9 -0
  19. data/features/step_definitions/stubbing_steps.rb +16 -0
  20. data/features/support/env.rb +1 -0
  21. data/features/support/matchers/smart_match.rb +23 -4
  22. data/geminstaller.yml +29 -0
  23. data/lib/autotest/rspec.rb +14 -7
  24. data/lib/spec/deprecation.rb +2 -1
  25. data/lib/spec/dsl/main.rb +2 -1
  26. data/lib/spec/example/example_group_methods.rb +6 -1
  27. data/lib/spec/example/example_methods.rb +4 -0
  28. data/lib/spec/example/subject.rb +9 -3
  29. data/lib/spec/interop/test/unit/testsuite_adapter.rb +2 -0
  30. data/lib/spec/interop/test.rb +1 -1
  31. data/lib/spec/matchers/be.rb +167 -128
  32. data/lib/spec/matchers/has.rb +3 -3
  33. data/lib/spec/matchers/have.rb +1 -0
  34. data/lib/spec/matchers/matcher.rb +55 -10
  35. data/lib/spec/matchers/method_missing.rb +2 -2
  36. data/lib/spec/matchers/operator_matcher.rb +6 -1
  37. data/lib/spec/matchers/pretty.rb +2 -2
  38. data/lib/spec/matchers/raise_exception.rb +131 -0
  39. data/lib/spec/matchers/simple_matcher.rb +2 -1
  40. data/lib/spec/matchers/throw_symbol.rb +18 -22
  41. data/lib/spec/matchers.rb +21 -2
  42. data/lib/spec/mocks/message_expectation.rb +63 -48
  43. data/lib/spec/mocks/methods.rb +13 -8
  44. data/lib/spec/mocks/proxy.rb +45 -22
  45. data/lib/spec/runner/backtrace_tweaker.rb +3 -2
  46. data/lib/spec/runner/configuration.rb +8 -0
  47. data/lib/spec/runner/differs/default.rb +1 -1
  48. data/lib/spec/runner/drb_command_line.rb +8 -2
  49. data/lib/spec/runner/example_group_runner.rb +1 -2
  50. data/lib/spec/runner/formatter/nested_text_formatter.rb +6 -3
  51. data/lib/spec/runner/option_parser.rb +2 -0
  52. data/lib/spec/runner/options.rb +8 -2
  53. data/lib/spec/stubs/cucumber.rb +2 -2
  54. data/lib/spec/version.rb +2 -2
  55. data/spec/autotest/autotest_helper.rb +1 -1
  56. data/spec/autotest/discover_spec.rb +2 -2
  57. data/spec/autotest/failed_results_re_spec.rb +2 -2
  58. data/spec/autotest/rspec_spec.rb +21 -6
  59. data/spec/spec/dsl/main_spec.rb +10 -2
  60. data/spec/spec/example/example_group_methods_spec.rb +21 -1
  61. data/spec/spec/example/example_group_proxy_spec.rb +1 -1
  62. data/spec/spec/example/example_group_spec.rb +1 -12
  63. data/spec/spec/example/example_matcher_spec.rb +3 -4
  64. data/spec/spec/example/subject_spec.rb +7 -0
  65. data/spec/spec/expectations/wrap_expectation_spec.rb +2 -1
  66. data/spec/spec/interop/test/unit/spec_spec.rb +7 -7
  67. data/spec/spec/interop/test/unit/testcase_spec.rb +7 -7
  68. data/spec/spec/interop/test/unit/testsuite_adapter_spec.rb +1 -1
  69. data/spec/spec/matchers/be_spec.rb +159 -10
  70. data/spec/spec/matchers/has_spec.rb +109 -0
  71. data/spec/spec/matchers/have_spec.rb +278 -293
  72. data/spec/spec/matchers/match_array_spec.rb +8 -1
  73. data/spec/spec/matchers/matcher_spec.rb +70 -9
  74. data/spec/spec/matchers/raise_exception_spec.rb +345 -0
  75. data/spec/spec/matchers/simple_matcher_spec.rb +51 -44
  76. data/spec/spec/matchers/throw_symbol_spec.rb +83 -58
  77. data/spec/spec/mocks/and_yield_spec.rb +117 -0
  78. data/spec/spec/mocks/bug_report_496_spec.rb +2 -4
  79. data/spec/spec/mocks/mock_spec.rb +2 -2
  80. data/spec/spec/runner/command_line_spec.rb +26 -5
  81. data/spec/spec/runner/drb_command_line_spec.rb +39 -0
  82. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +35 -11
  83. data/spec/spec/runner/option_parser_spec.rb +12 -6
  84. data/spec/spec/runner/options_spec.rb +7 -0
  85. data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +23 -5
  86. data/spec/spec_helper.rb +2 -1
  87. metadata +107 -38
  88. data/lib/spec/matchers/raise_error.rb +0 -129
  89. data/spec/spec/matchers/matcher_methods_spec.rb +0 -63
  90. data/spec/spec/matchers/raise_error_spec.rb +0 -333
  91. /data/lib/spec/{matchers/extensions → extensions}/instance_exec.rb +0 -0
@@ -7,7 +7,7 @@ module Spec
7
7
  protected :expected_received_count=, :method_block=, :expected_from=
8
8
  attr_accessor :error_generator
9
9
  protected :error_generator, :error_generator=
10
-
10
+
11
11
  def initialize(error_generator, expectation_ordering, expected_from, sym, method_block, expected_received_count=1, opts={}, &implementation)
12
12
  @error_generator = error_generator
13
13
  @error_generator.opts = opts
@@ -27,8 +27,9 @@ module Spec
27
27
  @failed_fast = nil
28
28
  @args_to_yield_were_cloned = false
29
29
  @return_block = implementation
30
+ @eval_context = nil
30
31
  end
31
-
32
+
32
33
  def build_child(expected_from, method_block, expected_received_count, opts={})
33
34
  child = clone
34
35
  child.expected_from = expected_from
@@ -41,7 +42,7 @@ module Spec
41
42
  child.clone_args_to_yield @args_to_yield
42
43
  child
43
44
  end
44
-
45
+
45
46
  def expected_args
46
47
  @args_expectation.args
47
48
  end
@@ -59,7 +60,7 @@ module Spec
59
60
  end
60
61
  @return_block = block_given? ? return_block : lambda { value }
61
62
  end
62
-
63
+
63
64
  # :call-seq:
64
65
  # and_raise()
65
66
  # and_raise(Exception) #any exception class
@@ -74,47 +75,53 @@ module Spec
74
75
  def and_raise(exception=Exception)
75
76
  @exception_to_raise = exception
76
77
  end
77
-
78
+
78
79
  def and_throw(symbol)
79
80
  @symbol_to_throw = symbol
80
81
  end
81
-
82
- def and_yield(*args)
82
+
83
+ def and_yield(*args, &block)
83
84
  if @args_to_yield_were_cloned
84
85
  @args_to_yield.clear
85
86
  @args_to_yield_were_cloned = false
86
87
  end
87
-
88
+
89
+ if block
90
+ require 'spec/extensions/instance_exec'
91
+ @eval_context = Object.new
92
+ @eval_context.extend Spec::Matchers::InstanceExec
93
+ yield @eval_context
94
+ end
88
95
  @args_to_yield << args
89
96
  self
90
97
  end
91
-
98
+
92
99
  def matches(sym, args)
93
100
  @sym == sym and @args_expectation.args_match?(args)
94
101
  end
95
-
102
+
96
103
  def invoke(*args, &block)
97
104
  if @expected_received_count == 0
98
105
  @failed_fast = true
99
106
  @actual_received_count += 1
100
107
  @error_generator.raise_expectation_error @sym, @expected_received_count, @actual_received_count, *args
101
108
  end
102
-
109
+
103
110
  @order_group.handle_order_constraint self
104
111
 
105
112
  begin
106
113
  Kernel::raise @exception_to_raise unless @exception_to_raise.nil?
107
114
  Kernel::throw @symbol_to_throw unless @symbol_to_throw.nil?
108
-
109
-
115
+
116
+
110
117
  if !@method_block.nil?
111
118
  default_return_val = invoke_method_block(*args)
112
- elsif @args_to_yield.size > 0
119
+ elsif @args_to_yield.size > 0 || @eval_context
113
120
  default_return_val = invoke_with_yield(&block)
114
121
  else
115
122
  default_return_val = nil
116
123
  end
117
-
124
+
118
125
  if @consecutive
119
126
  return invoke_consecutive_return_block(*args, &block)
120
127
  elsif @return_block
@@ -131,7 +138,7 @@ module Spec
131
138
  @expected_received_count != :any && @expected_received_count > 0 &&
132
139
  @actual_received_count >= @expected_received_count
133
140
  end
134
-
141
+
135
142
  def invoke_return_block(*args, &block)
136
143
  args << block unless block.nil?
137
144
  # Ruby 1.9 - when we set @return_block to return values
@@ -139,7 +146,7 @@ module Spec
139
146
  # a "wrong number of arguments" error
140
147
  @return_block.arity == 0 ? @return_block.call : @return_block.call(*args)
141
148
  end
142
-
149
+
143
150
  protected
144
151
 
145
152
  def invoke_method_block(*args)
@@ -149,7 +156,7 @@ module Spec
149
156
  @error_generator.raise_block_failed_error @sym, detail.message
150
157
  end
151
158
  end
152
-
159
+
153
160
  def invoke_with_yield(&block)
154
161
  if block.nil?
155
162
  @error_generator.raise_missing_block_error @args_to_yield
@@ -159,67 +166,75 @@ module Spec
159
166
  if block.arity > -1 && args_to_yield_this_time.length != block.arity
160
167
  @error_generator.raise_wrong_arity_error args_to_yield_this_time, block.arity
161
168
  end
162
- value = block.call(*args_to_yield_this_time)
169
+ value = eval_block(*args_to_yield_this_time, &block)
163
170
  end
164
171
  value
165
172
  end
166
-
173
+
174
+ def eval_block(*args, &block)
175
+ if @eval_context
176
+ @eval_context.instance_exec(*args, &block)
177
+ else
178
+ block.call(*args)
179
+ end
180
+ end
181
+
167
182
  def invoke_consecutive_return_block(*args, &block)
168
183
  value = invoke_return_block(*args, &block)
169
184
  index = [@actual_received_count, value.size-1].min
170
185
  value[index]
171
186
  end
172
-
187
+
173
188
  def clone_args_to_yield(args)
174
189
  @args_to_yield = args.clone
175
190
  @args_to_yield_were_cloned = true
176
191
  end
177
-
192
+
178
193
  def failed_fast?
179
194
  @failed_fast
180
195
  end
181
196
  end
182
-
197
+
183
198
  class MessageExpectation < BaseExpectation
184
199
 
185
200
  def matches_name?(sym)
186
201
  @sym == sym
187
202
  end
188
-
203
+
189
204
  def matches_name_but_not_args(sym, args)
190
205
  matches_name?(sym) and not @args_expectation.args_match?(args)
191
206
  end
192
-
207
+
193
208
  def verify_messages_received
194
209
  return if expected_messages_received? || failed_fast?
195
-
210
+
196
211
  generate_error
197
212
  rescue Spec::Mocks::MockExpectationError => error
198
213
  error.backtrace.insert(0, @expected_from)
199
214
  Kernel::raise error
200
215
  end
201
-
216
+
202
217
  def expected_messages_received?
203
218
  ignoring_args? || matches_exact_count? ||
204
219
  matches_at_least_count? || matches_at_most_count?
205
220
  end
206
-
221
+
207
222
  def ignoring_args?
208
223
  @expected_received_count == :any
209
224
  end
210
-
225
+
211
226
  def matches_at_least_count?
212
227
  @at_least && @actual_received_count >= @expected_received_count
213
228
  end
214
-
229
+
215
230
  def matches_at_most_count?
216
231
  @at_most && @actual_received_count <= @expected_received_count
217
232
  end
218
-
233
+
219
234
  def matches_exact_count?
220
235
  @expected_received_count == @actual_received_count
221
236
  end
222
-
237
+
223
238
  def similar_messages
224
239
  @similar_messages ||= []
225
240
  end
@@ -227,7 +242,7 @@ module Spec
227
242
  def advise(args, block)
228
243
  similar_messages << args
229
244
  end
230
-
245
+
231
246
  def generate_error
232
247
  if similar_messages.empty?
233
248
  @error_generator.raise_expectation_error(@sym, @expected_received_count, @actual_received_count, *@args_expectation.args)
@@ -240,17 +255,17 @@ module Spec
240
255
  @args_expectation = ArgumentExpectation.new(args, &block)
241
256
  self
242
257
  end
243
-
258
+
244
259
  def exactly(n)
245
260
  set_expected_received_count :exactly, n
246
261
  self
247
262
  end
248
-
263
+
249
264
  def at_least(n)
250
265
  set_expected_received_count :at_least, n
251
266
  self
252
267
  end
253
-
268
+
254
269
  def at_most(n)
255
270
  set_expected_received_count :at_most, n
256
271
  self
@@ -260,41 +275,41 @@ module Spec
260
275
  @method_block = block if block
261
276
  self
262
277
  end
263
-
278
+
264
279
  def any_number_of_times(&block)
265
280
  @method_block = block if block
266
281
  @expected_received_count = :any
267
282
  self
268
283
  end
269
-
284
+
270
285
  def never
271
286
  @expected_received_count = 0
272
287
  self
273
288
  end
274
-
289
+
275
290
  def once(&block)
276
291
  @method_block = block if block
277
292
  @expected_received_count = 1
278
293
  self
279
294
  end
280
-
295
+
281
296
  def twice(&block)
282
297
  @method_block = block if block
283
298
  @expected_received_count = 2
284
299
  self
285
300
  end
286
-
301
+
287
302
  def ordered(&block)
288
303
  @method_block = block if block
289
304
  @order_group.register(self)
290
305
  @ordered = true
291
306
  self
292
307
  end
293
-
308
+
294
309
  def negative_expectation_for?(sym)
295
310
  return false
296
311
  end
297
-
312
+
298
313
  protected
299
314
  def set_expected_received_count(relativity, n)
300
315
  @at_least = (relativity == :at_least)
@@ -308,22 +323,22 @@ module Spec
308
323
  2
309
324
  end
310
325
  end
311
-
326
+
312
327
  def clear_actual_received_count!
313
328
  @actual_received_count = 0
314
329
  end
315
-
330
+
316
331
  end
317
-
332
+
318
333
  class NegativeMessageExpectation < MessageExpectation
319
334
  def initialize(message, expectation_ordering, expected_from, sym, method_block)
320
335
  super(message, expectation_ordering, expected_from, sym, method_block, 0)
321
336
  end
322
-
337
+
323
338
  def negative_expectation_for?(sym)
324
339
  return @sym == sym
325
340
  end
326
341
  end
327
-
342
+
328
343
  end
329
344
  end
@@ -55,6 +55,19 @@ module Spec
55
55
  end
56
56
  end
57
57
 
58
+ # Record and otherwise ignore all messages that aren't specified,
59
+ # with +stub+, +stub!+, or +should_receive+.
60
+ #
61
+ # == Returns
62
+ # self
63
+ def as_null_object
64
+ __mock_proxy.as_null_object
65
+ end
66
+
67
+ def null_object?
68
+ __mock_proxy.null_object?
69
+ end
70
+
58
71
  def received_message?(sym, *args, &block) #:nodoc:
59
72
  __mock_proxy.received_message?(sym.to_sym, *args, &block)
60
73
  end
@@ -66,14 +79,6 @@ module Spec
66
79
  def rspec_reset #:nodoc:
67
80
  __mock_proxy.reset
68
81
  end
69
-
70
- def as_null_object
71
- __mock_proxy.as_null_object
72
- end
73
-
74
- def null_object?
75
- __mock_proxy.null_object?
76
- end
77
82
 
78
83
  private
79
84
 
@@ -40,13 +40,16 @@ module Spec
40
40
  def add_message_expectation(expected_from, sym, opts={}, &block)
41
41
  __add sym
42
42
  warn_if_nil_class sym
43
- if existing_stub = @stubs.detect {|s| s.sym == sym }
44
- expectation = existing_stub.build_child(expected_from, block_given?? block : nil, 1, opts)
43
+ @expectations << build_expectation(expected_from, sym, opts, &block)
44
+ @expectations.last
45
+ end
46
+
47
+ def build_expectation(expected_from, sym, opts, &block)
48
+ if stub = find_matching_method_stub(sym)
49
+ stub.build_child(expected_from, block_given?? block : nil, 1, opts)
45
50
  else
46
- expectation = MessageExpectation.new(@error_generator, @expectation_ordering, expected_from, sym, block_given? ? block : nil, 1, opts)
51
+ MessageExpectation.new(@error_generator, @expectation_ordering, expected_from, sym, block_given? ? block : nil, 1, opts)
47
52
  end
48
- @expectations << expectation
49
- @expectations.last
50
53
  end
51
54
 
52
55
  def add_negative_message_expectation(expected_from, sym, &block)
@@ -64,7 +67,6 @@ module Spec
64
67
 
65
68
  def remove_stub(message)
66
69
  message = message.to_sym
67
-
68
70
  if stub_to_remove = @stubs.detect { |s| s.matches_name?(message) }
69
71
  reset_proxied_method(message)
70
72
  @stubs.delete(stub_to_remove)
@@ -92,7 +94,7 @@ module Spec
92
94
  end
93
95
 
94
96
  def has_negative_expectation?(sym)
95
- @expectations.detect {|expectation| expectation.negative_expectation_for?(sym)}
97
+ @expectations.any? {|expectation| expectation.negative_expectation_for?(sym)}
96
98
  end
97
99
 
98
100
  def record_message_received(sym, args, block)
@@ -103,21 +105,41 @@ module Spec
103
105
  expectation = find_matching_expectation(sym, *args)
104
106
  stub = find_matching_method_stub(sym, *args)
105
107
 
106
- if (stub && expectation && expectation.called_max_times?) || (stub && !expectation)
107
- if expectation = find_almost_matching_expectation(sym, *args)
108
- expectation.advise(args, block) unless expectation.expected_messages_received?
109
- end
110
- stub.invoke(*args, &block)
108
+ if ok_to_invoke_stub?(stub, expectation)
109
+ record_stub(stub, sym, args, &block)
111
110
  elsif expectation
112
- expectation.invoke(*args, &block)
111
+ invoke_expectation(expectation, *args, &block)
113
112
  elsif expectation = find_almost_matching_expectation(sym, *args)
114
- expectation.advise(args, block) if null_object? unless expectation.expected_messages_received?
115
- raise_unexpected_message_args_error(expectation, *args) unless (has_negative_expectation?(sym) or null_object?)
113
+ record_almost_matching_expectation(expectation, sym, *args, &block)
114
+ elsif @target.is_a?(Class)
115
+ @target.superclass.send(sym, *args, &block)
116
116
  else
117
117
  @target.__send__ :method_missing, sym, *args, &block
118
118
  end
119
119
  end
120
120
 
121
+ def record_stub(stub, sym, args, &block)
122
+ almost_matching_expectation(sym, *args) do |e|
123
+ e.advise(args, block)
124
+ end
125
+ stub.invoke(*args, &block)
126
+ end
127
+
128
+ def invoke_expectation(expectation, *args, &block)
129
+ expectation.invoke(*args, &block)
130
+ end
131
+
132
+ def record_almost_matching_expectation(expectation, sym, *args, &block)
133
+ expectation.advise(args, block)
134
+ unless (null_object? or has_negative_expectation?(sym))
135
+ raise_unexpected_message_args_error(expectation, *args)
136
+ end
137
+ end
138
+
139
+ def ok_to_invoke_stub?(stub, expectation)
140
+ stub && (!expectation || expectation.called_max_times?)
141
+ end
142
+
121
143
  def raise_unexpected_message_args_error(expectation, *args)
122
144
  @error_generator.raise_unexpected_message_args_error expectation, *args
123
145
  end
@@ -201,15 +223,11 @@ module Spec
201
223
  end
202
224
 
203
225
  def verify_expectations
204
- @expectations.each do |expectation|
205
- expectation.verify_messages_received
206
- end
226
+ @expectations.map {|e| e.verify_messages_received}
207
227
  end
208
228
 
209
229
  def reset_proxied_methods
210
- @proxied_methods.each do |sym|
211
- reset_proxied_method(sym)
212
- end
230
+ @proxied_methods.map {|sym| reset_proxied_method(sym)}
213
231
  end
214
232
 
215
233
  def reset_proxied_method(sym)
@@ -236,10 +254,15 @@ module Spec
236
254
  @expectations.find {|expectation| expectation.matches(sym, args)}
237
255
  end
238
256
 
257
+ def almost_matching_expectation(sym, *args, &block)
258
+ if e = find_almost_matching_expectation(sym, *args)
259
+ yield e
260
+ end
261
+ end
262
+
239
263
  def find_almost_matching_expectation(sym, *args)
240
264
  @expectations.find {|expectation| expectation.matches_name_but_not_args(sym, args)}
241
265
  end
242
-
243
266
  end
244
267
  end
245
268
  end
@@ -38,8 +38,9 @@ module Spec
38
38
  # Tweaks raised Exceptions to mask noisy (unneeded) parts of the backtrace
39
39
  class QuietBacktraceTweaker < BacktraceTweaker
40
40
  unless defined?(IGNORE_PATTERNS)
41
- spec_files = Dir["lib/*"].map do |path|
42
- subpath = path[1..-1]
41
+ root_dir = File.expand_path(File.join(__FILE__, '..', '..', '..', '..'))
42
+ spec_files = Dir["#{root_dir}/lib/*"].map do |path|
43
+ subpath = path[root_dir.length..-1]
43
44
  /#{subpath}/
44
45
  end
45
46
  IGNORE_PATTERNS = spec_files + [
@@ -154,6 +154,14 @@ module Spec
154
154
  def ignored_backtrace_patterns # :nodoc:
155
155
  @ignored_backtrace_patterns ||= []
156
156
  end
157
+
158
+ def suppress_deprecation_warnings!
159
+ @suppress_deprecation_warnings = true
160
+ end
161
+
162
+ def suppress_deprecation_warnings?
163
+ @suppress_deprecation_warnings ||= false
164
+ end
157
165
 
158
166
  private
159
167
 
@@ -4,7 +4,7 @@ require 'pp'
4
4
  module Spec
5
5
  module Expectations
6
6
  module Differs
7
- unless defined?(Default)
7
+ unless defined?(Spec::Expectations::Differs::Default)
8
8
  class Default
9
9
  def initialize(options)
10
10
  @options = options
@@ -4,16 +4,21 @@ module Spec
4
4
  module Runner
5
5
  # Facade to run specs by connecting to a DRB server
6
6
  class DrbCommandLine
7
+
8
+ def self.port(options)
9
+ (options.drb_port || ENV["RSPEC_DRB"] || 8989).to_i
10
+ end
11
+
7
12
  # Runs specs on a DRB server. Note that this API is similar to that of
8
13
  # CommandLine - making it possible for clients to use both interchangeably.
9
14
  def self.run(options)
10
15
  begin
11
16
  begin; \
12
17
  DRb.start_service("druby://localhost:0"); \
13
- rescue SocketError; \
18
+ rescue SocketError, Errno::EADDRNOTAVAIL; \
14
19
  DRb.start_service("druby://:0"); \
15
20
  end
16
- spec_server = DRbObject.new_with_uri("druby://127.0.0.1:8989")
21
+ spec_server = DRbObject.new_with_uri("druby://127.0.0.1:#{port(options)}")
17
22
  spec_server.run(options.argv, options.error_stream, options.output_stream)
18
23
  true
19
24
  rescue DRb::DRbConnError
@@ -21,6 +26,7 @@ module Spec
21
26
  false
22
27
  end
23
28
  end
29
+
24
30
  end
25
31
  end
26
32
  end
@@ -22,9 +22,8 @@ module Spec
22
22
  example_groups.each do |example_group|
23
23
  success = success & example_group.run(@options)
24
24
  end
25
- return success
26
- ensure
27
25
  finish
26
+ success
28
27
  end
29
28
 
30
29
  protected
@@ -4,6 +4,9 @@ module Spec
4
4
  module Runner
5
5
  module Formatter
6
6
  class NestedTextFormatter < BaseTextFormatter
7
+
8
+ INDENT = ' '
9
+
7
10
  def initialize(options, where)
8
11
  super
9
12
  @last_nested_descriptions = []
@@ -13,8 +16,8 @@ module Spec
13
16
  super
14
17
 
15
18
  example_group.nested_descriptions.each_with_index do |nested_description, i|
16
- unless nested_description == @last_nested_descriptions[i]
17
- output.puts "#{' ' * i}#{nested_description}"
19
+ unless example_group.nested_descriptions[0..i] == @last_nested_descriptions[0..i]
20
+ output.puts "#{INDENT*i}#{nested_description}"
18
21
  end
19
22
  end
20
23
 
@@ -39,7 +42,7 @@ module Spec
39
42
  end
40
43
 
41
44
  def current_indentation
42
- ' ' * @last_nested_descriptions.length
45
+ INDENT*@last_nested_descriptions.length
43
46
  end
44
47
  end
45
48
  end
@@ -80,6 +80,7 @@ module Spec
80
80
  :runner => ["-U", "--runner RUNNER", "Use a custom Runner."],
81
81
  :debug => ["-u", "--debugger", "Enable ruby-debugging."],
82
82
  :drb => ["-X", "--drb", "Run examples via DRb. (For example against script/spec_server)"],
83
+ :drb_port => ["--port PORT", "Port for DRb server. (Ignored without --drb)"],
83
84
  :version => ["-v", "--version", "Show version"],
84
85
  :help => ["-h", "--help", "You're looking at it"]
85
86
  }
@@ -113,6 +114,7 @@ module Spec
113
114
  on(*OPTIONS[:runner]) {|runner| @options.user_input_for_runner = runner}
114
115
  on(*OPTIONS[:debug]) {@options.debug = true}
115
116
  on(*OPTIONS[:drb]) {}
117
+ on(*OPTIONS[:drb_port]) {|port| @options.drb_port = port}
116
118
  on(*OPTIONS[:version]) {parse_version}
117
119
  on("--autospec") {@options.autospec = true}
118
120
  on_tail(*OPTIONS[:help]) {parse_help}
@@ -1,4 +1,5 @@
1
1
  require 'ostruct'
2
+ require 'rbconfig'
2
3
 
3
4
  module Spec
4
5
  module Runner
@@ -50,7 +51,8 @@ module Spec
50
51
  :argv
51
52
  )
52
53
  attr_reader :colour, :differ_class, :files, :examples, :example_groups
53
-
54
+ attr_writer :drb_port
55
+
54
56
  def initialize(error_stream, output_stream)
55
57
  @error_stream = error_stream
56
58
  @output_stream = output_stream
@@ -183,7 +185,7 @@ module Spec
183
185
 
184
186
  def colour=(colour)
185
187
  @colour = colour
186
- if @colour && RUBY_PLATFORM =~ /mswin|mingw/ ;\
188
+ if @colour && Config::CONFIG['host_os'] =~ /mswin|mingw/ ;\
187
189
  begin ;\
188
190
  replace_output = @output_stream.equal?($stdout) ;\
189
191
  require 'rubygems' unless ENV['NO_RUBYGEMS'] ;\
@@ -289,6 +291,10 @@ module Spec
289
291
  @dry_run == true
290
292
  end
291
293
 
294
+ def drb_port
295
+ @drb_port.to_i if defined?(@drb_port)
296
+ end
297
+
292
298
  protected
293
299
 
294
300
  def define_predicate_matchers
@@ -1,5 +1,5 @@
1
1
  # This plugs RSpec's mocking/stubbing framework into cucumber
2
2
  require 'spec/mocks'
3
- Before {$rspec_stubs ||= Spec::Mocks::Space.new}
4
- After {$rspec_stubs.reset_all}
3
+ Before {$rspec_mocks ||= Spec::Mocks::Space.new}
4
+ After {$rspec_mocks.reset_all}
5
5
  World(Spec::Mocks::ExampleMethods)
data/lib/spec/version.rb CHANGED
@@ -2,8 +2,8 @@ module Spec # :nodoc:
2
2
  module VERSION # :nodoc:
3
3
  unless defined? MAJOR
4
4
  MAJOR = 1
5
- MINOR = 2
6
- TINY = 9
5
+ MINOR = 3
6
+ TINY = 1
7
7
  PRE = nil
8
8
 
9
9
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
@@ -5,4 +5,4 @@ rescue LoadError
5
5
  raise "You must install ZenTest to use autotest"
6
6
  end
7
7
  require 'autotest/rspec'
8
- require 'spec/autotest/autotest_matchers'
8
+ require 'autotest/autotest_matchers'
@@ -1,8 +1,8 @@
1
- require 'spec/autotest/autotest_helper'
1
+ require 'autotest/autotest_helper'
2
2
 
3
3
  describe Autotest::Rspec, "discovery" do
4
4
  it "adds the rspec autotest plugin" do
5
5
  Autotest.should_receive(:add_discovery)
6
- load File.expand_path(File.dirname(__FILE__) + "/../../lib/autotest/discover.rb")
6
+ load File.expand_path("../../../lib/autotest/discover.rb", __FILE__)
7
7
  end
8
8
  end