rspec 1.2.9 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/History.rdoc +34 -1
  2. data/License.txt +1 -1
  3. data/Manifest.txt +11 -4
  4. data/README.rdoc +2 -3
  5. data/Rakefile +17 -13
  6. data/Upgrade.rdoc +63 -2
  7. data/features/formatters/nested_formatter.feature +32 -0
  8. data/features/interop/cucumber_stubs_dont_leak.feature +11 -0
  9. data/features/matchers/define_matcher_with_fluent_interface.feature +21 -0
  10. data/features/matchers/define_wrapped_matcher.feature +28 -1
  11. data/features/matchers/match_unless_raises.feature +60 -0
  12. data/features/matchers/match_unless_raises_unexpected_error.feature +39 -0
  13. data/features/mocks/block_local_expectations.feature +62 -0
  14. data/features/step_definitions/running_rspec_steps.rb +9 -0
  15. data/features/step_definitions/stubbing_steps.rb +16 -0
  16. data/features/support/env.rb +1 -0
  17. data/features/support/matchers/smart_match.rb +23 -4
  18. data/geminstaller.yml +28 -0
  19. data/lib/autotest/rspec.rb +14 -7
  20. data/lib/spec/dsl/main.rb +1 -1
  21. data/lib/spec/example/example_methods.rb +4 -0
  22. data/lib/spec/{matchers/extensions → extensions}/instance_exec.rb +0 -0
  23. data/lib/spec/interop/test.rb +1 -1
  24. data/lib/spec/matchers.rb +21 -2
  25. data/lib/spec/matchers/be.rb +167 -128
  26. data/lib/spec/matchers/has.rb +3 -3
  27. data/lib/spec/matchers/have.rb +1 -0
  28. data/lib/spec/matchers/matcher.rb +55 -10
  29. data/lib/spec/matchers/method_missing.rb +2 -2
  30. data/lib/spec/matchers/raise_exception.rb +131 -0
  31. data/lib/spec/matchers/throw_symbol.rb +16 -20
  32. data/lib/spec/mocks/message_expectation.rb +63 -48
  33. data/lib/spec/mocks/methods.rb +13 -8
  34. data/lib/spec/mocks/proxy.rb +43 -22
  35. data/lib/spec/runner/differs/default.rb +1 -1
  36. data/lib/spec/runner/drb_command_line.rb +8 -2
  37. data/lib/spec/runner/example_group_runner.rb +1 -2
  38. data/lib/spec/runner/formatter/nested_text_formatter.rb +6 -3
  39. data/lib/spec/runner/option_parser.rb +2 -0
  40. data/lib/spec/runner/options.rb +6 -1
  41. data/lib/spec/stubs/cucumber.rb +2 -2
  42. data/lib/spec/version.rb +2 -2
  43. data/spec/autotest/autotest_helper.rb +1 -1
  44. data/spec/autotest/discover_spec.rb +2 -2
  45. data/spec/autotest/failed_results_re_spec.rb +2 -2
  46. data/spec/autotest/rspec_spec.rb +21 -6
  47. data/spec/spec/example/example_group_methods_spec.rb +2 -1
  48. data/spec/spec/interop/test/unit/spec_spec.rb +7 -7
  49. data/spec/spec/interop/test/unit/testcase_spec.rb +7 -7
  50. data/spec/spec/interop/test/unit/testsuite_adapter_spec.rb +1 -1
  51. data/spec/spec/matchers/be_spec.rb +159 -10
  52. data/spec/spec/matchers/has_spec.rb +109 -0
  53. data/spec/spec/matchers/matcher_spec.rb +70 -9
  54. data/spec/spec/matchers/raise_exception_spec.rb +345 -0
  55. data/spec/spec/matchers/throw_symbol_spec.rb +83 -58
  56. data/spec/spec/mocks/and_yield_spec.rb +117 -0
  57. data/spec/spec/mocks/mock_spec.rb +2 -2
  58. data/spec/spec/runner/command_line_spec.rb +26 -5
  59. data/spec/spec/runner/drb_command_line_spec.rb +39 -0
  60. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +35 -11
  61. data/spec/spec/runner/option_parser_spec.rb +12 -6
  62. data/spec/spec/runner/options_spec.rb +7 -0
  63. data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +23 -5
  64. metadata +17 -10
  65. data/lib/spec/matchers/raise_error.rb +0 -129
  66. data/spec/spec/matchers/matcher_methods_spec.rb +0 -63
  67. data/spec/spec/matchers/raise_error_spec.rb +0 -333
@@ -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
+
@@ -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])