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
@@ -4,91 +4,116 @@ module Spec
4
4
  module Matchers
5
5
  describe ThrowSymbol do
6
6
  describe "with no args" do
7
- before(:each) { @matcher = ThrowSymbol.new }
8
-
9
- it "should match if any Symbol is thrown" do
10
- @matcher.matches?(lambda{ throw :sym }).should be_true
7
+ let(:matcher) { throw_symbol }
8
+
9
+ it "matches if any Symbol is thrown" do
10
+ matcher.matches?(lambda{ throw :sym }).should be_true
11
11
  end
12
- it "should match if any Symbol is thrown with an arg" do
13
- @matcher.matches?(lambda{ throw :sym, "argument" }).should be_true
12
+
13
+ it "matches if any Symbol is thrown with an arg" do
14
+ matcher.matches?(lambda{ throw :sym, "argument" }).should be_true
14
15
  end
15
- it "should not match if no Symbol is thrown" do
16
- @matcher.matches?(lambda{ }).should be_false
16
+
17
+ it "does not match if no Symbol is thrown" do
18
+ matcher.matches?(lambda{ }).should be_false
17
19
  end
18
- it "should provide a failure message" do
19
- @matcher.matches?(lambda{})
20
- @matcher.failure_message_for_should.should == "expected a Symbol but nothing was thrown"
20
+
21
+ it "provides a failure message" do
22
+ matcher.matches?(lambda{})
23
+ matcher.failure_message_for_should.should == "expected a Symbol but nothing was thrown"
21
24
  end
22
- it "should provide a negative failure message" do
23
- @matcher.matches?(lambda{ throw :sym})
24
- @matcher.failure_message_for_should_not.should == "expected no Symbol, got :sym"
25
+
26
+ it "provides a negative failure message" do
27
+ matcher.matches?(lambda{ throw :sym})
28
+ matcher.failure_message_for_should_not.should == "expected no Symbol, got :sym"
25
29
  end
26
30
  end
27
-
31
+
28
32
  describe "with a symbol" do
29
- before(:each) { @matcher = ThrowSymbol.new(:sym) }
30
-
31
- it "should match if correct Symbol is thrown" do
32
- @matcher.matches?(lambda{ throw :sym }).should be_true
33
+ let(:matcher) { throw_symbol(:sym) }
34
+
35
+ it "matches if correct Symbol is thrown" do
36
+ matcher.matches?(lambda{ throw :sym }).should be_true
33
37
  end
34
- it "should match if correct Symbol is thrown with an arg" do
35
- @matcher.matches?(lambda{ throw :sym, "argument" }).should be_true
38
+
39
+ it "matches if correct Symbol is thrown with an arg" do
40
+ matcher.matches?(lambda{ throw :sym, "argument" }).should be_true
36
41
  end
37
- it "should not match if no Symbol is thrown" do
38
- @matcher.matches?(lambda{ }).should be_false
42
+
43
+ it "does not match if no Symbol is thrown" do
44
+ matcher.matches?(lambda{ }).should be_false
39
45
  end
40
- it "should not match if correct Symbol is thrown" do
41
- @matcher.matches?(lambda{ throw :other_sym }).should be_false
46
+
47
+ it "does not match if correct Symbol is thrown" do
48
+ matcher.matches?(lambda{ throw :other_sym }).should be_false
42
49
  end
43
- it "should provide a failure message when no Symbol is thrown" do
44
- @matcher.matches?(lambda{})
45
- @matcher.failure_message_for_should.should == "expected :sym but nothing was thrown"
50
+
51
+ it "provides a failure message when no Symbol is thrown" do
52
+ matcher.matches?(lambda{})
53
+ matcher.failure_message_for_should.should == "expected :sym but nothing was thrown"
46
54
  end
