rspec-mocks 2.5.0 → 2.6.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/.travis.yml +7 -0
  2. data/Gemfile +13 -12
  3. data/Guardfile +3 -3
  4. data/README.md +2 -0
  5. data/features/.nav +4 -0
  6. data/features/Changelog.md +12 -0
  7. data/features/README.markdown +44 -4
  8. data/features/message_expectations/any_instance.feature +19 -0
  9. data/features/message_expectations/block_local_expectations.feature.pending +2 -2
  10. data/features/message_expectations/expect_message.feature +3 -3
  11. data/features/message_expectations/warn_when_expectation_is_set_on_nil.feature +3 -3
  12. data/features/method_stubs/README.md +32 -24
  13. data/features/method_stubs/any_instance.feature +23 -0
  14. data/features/method_stubs/as_null_object.feature +36 -0
  15. data/features/method_stubs/simple_return_value.feature +2 -2
  16. data/features/method_stubs/stub_chain.feature +13 -6
  17. data/features/method_stubs/stub_implementation.feature +1 -1
  18. data/features/method_stubs/to_ary.feature +45 -0
  19. data/features/outside_rspec/configuration.feature +3 -3
  20. data/features/outside_rspec/standalone.feature +2 -2
  21. data/features/step_definitions/additional_cli_steps.rb +4 -0
  22. data/features/support/env.rb +5 -1
  23. data/lib/rspec/mocks.rb +2 -1
  24. data/lib/rspec/mocks/any_instance.rb +246 -0
  25. data/lib/rspec/mocks/extensions/psych.rb +23 -0
  26. data/lib/rspec/mocks/framework.rb +1 -0
  27. data/lib/rspec/mocks/message_expectation.rb +7 -4
  28. data/lib/rspec/mocks/methods.rb +1 -1
  29. data/lib/rspec/mocks/mock.rb +2 -2
  30. data/lib/rspec/mocks/serialization.rb +5 -3
  31. data/lib/rspec/mocks/space.rb +1 -1
  32. data/lib/rspec/mocks/version.rb +1 -1
  33. data/spec/rspec/mocks/and_yield_spec.rb +3 -3
  34. data/spec/rspec/mocks/any_instance_spec.rb +578 -0
  35. data/spec/rspec/mocks/any_number_of_times_spec.rb +22 -28
  36. data/spec/rspec/mocks/at_least_spec.rb +6 -0
  37. data/spec/rspec/mocks/at_most_spec.rb +6 -0
  38. data/spec/rspec/mocks/bug_report_10263_spec.rb +12 -14
  39. data/spec/rspec/mocks/bug_report_7611_spec.rb +2 -4
  40. data/spec/rspec/mocks/failing_argument_matchers_spec.rb +45 -46
  41. data/spec/rspec/mocks/nil_expectation_warning_spec.rb +1 -2
  42. data/spec/rspec/mocks/passing_argument_matchers_spec.rb +119 -122
  43. data/spec/rspec/mocks/precise_counts_spec.rb +6 -0
  44. data/spec/rspec/mocks/serialization_spec.rb +21 -3
  45. data/spec/rspec/mocks/stub_chain_spec.rb +72 -37
  46. data/spec/rspec/mocks/stub_spec.rb +64 -61
  47. data/spec/rspec/mocks/to_ary_spec.rb +31 -0
  48. metadata +32 -15
  49. data/spec/rspec/mocks/bug_report_7805_spec.rb +0 -22
  50. data/spec/rspec/mocks/bug_report_8302_spec.rb +0 -26
@@ -1,36 +1,30 @@
1
1
  require 'spec_helper'
2
2
 
3
- module RSpec
4
- module Mocks
5
-
6
- describe "AnyNumberOfTimes" do
7
- before(:each) do
8
- @mock = RSpec::Mocks::Mock.new("test mock")
9
- end
3
+ describe "AnyNumberOfTimes" do
4
+ before(:each) do
5
+ @mock = RSpec::Mocks::Mock.new("test mock")
6
+ end
10
7
 
