rspec 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. data/{CHANGES → History.txt} +116 -64
  2. data/Manifest.txt +403 -0
  3. data/{MIT-LICENSE → README.txt} +43 -0
  4. data/Rakefile +39 -212
  5. data/{TODO → TODO.txt} +0 -0
  6. data/bin/autospec +4 -0
  7. data/bin/spec +1 -1
  8. data/examples/pure/yielding_example.rb +33 -0
  9. data/examples/stories/game-of-life/.loadpath +5 -0
  10. data/examples/stories/game-of-life/behaviour/everything.rb +1 -1
  11. data/examples/stories/game-of-life/behaviour/stories/CellsWithMoreThanThreeNeighboursDie.story +17 -17
  12. data/init.rb +9 -0
  13. data/lib/autotest/discover.rb +1 -1
  14. data/lib/autotest/rspec.rb +3 -29
  15. data/lib/spec.rb +10 -12
  16. data/lib/spec/adapters.rb +1 -0
  17. data/lib/spec/adapters/ruby_engine.rb +26 -0
  18. data/lib/spec/adapters/ruby_engine/mri.rb +8 -0
  19. data/lib/spec/adapters/ruby_engine/rubinius.rb +8 -0
  20. data/lib/spec/example/errors.rb +6 -0
  21. data/lib/spec/example/example_group_methods.rb +17 -14
  22. data/lib/spec/example/example_matcher.rb +2 -0
  23. data/lib/spec/example/example_methods.rb +4 -9
  24. data/lib/spec/example/module_inclusion_warnings.rb +2 -1
  25. data/lib/spec/expectations/extensions/object.rb +2 -2
  26. data/lib/spec/expectations/handler.rb +8 -16
  27. data/lib/spec/extensions/main.rb +2 -17
  28. data/lib/spec/matchers.rb +8 -2
  29. data/lib/spec/matchers/be.rb +0 -3
  30. data/lib/spec/matchers/change.rb +44 -40
  31. data/lib/spec/matchers/has.rb +1 -1
  32. data/lib/spec/matchers/have.rb +17 -12
  33. data/lib/spec/matchers/operator_matcher.rb +10 -4
  34. data/lib/spec/matchers/simple_matcher.rb +113 -10
  35. data/lib/spec/mocks.rb +1 -1
  36. data/lib/spec/mocks/argument_constraints.rb +185 -0
  37. data/lib/spec/mocks/argument_expectation.rb +35 -173
  38. data/lib/spec/mocks/framework.rb +1 -1
  39. data/lib/spec/mocks/message_expectation.rb +30 -5
  40. data/lib/spec/mocks/methods.rb +14 -2
  41. data/lib/spec/mocks/mock.rb +4 -0
  42. data/lib/spec/mocks/proxy.rb +46 -5
  43. data/lib/spec/mocks/spec_methods.rb +9 -1
  44. data/lib/spec/rake/spectask.rb +14 -22
  45. data/lib/spec/rake/verify_rcov.rb +3 -3
  46. data/lib/spec/runner.rb +18 -6
  47. data/lib/spec/runner/backtrace_tweaker.rb +6 -7
  48. data/lib/spec/runner/command_line.rb +6 -17
  49. data/lib/spec/runner/drb_command_line.rb +1 -1
  50. data/lib/spec/runner/formatter/base_formatter.rb +3 -1
  51. data/lib/spec/runner/formatter/base_text_formatter.rb +5 -9
  52. data/lib/spec/runner/formatter/html_formatter.rb +1 -1
  53. data/lib/spec/runner/formatter/nested_text_formatter.rb +1 -1
  54. data/lib/spec/runner/formatter/progress_bar_formatter.rb +2 -2
  55. data/lib/spec/runner/formatter/specdoc_formatter.rb +1 -1
  56. data/lib/spec/runner/formatter/story/html_formatter.rb +62 -16
  57. data/lib/spec/runner/formatter/story/plain_text_formatter.rb +68 -16
  58. data/lib/spec/runner/formatter/story/progress_bar_formatter.rb +42 -0
  59. data/lib/spec/runner/heckle_runner.rb +2 -2
  60. data/lib/spec/runner/option_parser.rb +2 -1
  61. data/lib/spec/runner/options.rb +18 -9
  62. data/lib/spec/runner/reporter.rb +24 -4
  63. data/lib/spec/runner/spec_parser.rb +1 -1
  64. data/lib/spec/story/runner.rb +1 -2
  65. data/lib/spec/story/runner/story_mediator.rb +14 -0
  66. data/lib/spec/story/runner/story_parser.rb +20 -0
  67. data/lib/spec/story/step.rb +40 -28
  68. data/lib/spec/story/step_mother.rb +2 -1
  69. data/lib/spec/story/world.rb +6 -2
  70. data/lib/spec/version.rb +13 -22
  71. data/rake_tasks/failing_examples_with_html.rake +1 -1
  72. data/rake_tasks/verify_rcov.rake +2 -2
  73. data/rspec.gemspec +33 -0
  74. data/spec/autotest/rspec_spec.rb +90 -141
  75. data/spec/spec/adapters/ruby_engine_spec.rb +16 -0
  76. data/spec/spec/example/base_formatter_spec.rb +112 -0
  77. data/spec/spec/example/example_group_factory_spec.rb +2 -2
  78. data/spec/spec/example/example_group_methods_spec.rb +55 -4
  79. data/spec/spec/example/example_group_spec.rb +4 -3
  80. data/spec/spec/example/example_methods_spec.rb +18 -14
  81. data/spec/spec/example/pending_module_spec.rb +38 -0
  82. data/spec/spec/example/shared_example_group_spec.rb +1 -1
  83. data/spec/spec/expectations/extensions/object_spec.rb +0 -12
  84. data/spec/spec/extensions/main_spec.rb +3 -8
  85. data/spec/spec/matchers/change_spec.rb +16 -6
  86. data/spec/spec/matchers/handler_spec.rb +58 -37
  87. data/spec/spec/matchers/has_spec.rb +10 -0
  88. data/spec/spec/matchers/have_spec.rb +105 -2
  89. data/spec/spec/matchers/operator_matcher_spec.rb +35 -2
  90. data/spec/spec/matchers/simple_matcher_spec.rb +64 -2
  91. data/spec/spec/mocks/any_number_of_times_spec.rb +7 -0
  92. data/spec/spec/mocks/bug_report_496.rb +17 -0
  93. data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +7 -1
  94. data/spec/spec/mocks/hash_including_matcher_spec.rb +45 -24
  95. data/spec/spec/mocks/mock_spec.rb +55 -10
  96. data/spec/spec/mocks/nil_expectation_warning_spec.rb +54 -0
  97. data/spec/spec/mocks/null_object_mock_spec.rb +14 -0
  98. data/spec/spec/mocks/options_hash_spec.rb +18 -28
  99. data/spec/spec/mocks/partial_mock_spec.rb +2 -0
  100. data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +20 -6
  101. data/spec/spec/mocks/stub_spec.rb +7 -0
  102. data/spec/spec/runner/command_line_spec.rb +5 -12
  103. data/spec/spec/runner/drb_command_line_spec.rb +13 -6
  104. data/spec/spec/runner/formatter/html_formatter_spec.rb +2 -1
  105. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +3 -3
  106. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +20 -2
  107. data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +2 -1
  108. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +3 -3
  109. data/spec/spec/runner/formatter/story/html_formatter_spec.rb +76 -2
  110. data/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb +161 -0
  111. data/spec/spec/runner/formatter/story/progress_bar_formatter_spec.rb +82 -0
  112. data/spec/spec/runner/heckle_runner_spec.rb +8 -8
  113. data/spec/spec/runner/option_parser_spec.rb +21 -6
  114. data/spec/spec/runner/output_one_time_fixture_runner.rb +1 -1
  115. data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +6 -0
  116. data/spec/spec/runner/reporter_spec.rb +51 -5
  117. data/spec/spec/runner/spec_parser_spec.rb +4 -4
  118. data/spec/spec/story/runner/plain_text_story_runner_spec.rb +2 -5
  119. data/spec/spec/story/runner/story_mediator_spec.rb +10 -0
  120. data/spec/spec/story/runner/story_parser_spec.rb +23 -6
  121. data/spec/spec/story/scenario_spec.rb +1 -3
  122. data/spec/spec/story/step_mother_spec.rb +12 -0
  123. data/spec/spec/story/step_spec.rb +57 -4
  124. data/spec/spec/story/story_spec.rb +1 -3
  125. data/spec/spec/story/world_spec.rb +1 -1
  126. data/spec/spec_helper.rb +21 -68
  127. data/stories/all.rb +1 -1
  128. data/stories/configuration/before_blocks.story +21 -0
  129. data/stories/configuration/stories.rb +7 -0
  130. data/stories/example_groups/stories.rb +3 -4
  131. data/stories/resources/spec/before_blocks_example.rb +32 -0
  132. data/stories/stories/multiline_steps.story +23 -0
  133. data/stories/stories/steps/multiline_steps.rb +13 -0
  134. data/stories/stories/stories.rb +6 -0
  135. data/story_server/prototype/javascripts/builder.js +136 -0
  136. data/story_server/prototype/javascripts/controls.js +972 -0
  137. data/story_server/prototype/javascripts/dragdrop.js +976 -0
  138. data/story_server/prototype/javascripts/effects.js +1117 -0
  139. data/story_server/prototype/javascripts/prototype.js +4140 -0
  140. data/story_server/prototype/javascripts/rspec.js +149 -0
  141. data/story_server/prototype/javascripts/scriptaculous.js +58 -0
  142. data/story_server/prototype/javascripts/slider.js +276 -0
  143. data/story_server/prototype/javascripts/sound.js +55 -0
  144. data/story_server/prototype/javascripts/unittest.js +568 -0
  145. data/story_server/prototype/lib/server.rb +24 -0
  146. data/story_server/prototype/stories.html +176 -0
  147. data/story_server/prototype/stylesheets/rspec.css +136 -0
  148. data/story_server/prototype/stylesheets/test.css +90 -0
  149. metadata +166 -166
  150. data/README +0 -36
  151. data/UPGRADE +0 -7
  152. data/bin/spec_translator +0 -8
  153. data/lib/spec/mocks/argument_constraint_matchers.rb +0 -31
  154. data/lib/spec/translator.rb +0 -114
  155. data/spec/spec/example/example_spec.rb +0 -53
  156. data/spec/spec/runner/execution_context_spec.rb +0 -37
  157. data/spec/spec/translator_spec.rb +0 -265