47
- it "should provide a failure message when wrong Symbol is thrown" do
48
- @matcher.matches?(lambda{ throw :other_sym })
49
- @matcher.failure_message_for_should.should == "expected :sym, got :other_sym"
55
+
56
+ it "provides a failure message when wrong Symbol is thrown" do
57
+ matcher.matches?(lambda{ throw :other_sym })
58
+ matcher.failure_message_for_should.should == "expected :sym, got :other_sym"
50
59
  end
51
- it "should provide a negative failure message" do
52
- @matcher.matches?(lambda{ throw :sym })
53
- @matcher.failure_message_for_should_not.should == "expected :sym not to be thrown"
60
+
61
+ it "provides a negative failure message" do
62
+ matcher.matches?(lambda{ throw :sym })
63
+ matcher.failure_message_for_should_not.should == "expected :sym not to be thrown"
54
64
  end
65
+
55
66
  it "should only match NameErrors raised by uncaught throws" do
56
- @matcher.matches?(lambda{ sym }).should be_false
67
+ matcher.matches?(lambda{ :sym }).should be_false
68
+ end
69
+
70
+ it "bubbles up errors other than NameError" do
71
+ lambda do
72
+ matcher.matches?(lambda{ raise 'foo' })
73
+ end.should raise_error('foo')
57
74
  end
58
75
  end
59
76
 
60
77
  describe "with a symbol and an arg" do
61
- before(:each) { @matcher = ThrowSymbol.new(:sym, "a") }
62
-
63
- it "should match if correct Symbol and args are thrown" do
64
- @matcher.matches?(lambda{ throw :sym, "a" }).should be_true
78
+ let(:matcher) { throw_symbol(:sym, "a") }
79
+
80
+ it "matches if correct Symbol and args are thrown" do
81
+ matcher.matches?(lambda{ throw :sym, "a" }).should be_true
65
82
  end
66
- it "should not match if nothing is thrown" do
67
- @matcher.matches?(lambda{ }).should be_false
83
+
84
+ it "does not match if nothing is thrown" do
85
+ matcher.matches?(lambda{ }).should be_false
68
86
  end
69
- it "should not match if other Symbol is thrown" do
70
- @matcher.matches?(lambda{ throw :other_sym, "a" }).should be_false
87
+
88
+ it "does not match if other Symbol is thrown" do
89
+ matcher.matches?(lambda{ throw :other_sym, "a" }).should be_false
71
90
  end
72
- it "should not match if no arg is thrown" do
73
- @matcher.matches?(lambda{ throw :sym }).should be_false
91
+
92
+ it "does not match if no arg is thrown" do
93
+ matcher.matches?(lambda{ throw :sym }).should be_false
74
94
  end
75
- it "should not match if wrong arg is thrown" do
76
- @matcher.matches?(lambda{ throw :sym, "b" }).should be_false
95
+
96
+ it "does not match if wrong arg is thrown" do
97
+ matcher.matches?(lambda{ throw :sym, "b" }).should be_false
77
98
  end
78
- it "should provide a failure message when no Symbol is thrown" do
79
- @matcher.matches?(lambda{})
80
- @matcher.failure_message_for_should.should == %q[expected :sym with "a" but nothing was thrown]
99
+
100
+ it "provides a failure message when no Symbol is thrown" do
101
+ matcher.matches?(lambda{})
102
+ matcher.failure_message_for_should.should == %q[expected :sym with "a" but nothing was thrown]
81
103
  end
82
- it "should provide a failure message when wrong Symbol is thrown" do
83
- @matcher.matches?(lambda{ throw :other_sym })
84
- @matcher.failure_message_for_should.should == %q[expected :sym with "a", got :other_sym]
104
+
105
+ it "provides a failure message when wrong Symbol is thrown" do
106
+ matcher.matches?(lambda{ throw :other_sym })
107
+ matcher.failure_message_for_should.should == %q[expected :sym with "a", got :other_sym]
85
108
  end