11
- it "passes if any number of times method is called many times" do
12
- @mock.should_receive(:random_call).any_number_of_times
13
- (1..10).each do
14
- @mock.random_call
15
- end
16
- end
8
+ it "passes if any number of times method is called many times" do
9
+ @mock.should_receive(:random_call).any_number_of_times
10
+ (1..10).each do
11
+ @mock.random_call
12
+ end
13
+ end
17
14
 
18
- it "passes if any number of times method is called once" do
19
- @mock.should_receive(:random_call).any_number_of_times
20
- @mock.random_call
21
- end
22
-
23
- it "passes if any number of times method is not called" do
24
- @mock.should_receive(:random_call).any_number_of_times
25
- end
15
+ it "passes if any number of times method is called once" do
16
+ @mock.should_receive(:random_call).any_number_of_times
17
+ @mock.random_call
18
+ end
26
19
 
27
- it "returns the mocked value when called after a similar stub" do
28
- @mock.stub(:message).and_return :stub_value
29
- @mock.should_receive(:message).any_number_of_times.and_return(:mock_value)
30
- @mock.message.should == :mock_value
31
- @mock.message.should == :mock_value
32
- end
33
- end
20
+ it "passes if any number of times method is not called" do
21
+ @mock.should_receive(:random_call).any_number_of_times
22
+ end
34
23
 
24
+ it "returns the mocked value when called after a similar stub" do
25
+ @mock.stub(:message).and_return :stub_value
26
+ @mock.should_receive(:message).any_number_of_times.and_return(:mock_value)
27
+ @mock.message.should == :mock_value
28
+ @mock.message.should == :mock_value
35
29
  end
36
30
  end
@@ -92,6 +92,12 @@ module RSpec
92
92
  @mock.random_call
93
93
  @mock.rspec_verify
94
94
  end
95
+
96
+ it "returns the value given by a block when the at least once method is called" do
97
+ @mock.should_receive(:to_s).at_least(:once) { "testing" }
98
+ @mock.to_s.should == "testing"
99
+ @mock.rspec_verify
100
+ end
95
101
  end
96
102
  end
97
103
  end
@@ -88,6 +88,12 @@ module RSpec
88
88
  @mock.should_receive(:random_call).at_most(:twice)
89
89
  @mock.rspec_verify
90
90
  end
91
+
92
+ it "returns the value given by a block when the at most once method is called" do
93
+ @mock.should_receive(:to_s).at_most(:once) { "testing" }
94
+ @mock.to_s.should == "testing"
95
+ @mock.rspec_verify
96
+ end
91
97
  end
92
98
  end
93
99
  end
@@ -1,26 +1,24 @@
1
- describe "Mock" do
2
- before do
3
- @double = double("test double")
4
- end
5
-
6
- specify "when one example has an expectation (non-mock) inside the block passed to the mock" do
7
- @double.should_receive(:msg) do |b|
8
- b.should be_true #this call exposes the problem
1
+ describe "Double" do
2
+ let(:test_double) { double }
3
+
4
+ specify "when one example has an expectation inside the block passed to should_receive" do
5
+ test_double.should_receive(:msg) do |arg|
6
+ arg.should be_true #this call exposes the problem
9
7
  end
10
8
  begin
11
- @double.msg(false)
9
+ test_double.msg(false)
12
10
  rescue Exception
13
11
  end
14
12
  end
15
13
 
16
14
  specify "then the next example should behave as expected instead of saying" do
17
- @double.should_receive(:foobar)
18
- @double.foobar
19
- @double.rspec_verify
15
+ test_double.should_receive(:foobar)
16
+ test_double.foobar
17
+ test_double.rspec_verify
20
18
  begin
21
- @double.foobar
19
+ test_double.foobar
22
20
  rescue Exception => e
23
- e.message.should == "Double \"test double\" received unexpected message :foobar with (no args)"
21
+ e.message.should == "Double received unexpected message :foobar with (no args)"
24
22
  end