@@ -2,31 +2,52 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
 
3
3
  module Spec
4
4
  module Mocks
5
- describe HashIncludingConstraint do
6
-
7
- it "should match the same hash" do
8
- hash_including(:a => 1).matches?(:a => 1).should be_true
9
- end
10
-
11
- it "should not match a non-hash" do
12
- hash_including(:a => 1).matches?(1).should_not be_true
13
- end
5
+ module ArgumentConstraints
6
+ describe HashIncludingConstraint do
7
+
8
+ it "should describe itself properly" do
9
+ HashIncludingConstraint.new(:a => 1).description.should == "hash_including(:a=>1)"
10
+ end
14
11
 
15
- it "should match a hash with extra stuff" do
16
- hash_including(:a => 1).matches?(:a => 1, :b => 2).should be_true
17
- end
18
-
19
- it "should not match a hash with a missing key" do
20
- hash_including(:a => 1).matches?(:b => 2).should_not be_true
21
- end
12
+ describe "passing" do
13
+ it "should match the same hash" do
14
+ hash_including(:a => 1).should == {:a => 1}
15
+ end
22
16
 
23
- it "should not match a hash with an incorrect value" do
24
- hash_including(:a => 1, :b => 2).matches?(:a => 1, :b => 3).should_not be_true
25
- end
17
+ it "should match a hash with extra stuff" do
18
+ hash_including(:a => 1).should == {:a => 1, :b => 2}
19
+ end
20
+
21
+ describe "when matching against other constraints" do
22
+ it "should match an int against anything()" do
23
+ hash_including(:a => anything, :b => 2).should == {:a => 1, :b => 2}
24
+ end
26
25
 