86
- it "should provide a negative failure message" do
87
- @matcher.matches?(lambda{ throw :sym })
88
- @matcher.failure_message_for_should_not.should == %q[expected :sym with "a" not to be thrown]
109
+
110
+ it "provides a negative failure message" do
111
+ matcher.matches?(lambda{ throw :sym })
112
+ matcher.failure_message_for_should_not.should == %q[expected :sym with "a" not to be thrown]
89
113
  end
90
- it "should only match NameErrors raised by uncaught throws" do
91
- @matcher.matches?(lambda{ sym }).should be_false
114
+
115
+ it "only matches NameErrors raised by uncaught throws" do
116
+ matcher.matches?(lambda{ :sym }).should be_false
92
117
  end
93
118
  end
94
119
  end
@@ -0,0 +1,117 @@
1
+ require 'spec_helper'
2
+
3
+ module Spec
4
+ module Mocks
5
+ describe Mock do
6
+ describe "#and_yield" do
7
+
8
+ context "with eval context as block argument" do
9
+ let(:obj) { double }
10
+
11
+ it "evaluates the supplied block as it is read" do
12
+ evaluated = false
13
+ obj.stub(:method_that_accepts_a_block).and_yield do |eval_context|
14
+ evaluated = true
15
+ end
16
+ evaluated.should be_true
17
+ end
18
+
19
+ it "passes an eval context object to the supplied block" do
20
+ obj.stub(:method_that_accepts_a_block).and_yield do |eval_context|
21
+ eval_context.should_not be_nil
22
+ end
23
+ end
24
+
25
+ it "evaluates the block passed to the stubbed method in the context of the supplied eval context" do
26
+ expected_eval_context = nil
27
+ actual_eval_context = nil
28
+
29
+ obj.stub(:method_that_accepts_a_block).and_yield do |eval_context|
30
+ expected_eval_context = eval_context
31
+ end
32
+
33
+ obj.method_that_accepts_a_block do
34
+ actual_eval_context = self
35
+ end
36
+
37
+ actual_eval_context.should equal(expected_eval_context)
38
+ end
39
+
40
+ context "and no yielded arguments" do
41
+
42
+ it "passes when expectations set on the eval context are met" do
43
+ configured_eval_context = nil
44
+ obj.stub(:method_that_accepts_a_block).and_yield do |eval_context|
45
+ configured_eval_context = eval_context
46
+ configured_eval_context.should_receive(:foo)
47
+ end
48
+
49
+ obj.method_that_accepts_a_block do
50
+ foo
51
+ end
52
+
53
+ configured_eval_context.rspec_verify
54
+ end
55
+
56
+ it "fails when expectations set on the eval context are not met" do
57
+ configured_eval_context = nil
58
+ obj.stub(:method_that_accepts_a_block).and_yield do |eval_context|
59
+ configured_eval_context = eval_context
60
+ configured_eval_context.should_receive(:foo)
61
+ end
62
+
63
+ obj.method_that_accepts_a_block do
64
+ # foo is not called here
65
+ end
66
+
67
+ lambda {configured_eval_context.rspec_verify}.should raise_error(MockExpectationError)
68
+ end
69
+
70
+ end
71
+
72
+ context "and yielded arguments" do
73
+
74
+ it "passes when expectations set on the eval context and yielded arguments are met" do
75
+ configured_eval_context = nil
76
+ yielded_arg = Object.new
77
+ obj.stub(:method_that_accepts_a_block).and_yield(yielded_arg) do |eval_context|
78
+ configured_eval_context = eval_context
79
+ configured_eval_context.should_receive(:foo)
80
+ yielded_arg.should_receive(:bar)
81
+ end
82
+
83
+ obj.method_that_accepts_a_block do |obj|
84
+ obj.bar
85
+ foo
86
+ end
87
+
88
+ configured_eval_context.rspec_verify
89
+ yielded_arg.rspec_verify
90
+ end
91
+
92
+ it "fails when expectations set on the eval context and yielded arguments are not met" do
93
+ configured_eval_context = nil
94
+ yielded_arg = Object.new
95
+ obj.stub(:method_that_accepts_a_block).and_yield(yielded_arg) do |eval_context|
96
+ configured_eval_context = eval_context
97
+ configured_eval_context.should_receive(:foo)
98
+ yielded_arg.should_receive(:bar)
99
+ end
100
+
101
+ obj.method_that_accepts_a_block do |obj|
102
+ # obj.bar is not called here
103
+ # foo is not called here
104
+ end
105
+
106
+ lambda {configured_eval_context.rspec_verify}.should raise_error(MockExpectationError)
107
+ lambda {yielded_arg.rspec_verify}.should raise_error(MockExpectationError)
108
+ end
109
+
110
+ end
111
+
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
117
+
@@ -9,10 +9,8 @@ module BugReport496
9
9
 