25
23
  end
26
24
  end
@@ -2,11 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  module Bug7611
4
4
  describe "A Partial Mock" do
5
- class Foo
6
- end
5
+ class Foo; end
6
+ class Bar < Foo; end
7
7
 
8
- class Bar < Foo
9
- end
10
8
  it "respects subclasses" do
11
9
  Foo.stub(:new).and_return(Object.new)
12
10
  end
@@ -4,93 +4,92 @@ module RSpec
4
4
  module Mocks
5
5
  describe "failing MockArgumentMatchers" do
6
6
  before(:each) do
7
- @mock = double("test double")
8
- @reporter = RSpec::Mocks::Mock.new("reporter").as_null_object
7
+ @double = double("double")
8
+ @reporter = double("reporter").as_null_object
9
9
  end
10
10
 
11
11
  after(:each) do
12
- @mock.rspec_reset
12
+ @double.rspec_reset
13
13
  end
14
14
 
15
15
  it "rejects non boolean" do
16
- @mock.should_receive(:random_call).with(boolean())
17
- lambda do
18
- @mock.random_call("false")
19
- end.should raise_error(RSpec::Mocks::MockExpectationError)
16
+ @double.should_receive(:random_call).with(boolean())
17
+ expect do
18
+ @double.random_call("false")
19
+ end.to raise_error(RSpec::Mocks::MockExpectationError)
20
20
  end
21
21
 
22
22
  it "rejects non numeric" do
23
- @mock.should_receive(:random_call).with(an_instance_of(Numeric))
24
- lambda do
25
- @mock.random_call("1")
26
- end.should raise_error(RSpec::Mocks::MockExpectationError)
23
+ @double.should_receive(:random_call).with(an_instance_of(Numeric))
24
+ expect do
25
+ @double.random_call("1")
26
+ end.to raise_error(RSpec::Mocks::MockExpectationError)
27
27
  end
28
28
 
29
29
  it "rejects non string" do
30
- @mock.should_receive(:random_call).with(an_instance_of(String))
31
- lambda do
32
- @mock.random_call(123)
33
- end.should raise_error(RSpec::Mocks::MockExpectationError)
30
+ @double.should_receive(:random_call).with(an_instance_of(String))
31
+ expect do
32
+ @double.random_call(123)
33
+ end.to raise_error(RSpec::Mocks::MockExpectationError)
34
34
  end
35
35
 
36
36
  it "rejects goose when expecting a duck" do
37
- @mock.should_receive(:random_call).with(duck_type(:abs, :div))
38
- lambda { @mock.random_call("I don't respond to :abs or :div") }.should raise_error(RSpec::Mocks::MockExpectationError)
37
+ @double.should_receive(:random_call).with(duck_type(:abs, :div))
38
+ expect { @double.random_call("I don't respond to :abs or :div") }.to raise_error(RSpec::Mocks::MockExpectationError)
39
39
  end
40
40
 
41
41
  it "fails if regexp does not match submitted string" do
42
- @mock.should_receive(:random_call).with(/bcd/)
43
- lambda { @mock.random_call("abc") }.should raise_error(RSpec::Mocks::MockExpectationError)
42
+ @double.should_receive(:random_call).with(/bcd/)
43
+ expect { @double.random_call("abc") }.to raise_error(RSpec::Mocks::MockExpectationError)
44
44
  end
45
45
 
46
46
  it "fails if regexp does not match submitted regexp" do
47
- @mock.should_receive(:random_call).with(/bcd/)
48
- lambda { @mock.random_call(/bcde/) }.should raise_error(RSpec::Mocks::MockExpectationError)
47
+ @double.should_receive(:random_call).with(/bcd/)
48
+ expect { @double.random_call(/bcde/) }.to raise_error(RSpec::Mocks::MockExpectationError)
49
49
  end
50
50
 
51
51
  it "fails for a hash w/ wrong values" do