27
- it "should describe itself properly" do
28
- HashIncludingConstraint.new(:a => 1).description.should == "hash_including(:a=>1)"
29
- end
26
+ it "should match a string against anything()" do
27
+ hash_including(:a => anything, :b => 2).should == {:a => "1", :b => 2}
28
+ end
29
+ end
30
+ end
31
+
32
+ describe "failing" do
33
+ it "should not match a non-hash" do
34
+ hash_including(:a => 1).should_not == 1
35
+ end
36
+
37
+
38
+ it "should not match a hash with a missing key" do
39
+ hash_including(:a => 1).should_not == {:b => 2}
40
+ end
41
+
42
+ it "should not match a hash with an incorrect value" do
43
+ hash_including(:a => 1, :b => 2).should_not == {:a => 1, :b => 3}
44
+ end
45
+
46
+ it "should not match when values are nil but keys are different" do
47
+ hash_including(:a => nil).should_not == {:b => nil}
48
+ end
49
+ end
50
+ end
30
51
  end
31
- end
32
- end
52
+ end
53
+ end
@@ -23,6 +23,18 @@ module Spec
23
23
  end
24
24
  end
25
25
 
26
+ it "should report line number of expectation of unreceived message after #should_receive after similar stub" do
27
+ @mock.stub!(:wont_happen)
28
+ expected_error_line = __LINE__; @mock.should_receive(:wont_happen).with("x", 3)
29
+ begin
30
+ @mock.rspec_verify
31
+ violated
32
+ rescue MockExpectationError => e
33
+ # NOTE - this regexp ended w/ $, but jruby adds extra info at the end of the line
34
+ e.backtrace[0].should match(/#{File.basename(__FILE__)}:#{expected_error_line}/)
35
+ end
36
+ end
37
+
26
38
  it "should pass when not receiving message specified as not to be received" do
27
39
  @mock.should_not_receive(:not_expected)
28
40
  @mock.rspec_verify
@@ -403,7 +415,16 @@ module Spec
403
415
  @mock.msg.should equal(:stub_value)
404
416
  @mock.rspec_verify
405
417
  end
406
-
418
+
419
+ it "should not require a different signature to replace a method stub" do
420
+ @mock.stub!(:msg).and_return(:stub_value)
421
+ @mock.should_receive(:msg).and_return(:mock_value)
422
+ @mock.msg(:arg).should equal(:mock_value)
423
+ @mock.msg.should equal(:stub_value)
424
+ @mock.msg.should equal(:stub_value)
425
+ @mock.rspec_verify
426
+ end
427
+
407
428
  it "should temporarily replace a method stub on a non-mock" do
408
429
  non_mock = Object.new
409
430
  non_mock.stub!(:msg).and_return(:stub_value)
@@ -413,7 +434,22 @@ module Spec
413
434
  non_mock.msg.should equal(:stub_value)
414
435
  non_mock.rspec_verify
415
436
  end
416
-
437
+
438
+ it "should return the stubbed value when no new value specified" do
439
+ @mock.stub!(:msg).and_return(:stub_value)
440
+ @mock.should_receive(:msg)
441
+ @mock.msg.should equal(:stub_value)
442
+ @mock.rspec_verify
443
+ end
444
+
445
+ it "should not mess with the stub's yielded values when also mocked" do
446
+ @mock.stub!(:yield_back).and_yield(:stub_value)
447
+ @mock.should_receive(:yield_back).and_yield(:mock_value)
448
+ @mock.yield_back{|v| v}.should == :mock_value
449
+ @mock.yield_back{|v| v}.should == :stub_value
450
+ @mock.rspec_verify
451
+ end
452
+
417
453
  it "should assign stub return values" do
418
454
  mock = Mock.new('name', :message => :response)
419
455
  mock.message.should == :response
@@ -439,6 +475,15 @@ module Spec
439
475
  @calls.should == 1
440
476
  end
441
477
 
478
+ it "should call the block after #should_receive after a similar stub" do
479
+ @mock.stub!(:foo).and_return(:bar)
480
+ @mock.should_receive(:foo) { add_call }
481
+
482
+ @mock.foo
483
+
484
+ @calls.should == 1
485
+ end
486
+
442
487
  it "should call the block after #once" do
443
488
  @mock.should_receive(:foo).once { add_call }
444
489
 
@@ -472,14 +517,6 @@ module Spec
472
517
  @calls.should == 7
473
518
  end
474
519
 
475
- it "should call the block after #with" do
476
- @mock.should_receive(:foo).with(:arg) { add_call }
477
-
478
- @mock.foo(:arg)
479
-
480
- @calls.should == 1
481
- end
482
-
483
520
  it "should call the block after #ordered" do
484
521
  @mock.should_receive(:foo).ordered { add_call }
485
522
  @mock.should_receive(:bar).ordered { add_call }
@@ -490,5 +527,13 @@ module Spec
490
527
  @calls.should == 2
491
528
  end
492
529
  end
530
+
531
+ describe 'string representation generated by #to_s' do
532
+ it 'should not contain < because that might lead to invalid HTML in some situations' do
533
+ mock = mock("Dog")
534
+ valid_html_str = "#{mock}"
535
+ valid_html_str.should_not include('<')
536
+ end
537
+ end
493
538
  end
494
539
  end
@@ -0,0 +1,54 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ module Spec
4
+ module Mocks
5
+
6
+ describe "an expectation set on nil" do
7
+
8
+ it "should issue a warning with file and line number information" do
9
+ expected_warning = "An expectation of :foo was set on nil. Called from #{__FILE__}:#{__LINE__+3}. Use allow_message_expectations_on_nil to disable warnings."
10
+ Kernel.should_receive(:warn).with(expected_warning)
11
+
12
+ nil.should_receive(:foo)
13
+ nil.foo
14
+ end
15
+
16
+ it "should issue a warning when the expectation is negative" do
17
+ Kernel.should_receive(:warn)
18
+
19
+ nil.should_not_receive(:foo)
20
+ end
21
+
22
+ it "should not issue a warning when expectations are set to be allowed" do
23
+ allow_message_expectations_on_nil
24
+ Kernel.should_not_receive(:warn)
25
+
26
+ nil.should_receive(:foo)
27
+ nil.should_not_receive(:bar)
28
+ nil.foo
29
+ end
30
+
31
+ end
32
+
33
+ describe "#allow_message_expectations_on_nil" do
34
+ include SandboxedOptions
35
+
36
+ it "should not effect subsequent examples" do
37
+ example_group = Class.new(ExampleGroup)
38
+ example_group.it("when called in one example that doesn't end up setting an expectation on nil") do
39
+ allow_message_expectations_on_nil
40
+ end
41
+ example_group.it("should not effect the next exapmle ran") do
42
+ Kernel.should_receive(:warn)
43
+ nil.should_receive(:foo)
44
+ nil.foo
45
+ end
46
+
47
+ example_group.run.should be_true
48
+
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+ end
@@ -36,5 +36,19 @@ module Spec
36
36
  @mock.message(:unexpected_arg)
37
37
  end
38
38
  end
39
+
40
+ describe "#null_object?" do
41
+ it "should default to false" do
42
+ obj = mock('anything')
43
+ obj.should_not be_null_object
44
+ end
45
+ end
46
+
47
+ describe "#as_null_object" do
48
+ it "should set the object to null_object" do
49
+ obj = mock('anything').as_null_object
50
+ obj.should be_null_object
51
+ end
52
+ end
39
53
  end
40
54
  end
@@ -3,42 +3,32 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
3
3
  module Spec
4
4
  module Mocks
5
5
  describe "calling :should_receive with an options hash" do
6
- it_should_behave_like "sandboxed rspec_options"
7
- attr_reader :reporter, :example_group
8
- before do
9
- @reporter = ::Spec::Runner::Reporter.new(options)
10
- @example_group = Class.new(::Spec::Example::ExampleGroup) do
11
- plugin_mock_framework
12
- describe("Some Examples")
13
- end
14
- reporter.add_example_group example_group
15
- end
16
-
17
6
  it "should report the file and line submitted with :expected_from" do
18
- example_definition = example_group.it "spec" do
7
+ begin
19
8
  mock = Spec::Mocks::Mock.new("a mock")
20
9
  mock.should_receive(:message, :expected_from => "/path/to/blah.ext:37")
21
10
  mock.rspec_verify
11
+ rescue => e
12
+ ensure
13
+ e.backtrace.to_s.should =~ /\/path\/to\/blah.ext:37/m
22
14
  end
23
- example = example_group.new(example_definition)
24
-
25
- reporter.should_receive(:example_finished) do |spec, error|
26
- error.backtrace.detect {|line| line =~ /\/path\/to\/blah.ext:37/}.should_not be_nil
27
- end
28
- example.execute(options, {})
29
15
  end
30
16
 
31
17
  it "should use the message supplied with :message" do
32
- example_definition = @example_group.it "spec" do
33
- mock = Spec::Mocks::Mock.new("a mock")
34
- mock.should_receive(:message, :message => "recebi nada")
35
- mock.rspec_verify
36
- end
37
- example = @example_group.new(example_definition)
38
- @reporter.should_receive(:example_finished) do |spec, error|
39
- error.message.should == "recebi nada"
40
- end
41
- example.execute(@options, {})
18
+ lambda {
19
+ m = Spec::Mocks::Mock.new("a mock")
20
+ m.should_receive(:message, :message => "recebi nada")
21
+ m.rspec_verify
22
+ }.should raise_error("recebi nada")
23
+ end
24
+
25
+ it "should use the message supplied with :message after a similar stub" do
26
+ lambda {
27
+ m = Spec::Mocks::Mock.new("a mock")
28
+ m.stub!(:message)
29
+ m.should_receive(:message, :message => "from mock")
30
+ m.rspec_verify
31
+ }.should raise_error("from mock")
42
32
  end
43
33
  end
44
34
  end
@@ -74,6 +74,8 @@ module Spec
74
74
  end
75
75
 
76
76
  it "should use report nil in the error message" do
77
+ allow_message_expectations_on_nil
78
+
77
79
  @this_will_resolve_to_nil.should_receive(:foobar)
78
80
  lambda do
79
81
  @this_will_resolve_to_nil.rspec_verify
@@ -116,9 +116,28 @@ module Spec
116
116
  end
117
117
 
118
118
  end
119
+
120
+ describe Methods, "handling block constraints" do
121
+ it_should_behave_like "mock argument constraints"
122
+
123
+ it "should match arguments against RSpec expectations" do
124
+ @mock.should_receive(:random_call).with {|arg1, arg2, arr, *rest|
125
+ arg1.should == 5
126
+ arg2.should have_at_least(3).characters
127
+ arg2.should have_at_most(10).characters
128
+ arr.map {|i| i * 2}.should == [2,4,6]
129
+ rest.should == [:fee, "fi", 4]
130
+ }
131
+ @mock.random_call 5, "hello", [1,2,3], :fee, "fi", 4
132
+ end
133
+ end
119
134
 
120
135
  describe Methods, "handling non-constraint arguments" do
121
-
136
+
137
+ before(:each) do
138
+ @mock = Mock.new("test mock")
139
+ end
140
+
122
141
  it "should match non special symbol (can be removed when deprecated symbols are removed)" do
123
142
  @mock.should_receive(:random_call).with(:some_symbol)
124
143
  @mock.random_call(:some_symbol)
@@ -150,11 +169,6 @@ module Spec
150
169
  @mock.should_receive(:random_call).with(:a => "a", :b => "b")
151
170
  @mock.random_call(opts)
152
171
  end
153
-
154
- it "should match against a Matcher" do
155
- @mock.should_receive(:msg).with(equal(37))
156
- @mock.msg(37)
157
- end
158
172
  end
159
173
  end
160
174
  end
@@ -14,6 +14,7 @@ module Spec
14
14
  end
15
15
  end
16
16
  @instance = @class.new
17
+ @stub = Object.new
17
18
  end
18
19
 
19
20
  it "should return expected value when expected message is received" do
@@ -44,6 +45,12 @@ module Spec
44
45
  @instance.rspec_verify
45
46
  end.should_not raise_error
46
47
  end
48
+
49
+ it "should handle multiple stubbed methods" do
50
+ @instance.stub!(:msg1 => 1, :msg2 => 2)
51
+ @instance.msg1.should == 1
52
+ @instance.msg2.should == 2
53
+ end
47
54
 
48
55
  it "should clear itself when verified" do
49
56
  @instance.stub!(:this_should_go).and_return(:blah)
@@ -3,16 +3,16 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
3
3
  module Spec
4
4
  module Runner
5
5
  describe CommandLine, ".run" do
6
- it_should_behave_like "sandboxed rspec_options"
6
+ include SandboxedOptions
7
7
  attr_reader :options, :err, :out
8
8
  before do
9
9
  @err = options.error_stream
10
10
  @out = options.output_stream
11
11
  end
12
-
12
+
13
13
  it "should run directory" do
14
14
  file = File.dirname(__FILE__) + '/../../../examples/pure'
15
- Spec::Runner::CommandLine.run(OptionParser.parse([file,"-p","**/*.rb"], @err, @out))
15
+ run_with(OptionParser.parse([file,"-p","**/*.rb"], @err, @out))
16
16
 
17
17
  @out.rewind
18
18
  @out.read.should =~ /\d+ examples, 0 failures, 3 pending/n
@@ -20,7 +20,7 @@ module Spec
20
20
 
21
21
  it "should run file" do
22
22
  file = File.dirname(__FILE__) + '/../../../failing_examples/predicate_example.rb'
23
- Spec::Runner::CommandLine.run(OptionParser.parse([file], @err, @out))
23
+ run_with(OptionParser.parse([file], @err, @out))
24
24
 
25
25
  @out.rewind
26
26
  @out.read.should =~ /2 examples, 1 failure/n
@@ -130,18 +130,11 @@ module Spec
130
130
  options.reporter.should_receive(:add_example_group).with(example_group)
131
131
 
132
132
  options.add_example_group example_group
133
- Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
133
+ run_with(options)
134
134
 
135
135
  should_has_run.should be_true
136
136
  should_not_has_run.should be_false
137
137
  end
138
-
139
- it "sets Spec.run to true" do
140
- ::Spec.run = false
141
- ::Spec.should_not be_run
142
- Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
143
- ::Spec.should be_run
144
- end
145
138
  end
146
139
  end
147
140
  end
@@ -3,6 +3,8 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
3
3
  module Spec
4
4
  module Runner
5
5
  describe DrbCommandLine, "without running local server" do
6
+ include SandboxedOptions
7
+
6
8
  unless Config::CONFIG['ruby_install_name'] == 'jruby'
7
9
  it "should print error when there is no running local server" do
8
10
  err = StringIO.new
@@ -15,18 +17,22 @@ module Spec
15
17
  end
16
18
  end
17
19
 
18
- class DrbCommandLineSpec < ::Spec::Example::ExampleGroup
19
- describe DrbCommandLine, "with local server"
20
+ describe "with local server" do
20
21
 
21
22
  class CommandLineForSpec
22
23
  def self.run(argv, stderr, stdout)
23
- exit Spec::Runner::CommandLine.run(OptionParser.parse(argv, stderr, stdout))
24
+ orig_options = Spec::Runner.options
25
+ tmp_options = OptionParser.parse(argv, stderr, stdout)
26
+ Spec::Runner.use tmp_options
27
+ Spec::Runner::CommandLine.run(tmp_options)
28
+ ensure
29
+ Spec::Runner.use orig_options
24
30
  end
25
31
  end
26
32
 
27
33
  unless Config::CONFIG['ruby_install_name'] == 'jruby'
28
34
  before(:all) do
29
- DRb.start_service("druby://localhost:8989", CommandLineForSpec)
35
+ DRb.start_service("druby://127.0.0.1:8989", CommandLineForSpec)
30
36
  @@drb_example_file_counter = 0
31
37
  end
32
38
 
@@ -45,7 +51,7 @@ module Spec
45
51
 
46
52
  it "should run against local server" do
47
53
  out = run_spec_via_druby(['--version'])
48
- out.should =~ /RSpec/n
54
+ out.should =~ /rspec version \d+\.\d+\.\d+.*/n
49
55
  end
50
56
 
51
57
  it "should output green colorized text when running with --colour option" do
@@ -86,7 +92,8 @@ module Spec
86
92
  out.rewind; out.read
87
93
  end
88
94
  end
89
-
95
+
90
96
  end
97
+
91
98
  end
92
99
  end