10
10
  describe "a message expectation on a base class object" do
11
11
  it "should correctly pick up message sent to it subclass" do
12
- pending("fix for http://rspec.lighthouseapp.com/projects/5645/tickets/496") do
13
- BaseClass.should_receive(:new).once
14
- SubClass.new
15
- end
12
+ BaseClass.should_receive(:new).once
13
+ SubClass.new
16
14
  end
17
15
  end
18
16
  end
@@ -150,7 +150,7 @@ module Spec
150
150
  @mock.should_receive(:something) {| bool | bool.should be_true}
151
151
  lambda {
152
152
  @mock.something false
153
- }.should raise_error(MockExpectationError, /Mock "test mock" received :something but passed block failed with: expected true, got false/)
153
+ }.should raise_error(MockExpectationError, /Mock "test mock" received :something but passed block failed with: expected false to be true/)
154
154
  end
155
155
 
156
156
  it "should fail right away when method defined as never is received" do
@@ -359,7 +359,7 @@ module Spec
359
359
  @mock.yield_back
360
360
  }.should raise_error(MockExpectationError, "Mock \"test mock\" asked to yield |[\"wha\", \"zup\"]| but no block was passed")
361
361
  end
362
-
362
+
363
363
  it "should be able to mock send" do
364
364
  @mock.should_receive(:send).with(any_args)
365
365
  @mock.send 'hi'
@@ -9,7 +9,7 @@ module Spec
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/passing'
15
15
  run_with(OptionParser.parse([file,"-p","**/*_spec.rb,**/*_example.rb"], @err, @out))
@@ -41,7 +41,7 @@ module Spec
41
41
  ).should be_true
42
42
  end
43
43
 
44
- it "should dump even if Interrupt exception is occurred" do
44
+ it "should exit if Interrupt exception occurrs during the spec" do
45
45
  example_group = Class.new(::Spec::Example::ExampleGroup) do
46
46
  describe("example_group")
47
47
  it "no error" do
@@ -54,10 +54,31 @@ module Spec
54
54
 
55
55
  options = ::Spec::Runner::Options.new(@err, @out)
56
56
  ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
57
- options.reporter.should_receive(:dump)
58
57
  options.add_example_group(example_group)
59
58
 
60
- Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
59
+ expect {
60
+ Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
61
+ }.to raise_error(SystemExit)
62
+ end
63
+
64
+ it "should exit if Interrupt exception occurrs during an after(:each)" do
65
+ example_group = Class.new(::Spec::Example::ExampleGroup) do
66
+ describe("example_group")
67
+ it "no error" do
68
+ end
69
+
70
+ after do
71
+ raise Interrupt, "I'm interrupting"
72
+ end
73
+ end
74
+
75
+ options = ::Spec::Runner::Options.new(@err, @out)
76
+ ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
77
+ options.add_example_group(example_group)
78
+
79
+ expect {
80
+ Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
81
+ }.to raise_error(SystemExit)
61
82
  end
62
83
 