52
- @mock.should_receive(:random_call).with(:a => "b", :c => "d")
53
- lambda do
54
- @mock.random_call(:a => "b", :c => "e")
55
- end.should raise_error(RSpec::Mocks::MockExpectationError, /Double "test double" received :random_call with unexpected arguments\n expected: \(\{(:a=>\"b\", :c=>\"d\"|:c=>\"d\", :a=>\"b\")\}\)\n got: \(\{(:a=>\"b\", :c=>\"e\"|:c=>\"e\", :a=>\"b\")\}\)/)
52
+ @double.should_receive(:random_call).with(:a => "b", :c => "d")
53
+ expect do
54
+ @double.random_call(:a => "b", :c => "e")
55
+ end.to raise_error(RSpec::Mocks::MockExpectationError, /Double "double" received :random_call with unexpected arguments\n expected: \(\{(:a=>\"b\", :c=>\"d\"|:c=>\"d\", :a=>\"b\")\}\)\n got: \(\{(:a=>\"b\", :c=>\"e\"|:c=>\"e\", :a=>\"b\")\}\)/)
56
56
  end
57
57
 
58
58
  it "fails for a hash w/ wrong keys" do
59
- @mock.should_receive(:random_call).with(:a => "b", :c => "d")
60
- lambda do
61
- @mock.random_call("a" => "b", "c" => "d")
62
- end.should raise_error(RSpec::Mocks::MockExpectationError, /Double "test double" received :random_call with unexpected arguments\n expected: \(\{(:a=>\"b\", :c=>\"d\"|:c=>\"d\", :a=>\"b\")\}\)\n got: \(\{(\"a\"=>\"b\", \"c\"=>\"d\"|\"c\"=>\"d\", \"a\"=>\"b\")\}\)/)
59
+ @double.should_receive(:random_call).with(:a => "b", :c => "d")
60
+ expect do
61
+ @double.random_call("a" => "b", "c" => "d")
62
+ end.to raise_error(RSpec::Mocks::MockExpectationError, /Double "double" received :random_call with unexpected arguments\n expected: \(\{(:a=>\"b\", :c=>\"d\"|:c=>\"d\", :a=>\"b\")\}\)\n got: \(\{(\"a\"=>\"b\", \"c\"=>\"d\"|\"c\"=>\"d\", \"a\"=>\"b\")\}\)/)
63
63
  end
64
64
 
65
65
  it "matches against a Matcher" do
66
- lambda do
67
- @mock.should_receive(:msg).with(equal(3))
68
- @mock.msg(37)
69
- end.should raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :msg with unexpected arguments\n expected: (equal 3)\n got: (37)")
66
+ expect do
67
+ @double.should_receive(:msg).with(equal(3))
68
+ @double.msg(37)
69
+ end.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"double\" received :msg with unexpected arguments\n expected: (equal 3)\n got: (37)")
70
70
  end
71
71
 
72
72
  it "fails no_args with one arg" do
73
- lambda do
74
- @mock.should_receive(:msg).with(no_args)
75
- @mock.msg(37)
76
- end.should raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :msg with unexpected arguments\n expected: (no args)\n got: (37)")
73
+ expect do
74
+ @double.should_receive(:msg).with(no_args)
75
+ @double.msg(37)
76
+ end.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"double\" received :msg with unexpected arguments\n expected: (no args)\n got: (37)")
77
77
  end
78
78
 
79
79
  it "fails hash_including with missing key" do
80
- lambda do
81
- @mock.should_receive(:msg).with(hash_including(:a => 1))
82
- @mock.msg({})
83
- end.should raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :msg with unexpected arguments\n expected: (hash_including(:a=>1))\n got: ({})")
80
+ expect do
81
+ @double.should_receive(:msg).with(hash_including(:a => 1))
82
+ @double.msg({})
83
+ end.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"double\" received :msg with unexpected arguments\n expected: (hash_including(:a=>1))\n got: ({})")
84
84
  end
85
85
 
86
86
  it "fails with block matchers" do
87
- lambda do
88
- @mock.should_receive(:msg).with {|arg| arg.should == :received }
89
- @mock.msg :no_msg_for_you
90
- end.should raise_error(RSpec::Expectations::ExpectationNotMetError, /expected: :received.*\s*.*got: :no_msg_for_you/)
87
+ expect do
88
+ @double.should_receive(:msg).with {|arg| arg.should == :received }
89
+ @double.msg :no_msg_for_you
90
+ end.to raise_error(RSpec::Expectations::ExpectationNotMetError, /expected: :received.*\s*.*got: :no_msg_for_you/)
91
91
  end
92
92
 
93
93
  end
94
94
  end
95
95
  end
96
-
@@ -13,9 +13,8 @@ module RSpec
13
13
  module Mocks
14
14
 
15
15
  describe "an expectation set on nil" do
16
-
17
16
  it "issues a warning with file and line number information" do
18
- expected_warning = %r%An expectation of :foo was set on nil. Called from #{__FILE__}:#{__LINE__+3}(:in `block \(2 levels\) in <module:Mocks>')?. Use allow_message_expectations_on_nil to disable warnings.%
17
+ expected_warning = %r%An expectation of :foo was set on nil. Called from #{__FILE__}:#{__LINE__+3}(:in .+)?. Use allow_message_expectations_on_nil to disable warnings.%
19
18
  Kernel.should_receive(:warn).with(expected_warning)
20
19
 
21
20
  nil.should_receive(:foo)
@@ -1,144 +1,141 @@
1
1
  require 'spec_helper'
2
2
 
3
- def include_mock_argument_matchers
4
- before(:each) do
5
- @mock = RSpec::Mocks::Mock.new("test mock")
6
- Kernel.stub(:warn)
7
- end
8
-
9
- after(:each) do
10
- @mock.rspec_verify
11
- end
12
- end
13
3
  module RSpec
14
4
  module Mocks
15
-
16
- describe Methods, "handling argument matchers" do
17
- include_mock_argument_matchers
18
-
19
- it "accepts true as boolean()" do
20
- @mock.should_receive(:random_call).with(boolean())
21
- @mock.random_call(true)
5
+ describe Methods do
6
+ before(:each) do
7
+ @double = double('double')
8
+ Kernel.stub(:warn)
22
9
  end
23
10
 
24
- it "accepts false as boolean()" do
25
- @mock.should_receive(:random_call).with(boolean())
26
- @mock.random_call(false)
11
+ after(:each) do
12
+ @double.rspec_verify
27
13
  end
28
14
 
29
- it "accepts fixnum as kind_of(Numeric)" do
30
- @mock.should_receive(:random_call).with(kind_of(Numeric))
31
- @mock.random_call(1)
32
- end
15
+ context "handling argument matchers" do
16
+ it "accepts true as boolean()" do
17
+ @double.should_receive(:random_call).with(boolean())
18
+ @double.random_call(true)
19
+ end
33
20
 
34
- it "accepts float as an_instance_of(Numeric)" do
35
- @mock.should_receive(:random_call).with(kind_of(Numeric))
36
- @mock.random_call(1.5)
37
- end
38
-
39
- it "accepts fixnum as instance_of(Fixnum)" do
40
- @mock.should_receive(:random_call).with(instance_of(Fixnum))
41
- @mock.random_call(1)
42
- end
21
+ it "accepts false as boolean()" do
22
+ @double.should_receive(:random_call).with(boolean())
23
+ @double.random_call(false)
24
+ end
43
25
 
44
- it "does NOT accept fixnum as instance_of(Numeric)" do
45
- @mock.should_not_receive(:random_call).with(instance_of(Numeric))
46
- @mock.random_call(1)
47
- end
26
+ it "accepts fixnum as kind_of(Numeric)" do
27
+ @double.should_receive(:random_call).with(kind_of(Numeric))
28
+ @double.random_call(1)
29
+ end
48
30
 
49
- it "does NOT accept float as instance_of(Numeric)" do
50
- @mock.should_not_receive(:random_call).with(instance_of(Numeric))
51
- @mock.random_call(1.5)
52
- end
31
+ it "accepts float as an_instance_of(Numeric)" do
32
+ @double.should_receive(:random_call).with(kind_of(Numeric))
33
+ @double.random_call(1.5)
34
+ end
53
35
 
54
- it "accepts string as anything()" do
55
- @mock.should_receive(:random_call).with("a", anything(), "c")
56
- @mock.random_call("a", "whatever", "c")
57
- end
36
+ it "accepts fixnum as instance_of(Fixnum)" do
37
+ @double.should_receive(:random_call).with(instance_of(Fixnum))
38
+ @double.random_call(1)
39
+ end
58
40
 
59
- it "matches duck type with one method" do
60
- @mock.should_receive(:random_call).with(duck_type(:length))
61
- @mock.random_call([])
62
- end
41
+ it "does NOT accept fixnum as instance_of(Numeric)" do
42
+ @double.should_not_receive(:random_call).with(instance_of(Numeric))
43
+ @double.random_call(1)
44
+ end
63
45
 
64
- it "matches duck type with two methods" do
65
- @mock.should_receive(:random_call).with(duck_type(:abs, :div))
66
- @mock.random_call(1)
67
- end
68
-
69
- it "matches no args against any_args()" do
70
- @mock.should_receive(:random_call).with(any_args)
71
- @mock.random_call()
72
- end
73
-
74
- it "matches one arg against any_args()" do
75
- @mock.should_receive(:random_call).with(any_args)
76
- @mock.random_call("a string")
77
- end
78
-
79
- it "matches no args against no_args()" do
80
- @mock.should_receive(:random_call).with(no_args)
81
- @mock.random_call()
82
- end
83
-
84
- it "matches hash with hash_including same hash" do
85
- @mock.should_receive(:random_call).with(hash_including(:a => 1))
86
- @mock.random_call(:a => 1)
87
- end
88
-
89
- end
46
+ it "does NOT accept float as instance_of(Numeric)" do
47
+ @double.should_not_receive(:random_call).with(instance_of(Numeric))
48
+ @double.random_call(1.5)
49
+ end
90
50
 
91
- describe Methods, "handling block matchers" do
92
- include_mock_argument_matchers
93
-
94
- it "matches arguments against RSpec expectations" do
95
- @mock.should_receive(:random_call).with {|arg1, arg2, arr, *rest|
96
- arg1.should == 5
97
- arg2.should have_at_least(3).characters
98
- arg2.should have_at_most(10).characters
99
- arr.map {|i| i * 2}.should == [2,4,6]
100
- rest.should == [:fee, "fi", 4]
101
- }
102
- @mock.random_call 5, "hello", [1,2,3], :fee, "fi", 4
103
- end
104
- end
105
-
106
- describe Methods, "handling non-matcher arguments" do
107
-
108
- before(:each) do
109
- @mock = RSpec::Mocks::Mock.new("test mock")
110
- end
111
-
112
- it "matches non special symbol (can be removed when deprecated symbols are removed)" do
113
- @mock.should_receive(:random_call).with(:some_symbol)
114
- @mock.random_call(:some_symbol)
115
- end
51
+ it "accepts string as anything()" do
52
+ @double.should_receive(:random_call).with("a", anything(), "c")
53
+ @double.random_call("a", "whatever", "c")
54
+ end
116
55
 
117
- it "matches string against regexp" do
118
- @mock.should_receive(:random_call).with(/bcd/)
119
- @mock.random_call("abcde")
120
- end
56
+ it "matches duck type with one method" do
57
+ @double.should_receive(:random_call).with(duck_type(:length))
58
+ @double.random_call([])
59
+ end
121
60
 
122
- it "matches regexp against regexp" do
123
- @mock.should_receive(:random_call).with(/bcd/)
124
- @mock.random_call(/bcd/)
125
- end
126
-
127
- it "matches against a hash submitted and received by value" do
128
- @mock.should_receive(:random_call).with(:a => "a", :b => "b")
129
- @mock.random_call(:a => "a", :b => "b")
61
+ it "matches duck type with two methods" do
62
+ @double.should_receive(:random_call).with(duck_type(:abs, :div))
63
+ @double.random_call(1)
64
+ end
65
+
66
+ it "matches no args against any_args()" do
67
+ @double.should_receive(:random_call).with(any_args)
68
+ @double.random_call()
69
+ end
70
+
71
+ it "matches one arg against any_args()" do
72
+ @double.should_receive(:random_call).with(any_args)
73
+ @double.random_call("a string")
74
+ end
75
+
76
+ it "matches no args against no_args()" do
77
+ @double.should_receive(:random_call).with(no_args)
78
+ @double.random_call()
79
+ end
80
+
81
+ it "matches hash with hash_including same hash" do
82
+ @double.should_receive(:random_call).with(hash_including(:a => 1))
83
+ @double.random_call(:a => 1)
84
+ end
130
85
  end
131
-
132
- it "matches against a hash submitted by reference and received by value" do
133
- opts = {:a => "a", :b => "b"}
134
- @mock.should_receive(:random_call).with(opts)
135
- @mock.random_call(:a => "a", :b => "b")
86
+
87
+ context "handling block matchers" do
88
+ it "matches arguments against RSpec expectations" do
89
+ @double.should_receive(:random_call).with {|arg1, arg2, arr, *rest|
90
+ arg1.should == 5
91
+ arg2.should have_at_least(3).characters
92
+ arg2.should have_at_most(10).characters
93
+ arr.map {|i| i * 2}.should == [2,4,6]
94
+ rest.should == [:fee, "fi", 4]
95
+ }
96
+ @double.random_call 5, "hello", [1,2,3], :fee, "fi", 4
97
+ end
98
+
99
+ it "does not eval the block as the return value" do
100
+ eval_count = 0
101
+ @double.should_receive(:msg).with {|a| eval_count += 1}
102
+ @double.msg(:ignore)
103
+ eval_count.should eq(1)
104
+ end
136
105
  end
137
-
138
- it "matches against a hash submitted by value and received by reference" do
139
- opts = {:a => "a", :b => "b"}
140
- @mock.should_receive(:random_call).with(:a => "a", :b => "b")
141
- @mock.random_call(opts)
106
+
107
+ context "handling non-matcher arguments" do
108
+ it "matches non special symbol (can be removed when deprecated symbols are removed)" do
109
+ @double.should_receive(:random_call).with(:some_symbol)
110
+ @double.random_call(:some_symbol)
111
+ end
112
+
113
+ it "matches string against regexp" do
114
+ @double.should_receive(:random_call).with(/bcd/)
115
+ @double.random_call("abcde")
116
+ end
117
+
118
+ it "matches regexp against regexp" do
119
+ @double.should_receive(:random_call).with(/bcd/)
120
+ @double.random_call(/bcd/)
121
+ end
122
+
123
+ it "matches against a hash submitted and received by value" do
124
+ @double.should_receive(:random_call).with(:a => "a", :b => "b")
125
+ @double.random_call(:a => "a", :b => "b")
126
+ end
127
+
128
+ it "matches against a hash submitted by reference and received by value" do
129
+ opts = {:a => "a", :b => "b"}
130
+ @double.should_receive(:random_call).with(opts)
131
+ @double.random_call(:a => "a", :b => "b")
132
+ end
133
+
134
+ it "matches against a hash submitted by value and received by reference" do
135
+ opts = {:a => "a", :b => "b"}
136
+ @double.should_receive(:random_call).with(:a => "a", :b => "b")
137
+ @double.random_call(opts)
138
+ end
142
139
  end
143
140
  end
144
141
  end