63
84
  it "should heckle when options have heckle_runner" do
@@ -107,7 +128,7 @@ module Spec
107
128
 
108
129
  ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
109
130
  options.reporter.should_receive(:add_example_group).with(Spec::Example::ExampleGroupProxy.new(example_group))
110
-
131
+
111
132
  Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
112
133
  end
113
134
 
@@ -101,6 +101,45 @@ module Spec
101
101
  end
102
102
  end
103
103
 
104
+ context "#port" do
105
+ before do
106
+ @options = stub("options", :drb_port => nil)
107
+ end
108
+
109
+ context "with no additional configuration" do
110
+ it "defaults to 8989" do
111
+ Spec::Runner::DrbCommandLine.port(@options).should == 8989
112
+ end
113
+ end
114
+
115
+ context "with RSPEC_DRB environment variable set" do
116
+ def with_RSPEC_DRB_set_to(val)
117
+ original = ENV['RSPEC_DRB']
118
+ begin
119
+ ENV['RSPEC_DRB'] = val
120
+ yield
121
+ ensure
122
+ ENV['RSPEC_DRB'] = original
123
+ end
124
+ end
125
+
126
+ it "uses RSPEC_DRB value" do
127
+ with_RSPEC_DRB_set_to('9000') do
128
+ Spec::Runner::DrbCommandLine.port(@options).should == 9000
129
+ end
130
+ end
131
+
132
+ context "and config variable set" do
133
+ it "uses configured value" do
134
+ @options.stub(:drb_port => '5000')
135
+ with_RSPEC_DRB_set_to('9000') do
136
+ Spec::Runner::DrbCommandLine.port(@options).should == 5000
137
+ end
138
+ end
139
+ end
140
+
141
+ end
142
+ end
104
143
  end
105
144
  end
106
145
  end
@@ -9,8 +9,6 @@ module Spec
9
9
  attr_reader :io, :options, :formatter, :example_group
10
10
  before(:each) do
11
11
  @io = StringIO.new
12
- options.stub!(:dry_run).and_return(false)
13
- options.stub!(:colour).and_return(false)
14
12
  @formatter = NestedTextFormatter.new(options, io)
15
13
  @example_group = Class.new(::Spec::Example::ExampleGroupDouble).describe("ExampleGroup")
16
14
  @example_group.example("example") {}
@@ -21,12 +19,12 @@ module Spec
21
19
  formatter.example_group_started(Spec::Example::ExampleGroupProxy.new(example_group))
22
20
  end
23
21
 
24
- before do
22
+ before(:each) do
25
23
  example_group_started
26
24
  end
27
25
 
28
26
  describe "#dump_summary" do
29
- it "should produce standard summary without pending when pending has a 0 count" do
27
+ it "produces standard summary without pending when pending has a 0 count" do
30
28
  formatter.dump_summary(3, 2, 1, 0)
31
29
  io.string.should == <<-OUT
32
30
  ExampleGroup
@@ -37,7 +35,7 @@ Finished in 3 seconds
37
35
  OUT
38
36
  end
39
37
 
40
- it "should produce standard summary" do
38
+ it "produces standard summary" do
41
39
  formatter.dump_summary(3, 2, 1, 4)
42
40
  io.string.should == <<-OUT
43
41
  ExampleGroup
@@ -50,10 +48,11 @@ OUT
50
48
  end
51
49
 
52
50
  describe "#example_group_started" do
51
+
53
52
  describe "when ExampleGroup has a nested description" do
54
-
53
+
55
54
  describe "when ExampleGroup has no parents with nested description" do
56
- it "should push ExampleGroup name" do
55
+ it "pushes ExampleGroup name" do
57
56
  io.string.should eql("ExampleGroup\n")
58
57
  end
59
58
  end
@@ -69,7 +68,7 @@ OUT
69
68
  formatter.example_group_started(Spec::Example::ExampleGroupProxy.new(child_example_group))
70
69
  end
71
70
 
72
- it "should push ExampleGroup name with two spaces of indentation" do
71
+ it "pushes ExampleGroup name with two spaces of indentation" do
73
72
  io.string.should == <<-OUT
74
73
  ExampleGroup
75
74
  Child ExampleGroup
@@ -102,10 +101,9 @@ OUT
102
101
  describe "and parent ExampleGroups have not been printed" do
103
102
  before do
104
103
  formatter.example_group_started(Spec::Example::ExampleGroupProxy.new(grand_child_example_group))
105
-
106
104
  end
107
105
 
108
- it "should print the entire nested ExampleGroup heirarchy" do
106
+ it "prints the entire nested ExampleGroup heirarchy" do
109
107
  io.string.should == <<-OUT
110
108
  ExampleGroup
111
109
  Child ExampleGroup
@@ -170,6 +168,32 @@ OUT
170
168
  io.string.should == ""
171
169
  end
172
170
  end
171
+
172
+ describe "with parallel groups" do
173
+ def make_group(name, parent=::Spec::Example::ExampleGroupDouble)
174
+ Class.new(parent).describe(name)
175
+ end
176
+
177
+ it "excludes duplicated group" do
178
+ parent_1 = make_group("ExampleGroup")
179
+ child_1 = make_group("Child ExampleGroup", parent_1)
180
+ grandchild_1 = make_group("GrandChild ExampleGroup", child_1)
181
+
182
+ parent_2 = make_group("ExampleGroup")
183
+ child_2 = make_group("Child ExampleGroup 2", parent_2)
184
+ grandchild_2 = make_group("GrandChild ExampleGroup", child_2)
185
+
186
+ formatter.example_group_started(Spec::Example::ExampleGroupProxy.new(grandchild_1))
187
+ formatter.example_group_started(Spec::Example::ExampleGroupProxy.new(grandchild_2))
188
+ io.string.should == <<-OUTPUT
189
+ ExampleGroup
190
+ Child ExampleGroup
191
+ GrandChild ExampleGroup
192
+ Child ExampleGroup 2
193
+ GrandChild ExampleGroup
194
+ OUTPUT
195
+ end
196
+ end
173
197
  end
174
198
 
175
199
  describe "#example_failed" do
@@ -302,4 +326,4 @@ OUT
302
326
  end
303
327
  end
304
328
  end
305
- end
329
+ end
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
2
  require 'spec/runner/resources/custom_example_group_runner'
3
- require 'fakefs/safe'
4
3
  require 'fakefs/spec_helpers'
5
4
 
6
5
  describe "OptionParser" do
@@ -15,10 +14,8 @@ describe "OptionParser" do
15
14
  @parser.options
16
15
  end
17
16
 
18
- # FIXME - this entire file should run w/ fakefs
19
17
  describe "with fakefs" do
20
- extend FakeFS::SpecHelpers
21
- use_fakefs
18
+ include FakeFS::SpecHelpers
22
19
 
23
20
  it "should not use colour by default" do
24
21
  options = parse([])
@@ -63,6 +60,15 @@ describe "OptionParser" do
63
60
  options = parse(["--drb", "-u"])
64
61
  options.debug.should be_false
65
62
  end
63
+
64
+ it "should accept port option" do
65
+ options = parse(["--port", "9000"])
66
+ options.drb_port.should == 9000
67
+ end
68
+
69
+ it 'should require argument to port option' do
70
+ lambda { parse(["--port"]) }.should raise_error(OptionParser::MissingArgument)
71
+ end
66
72
 
67
73
  it "should accept dry run option" do
68
74
  options = parse(["--dry-run"])
@@ -518,8 +524,8 @@ describe "OptionParser" do
518
524
  end
519
525
 
520
526
  describe "implicitly loading spec/spec.opts" do
521
- extend FakeFS::SpecHelpers
522
- use_fakefs
527
+ include FakeFS::SpecHelpers
528
+
523
529
  it "uses spec/spec.opts if present" do
524
530
  File.open('spec/spec.opts', 'w') { |f| f.write "--colour" }
525
531
  options = parse(['ignore.rb'])
@@ -266,6 +266,13 @@ module Spec
266
266
  end
267
267
  end
268
268
 
269
+ describe "#drb_port" do
270
+ it "returns a number" do
271
+ @options.drb_port = "400"
272
+ @options.drb_port.should == 400
273
+ end
274
+ end
275
+
269
276
  describe "#number_of_examples" do
270
277
  context "when --example is parsed" do
271
278
  it "provides the number of examples parsed instead of the total number of examples collected" do
@@ -9,12 +9,12 @@ module Spec
9
9
  end
10
10
 
11
11
  it "gracefully handles nil backtrace" do
12
- lambda do
12
+ expect do
13
13
  @tweaker.tweak_backtrace(@error)
14
- end.should_not raise_error
14
+ end.to_not raise_error
15
15
  end
16
16
 
17
- it "gracefully handle backtraces with newlines" do
17
+ it "gracefully handles backtraces with newlines" do
18
18
  @error.set_backtrace(["we like\nbin/spec:\nnewlines"])
19
19
  @tweaker.tweak_backtrace(@error)
20
20
  @error.backtrace.should include("we like\nnewlines")
@@ -47,6 +47,24 @@ module Spec
47
47
  @error.backtrace.should be_empty
48
48
  end
49
49
 
50
+ it "preserves lines in spec" do
51
+ @error.set_backtrace(["spec/foo/bar_spec.rb"])
52
+ @tweaker.tweak_backtrace(@error)
53
+ @error.backtrace.should == ["spec/foo/bar_spec.rb"]
54
+ end
55
+
56
+ it "preserves lines in ./spec" do
57
+ @error.set_backtrace(["./spec/foo/bar_spec.rb"])
58
+ @tweaker.tweak_backtrace(@error)
59
+ @error.backtrace.should == ["./spec/foo/bar_spec.rb"]
60
+ end
61
+
62
+ it "preserves lines in /path/to/project/spec" do
63
+ @error.set_backtrace(["/path/to/project/spec/foo/bar_spec.rb"])
64
+ @tweaker.tweak_backtrace(@error)
65
+ @error.backtrace.should == ["/path/to/project/spec/foo/bar_spec.rb"]
66
+ end
67
+
50
68
  it "removes lines in mock_frameworks/rspec" do
51
69
  element = "mock_frameworks/rspec"
52
70
  @error.set_backtrace([element])
@@ -54,7 +72,7 @@ module Spec
54
72
  @error.backtrace.should be_empty, "Should have removed line with '#{element}'"
55
73
  end
56
74
 
57
- it "removes custom patterns" do
75
+ it "removes custom patterns in regexp form" do
58
76
  element = "/vendor/lib/custom_pattern/"
59
77
  @tweaker.ignore_patterns /custom_pattern/
60
78
  @error.set_backtrace([element])
@@ -62,7 +80,7 @@ module Spec
62
80
  @error.backtrace.should be_empty, "Should have removed line with '#{element}'"
63
81
  end
64
82
 
65
- it "removes custom patterns added as a string" do
83
+ it "removes custom patterns in string form" do
66
84
  element = "/vendor/lib/custom_pattern/"
67
85
  @tweaker.ignore_patterns "custom_pattern"
68
86
  @error.set_backtrace([element])
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
+ $: << '.' # for ruby 1.9
1
2
  require 'stringio'
2
3
 
3
4
  $_spec_spec = true # Prevents Kernel.exit in various places
@@ -109,4 +110,4 @@ end
109
110
 
110
111
  Spec::Runner.configure do |config|
111
112
  config.extend(Macros)
112
- end
113
+ end