mcmire-rr 1.0.5.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. data/CHANGES +269 -0
  2. data/Gemfile +16 -0
  3. data/Gemfile.lock +47 -0
  4. data/LICENSE +22 -0
  5. data/README.rdoc +390 -0
  6. data/Rakefile +49 -0
  7. data/VERSION +1 -0
  8. data/lib/rr.rb +101 -0
  9. data/lib/rr/adapters/minitest.rb +31 -0
  10. data/lib/rr/adapters/rr_methods.rb +146 -0
  11. data/lib/rr/adapters/rspec.rb +61 -0
  12. data/lib/rr/adapters/rspec2.rb +22 -0
  13. data/lib/rr/adapters/test_unit.rb +31 -0
  14. data/lib/rr/blank_slate.rb +17 -0
  15. data/lib/rr/class_instance_method_defined.rb +9 -0
  16. data/lib/rr/double.rb +154 -0
  17. data/lib/rr/double_definitions/child_double_definition_create.rb +27 -0
  18. data/lib/rr/double_definitions/double_definition.rb +365 -0
  19. data/lib/rr/double_definitions/double_definition_create.rb +139 -0
  20. data/lib/rr/double_definitions/double_definition_create_blank_slate.rb +26 -0
  21. data/lib/rr/double_definitions/double_injections/any_instance_of.rb +28 -0
  22. data/lib/rr/double_definitions/double_injections/instance.rb +16 -0
  23. data/lib/rr/double_definitions/strategies/double_injection/any_instance_of.rb +30 -0
  24. data/lib/rr/double_definitions/strategies/double_injection/double_injection_strategy.rb +10 -0
  25. data/lib/rr/double_definitions/strategies/double_injection/instance.rb +17 -0
  26. data/lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb +10 -0
  27. data/lib/rr/double_definitions/strategies/implementation/proxy.rb +60 -0
  28. data/lib/rr/double_definitions/strategies/implementation/reimplementation.rb +14 -0
  29. data/lib/rr/double_definitions/strategies/implementation/strongly_typed_reimplementation.rb +15 -0
  30. data/lib/rr/double_definitions/strategies/strategy.rb +43 -0
  31. data/lib/rr/double_definitions/strategies/strategy_methods.rb +53 -0
  32. data/lib/rr/double_definitions/strategies/verification/dont_allow.rb +31 -0
  33. data/lib/rr/double_definitions/strategies/verification/mock.rb +42 -0
  34. data/lib/rr/double_definitions/strategies/verification/stub.rb +43 -0
  35. data/lib/rr/double_definitions/strategies/verification/verification_strategy.rb +10 -0
  36. data/lib/rr/double_matches.rb +42 -0
  37. data/lib/rr/errors/argument_equality_error.rb +6 -0
  38. data/lib/rr/errors/double_definition_error.rb +6 -0
  39. data/lib/rr/errors/double_not_found_error.rb +6 -0
  40. data/lib/rr/errors/double_order_error.rb +6 -0
  41. data/lib/rr/errors/rr_error.rb +20 -0
  42. data/lib/rr/errors/spy_verification_errors/double_injection_not_found_error.rb +8 -0
  43. data/lib/rr/errors/spy_verification_errors/invocation_count_error.rb +8 -0
  44. data/lib/rr/errors/spy_verification_errors/spy_verification_error.rb +8 -0
  45. data/lib/rr/errors/subject_does_not_implement_method_error.rb +6 -0
  46. data/lib/rr/errors/subject_has_different_arity_error.rb +6 -0
  47. data/lib/rr/errors/times_called_error.rb +6 -0
  48. data/lib/rr/expectations/any_argument_expectation.rb +21 -0
  49. data/lib/rr/expectations/argument_equality_expectation.rb +41 -0
  50. data/lib/rr/expectations/times_called_expectation.rb +57 -0
  51. data/lib/rr/hash_with_object_id_key.rb +46 -0
  52. data/lib/rr/injections/double_injection.rb +220 -0
  53. data/lib/rr/injections/injection.rb +33 -0
  54. data/lib/rr/injections/method_missing_injection.rb +73 -0
  55. data/lib/rr/injections/singleton_method_added_injection.rb +72 -0
  56. data/lib/rr/method_dispatches/base_method_dispatch.rb +84 -0
  57. data/lib/rr/method_dispatches/method_dispatch.rb +59 -0
  58. data/lib/rr/method_dispatches/method_missing_dispatch.rb +61 -0
  59. data/lib/rr/proc_from_block.rb +7 -0
  60. data/lib/rr/recorded_calls.rb +103 -0
  61. data/lib/rr/space.rb +119 -0
  62. data/lib/rr/spy_verification.rb +48 -0
  63. data/lib/rr/spy_verification_proxy.rb +13 -0
  64. data/lib/rr/times_called_matchers/any_times_matcher.rb +18 -0
  65. data/lib/rr/times_called_matchers/at_least_matcher.rb +15 -0
  66. data/lib/rr/times_called_matchers/at_most_matcher.rb +23 -0
  67. data/lib/rr/times_called_matchers/integer_matcher.rb +19 -0
  68. data/lib/rr/times_called_matchers/never_matcher.rb +23 -0
  69. data/lib/rr/times_called_matchers/non_terminal.rb +27 -0
  70. data/lib/rr/times_called_matchers/proc_matcher.rb +11 -0
  71. data/lib/rr/times_called_matchers/range_matcher.rb +21 -0
  72. data/lib/rr/times_called_matchers/terminal.rb +20 -0
  73. data/lib/rr/times_called_matchers/times_called_matcher.rb +44 -0
  74. data/lib/rr/wildcard_matchers.rb +158 -0
  75. data/lib/rr/wildcard_matchers/anything.rb +18 -0
  76. data/lib/rr/wildcard_matchers/boolean.rb +23 -0
  77. data/lib/rr/wildcard_matchers/duck_type.rb +32 -0
  78. data/lib/rr/wildcard_matchers/hash_including.rb +29 -0
  79. data/lib/rr/wildcard_matchers/is_a.rb +25 -0
  80. data/lib/rr/wildcard_matchers/numeric.rb +13 -0
  81. data/lib/rr/wildcard_matchers/range.rb +7 -0
  82. data/lib/rr/wildcard_matchers/regexp.rb +7 -0
  83. data/lib/rr/wildcard_matchers/satisfy.rb +26 -0
  84. data/spec/api/any_instance_of/all_instances_of_spec.rb +12 -0
  85. data/spec/api/any_instance_of/any_instance_of_spec.rb +47 -0
  86. data/spec/api/any_instance_of/instance_of_spec.rb +12 -0
  87. data/spec/api/dont_allow/dont_allow_after_stub_spec.rb +14 -0
  88. data/spec/api/mock/mock_spec.rb +193 -0
  89. data/spec/api/proxy/proxy_spec.rb +86 -0
  90. data/spec/api/spy/spy_spec.rb +49 -0
  91. data/spec/api/strong/strong_spec.rb +87 -0
  92. data/spec/api/stub/stub_spec.rb +152 -0
  93. data/spec/core_spec_suite.rb +18 -0
  94. data/spec/environment_fixture_setup.rb +7 -0
  95. data/spec/minitest_spec_suite.rb +21 -0
  96. data/spec/proc_from_block_spec.rb +14 -0
  97. data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +67 -0
  98. data/spec/rr/adapters/rr_methods_creator_spec.rb +137 -0
  99. data/spec/rr/adapters/rr_methods_space_spec.rb +98 -0
  100. data/spec/rr/adapters/rr_methods_spec_helper.rb +7 -0
  101. data/spec/rr/adapters/rr_methods_times_matcher_spec.rb +13 -0
  102. data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +112 -0
  103. data/spec/rr/double_definitions/double_definition_create_blank_slate_spec.rb +91 -0
  104. data/spec/rr/double_definitions/double_definition_create_spec.rb +443 -0
  105. data/spec/rr/double_injection/double_injection_spec.rb +546 -0
  106. data/spec/rr/double_injection/double_injection_verify_spec.rb +29 -0
  107. data/spec/rr/errors/rr_error_spec.rb +67 -0
  108. data/spec/rr/expectations/any_argument_expectation_spec.rb +47 -0
  109. data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +14 -0
  110. data/spec/rr/expectations/argument_equality_expectation_spec.rb +135 -0
  111. data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +34 -0
  112. data/spec/rr/expectations/hash_including_argument_equality_expectation_spec.rb +82 -0
  113. data/spec/rr/expectations/hash_including_spec.rb +17 -0
  114. data/spec/rr/expectations/satisfy_argument_equality_expectation_spec.rb +59 -0
  115. data/spec/rr/expectations/satisfy_spec.rb +14 -0
  116. data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +22 -0
  117. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +37 -0
  118. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +43 -0
  119. data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +11 -0
  120. data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +58 -0
  121. data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +35 -0
  122. data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +39 -0
  123. data/spec/rr/minitest/minitest_integration_test.rb +59 -0
  124. data/spec/rr/minitest/test_helper.rb +7 -0
  125. data/spec/rr/rspec/invocation_matcher_spec.rb +279 -0
  126. data/spec/rr/rspec/rspec_adapter_spec.rb +63 -0
  127. data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +21 -0
  128. data/spec/rr/rspec/rspec_backtrace_tweaking_spec_fixture.rb +11 -0
  129. data/spec/rr/rspec/rspec_usage_spec.rb +86 -0
  130. data/spec/rr/space/hash_with_object_id_key_spec.rb +88 -0
  131. data/spec/rr/space/space_spec.rb +596 -0
  132. data/spec/rr/test_unit/test_helper.rb +7 -0
  133. data/spec/rr/test_unit/test_unit_backtrace_test.rb +36 -0
  134. data/spec/rr/test_unit/test_unit_integration_test.rb +59 -0
  135. data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +47 -0
  136. data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +55 -0
  137. data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +70 -0
  138. data/spec/rr/times_called_matchers/integer_matcher_spec.rb +70 -0
  139. data/spec/rr/times_called_matchers/proc_matcher_spec.rb +55 -0
  140. data/spec/rr/times_called_matchers/range_matcher_spec.rb +76 -0
  141. data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +118 -0
  142. data/spec/rr/wildcard_matchers/anything_spec.rb +24 -0
  143. data/spec/rr/wildcard_matchers/boolean_spec.rb +36 -0
  144. data/spec/rr/wildcard_matchers/duck_type_spec.rb +52 -0
  145. data/spec/rr/wildcard_matchers/is_a_spec.rb +32 -0
  146. data/spec/rr/wildcard_matchers/numeric_spec.rb +32 -0
  147. data/spec/rr/wildcard_matchers/range_spec.rb +35 -0
  148. data/spec/rr/wildcard_matchers/regexp_spec.rb +43 -0
  149. data/spec/rr_spec.rb +28 -0
  150. data/spec/rspec_spec_suite.rb +16 -0
  151. data/spec/spec_helper.rb +40 -0
  152. data/spec/spec_suite.rb +50 -0
  153. data/spec/spy_verification_spec.rb +129 -0
  154. data/spec/test_unit_spec_suite.rb +20 -0
  155. metadata +220 -0
@@ -0,0 +1,14 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ module RR
4
+ module WildcardMatchers
5
+ describe Satisfy do
6
+ describe "#inspect" do
7
+ it "returns satisfy string" do
8
+ matcher = Satisfy.new(lambda {})
9
+ matcher.inspect.should == "satisfy {block}"
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
+
3
+ module RR
4
+ module Expectations
5
+ describe TimesCalledExpectation do
6
+ context "when using an AnyTimesMatcher" do
7
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation"
8
+
9
+ describe "#verify!" do
10
+ it "always passes" do
11
+ stub(subject).foobar.any_number_of_times
12
+ RR.verify
13
+
14
+ stub(subject).foobar.any_number_of_times
15
+ 10.times {subject.foobar}
16
+ RR.verify
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,37 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
+
3
+ module RR
4
+ module Expectations
5
+ describe TimesCalledExpectation do
6
+ context "when using an AtLeastMatcher" do
7
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation"
8
+
9
+ before do
10
+ mock(subject).foobar.at_least(3)
11
+ end
12
+
13
+ describe "#verify!" do
14
+ it "passes when times called > times" do
15
+ 4.times {subject.foobar}
16
+ RR.verify
17
+ end
18
+
19
+ it "passes when times called == times" do
20
+ 3.times {subject.foobar}
21
+ RR.verify
22
+ end
23
+
24
+ it "raises error when times called < times" do
25
+ subject.foobar
26
+ lambda do
27
+ RR.verify
28
+ end.should raise_error(
29
+ RR::Errors::TimesCalledError,
30
+ "foobar()\nCalled 1 time.\nExpected at least 3 times."
31
+ )
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,43 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
+
3
+ module RR
4
+ module Expectations
5
+ describe TimesCalledExpectation do
6
+ context "when using an AtMostMatcher" do
7
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation"
8
+
9
+ before do
10
+ stub(subject).foobar.at_most(3)
11
+ end
12
+
13
+ describe "#verify!" do
14
+ it "passes when times called == times" do
15
+ 3.times {subject.foobar}
16
+ RR.verify
17
+ end
18
+
19
+ it "passes when times called < times" do
20
+ 2.times {subject.foobar}
21
+ RR.verify
22
+ end
23
+
24
+ it "raises error when times called > times" do
25
+ lambda do
26
+ 4.times {subject.foobar}
27
+ end.should raise_error(
28
+ RR::Errors::TimesCalledError,
29
+ "foobar()\nCalled 4 times.\nExpected at most 3 times."
30
+ )
31
+
32
+ lambda do
33
+ RR.verify
34
+ end.should raise_error(
35
+ RR::Errors::TimesCalledError,
36
+ "foobar()\nCalled 4 times.\nExpected at most 3 times."
37
+ )
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,11 @@
1
+ shared_examples_for "RR::Expectations::TimesCalledExpectation" do
2
+ attr_reader :subject
3
+ it_should_behave_like "Swapped Space"
4
+ before do
5
+ @subject = Object.new
6
+ end
7
+
8
+ def raises_expectation_error(&block)
9
+ lambda {block.call}.should raise_error(RR::Errors::TimesCalledError)
10
+ end
11
+ end
@@ -0,0 +1,58 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
+
3
+ module RR
4
+ module Expectations
5
+ describe TimesCalledExpectation do
6
+ context "when using an IntegerMatcher" do
7
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation"
8
+
9
+ before do
10
+ stub(subject).foobar.times(2)
11
+ end
12
+
13
+ describe "verify" do
14
+ it "passes after attempt! called 2 times" do
15
+ subject.foobar
16
+ subject.foobar
17
+ RR.verify
18
+ end
19
+
20
+ it "fails after attempt! called 1 time" do
21
+ subject.foobar
22
+ lambda {RR.verify}.should raise_error(
23
+ RR::Errors::TimesCalledError,
24
+ "foobar()\nCalled 1 time.\nExpected 2 times."
25
+ )
26
+ end
27
+
28
+ it "can't be called when attempt! is called 3 times" do
29
+ subject.foobar
30
+ subject.foobar
31
+ lambda do
32
+ subject.foobar
33
+ end.should raise_error(RR::Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 2 times.")
34
+ lambda do
35
+ RR.verify
36
+ end.should raise_error(RR::Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 2 times.")
37
+ end
38
+
39
+ it "has a backtrace to where the TimesCalledExpectation was instantiated on failure" do
40
+ error = nil
41
+ begin
42
+ RR.verify
43
+ rescue RR::Errors::TimesCalledError => e
44
+ error = e
45
+ end
46
+ e.backtrace.join("\n").should include(__FILE__)
47
+ end
48
+
49
+ it "has an error message that includes the number of times called and expected number of times" do
50
+ lambda do
51
+ RR.verify
52
+ end.should raise_error(RR::Errors::TimesCalledError, "foobar()\nCalled 0 times.\nExpected 2 times.")
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,35 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
+
3
+ module RR
4
+ module Expectations
5
+ describe TimesCalledExpectation do
6
+ context "when using a ProcMatcher" do
7
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation"
8
+
9
+ before do
10
+ stub(subject).foobar.times(lambda {|value| value == 2})
11
+ end
12
+
13
+ describe "#verify" do
14
+ it "passes after attempt! called 2 times" do
15
+ subject.foobar
16
+ subject.foobar
17
+ RR.verify
18
+ end
19
+
20
+ it "fails after attempt! called 1 time" do
21
+ subject.foobar
22
+ lambda {RR.verify}.should raise_error(RR::Errors::TimesCalledError)
23
+ end
24
+
25
+ it "fails after attempt! called 3 times" do
26
+ subject.foobar
27
+ subject.foobar
28
+ subject.foobar
29
+ lambda {RR.verify}.should raise_error(RR::Errors::TimesCalledError)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
+
3
+ module RR
4
+ module Expectations
5
+ describe TimesCalledExpectation do
6
+ context "when using a RangeMatcher" do
7
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation"
8
+
9
+ before do
10
+ stub(subject).foobar.times(1..2)
11
+ end
12
+
13
+ describe "#verify" do
14
+ it "passes after attempt! called 1 time" do
15
+ subject.foobar
16
+ RR.verify
17
+ end
18
+
19
+ it "passes after attempt! called 2 times" do
20
+ subject.foobar
21
+ subject.foobar
22
+ RR.verify
23
+ end
24
+
25
+ it "can't be called when attempt! is called 3 times" do
26
+ subject.foobar
27
+ subject.foobar
28
+ lambda do
29
+ subject.foobar
30
+ end.should raise_error(RR::Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 1..2 times.")
31
+ lambda do
32
+ RR.verify
33
+ end.should raise_error(RR::Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 1..2 times.")
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,59 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class MiniTestIntegrationTest < MiniTest::Unit::TestCase
4
+ include RR::Adapters::MiniTest # Testing against double inclusion issues
5
+
6
+ def setup
7
+ super
8
+ @subject = Object.new
9
+ end
10
+
11
+ def teardown
12
+ super
13
+ end
14
+
15
+ def test_using_a_mock
16
+ mock(@subject).foobar(1, 2) {:baz}
17
+ assert_equal :baz, @subject.foobar(1, 2)
18
+ end
19
+
20
+ def test_using_a_stub
21
+ stub(@subject).foobar {:baz}
22
+ assert_equal :baz, @subject.foobar("any", "thing")
23
+ end
24
+
25
+ def test_using_a_mock_proxy
26
+ def @subject.foobar
27
+ :baz
28
+ end
29
+
30
+ mock.proxy(@subject).foobar
31
+ assert_equal :baz, @subject.foobar
32
+ end
33
+
34
+ def test_using_a_stub_proxy
35
+ def @subject.foobar
36
+ :baz
37
+ end
38
+
39
+ stub.proxy(@subject).foobar
40
+ assert_equal :baz, @subject.foobar
41
+ end
42
+
43
+ def test_times_called_verification
44
+ mock(@subject).foobar(1, 2) {:baz}
45
+ assert_raises RR::Errors::TimesCalledError do
46
+ teardown
47
+ end
48
+ end
49
+
50
+ def test_using_assert_received
51
+ stub(@subject).foobar(1, 2)
52
+ @subject.foobar(1, 2)
53
+ assert_received(@subject) {|subject| subject.foobar(1, 2)}
54
+
55
+ assert_raises RR::Errors::SpyVerificationErrors::InvocationCountError do
56
+ assert_received(@subject) {|subject| subject.foobar(1, 2, 3)}
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../environment_fixture_setup")
2
+
3
+ require "minitest/autorun"
4
+
5
+ class MiniTest::Unit::TestCase
6
+ include RR::Adapters::MiniTest
7
+ end
@@ -0,0 +1,279 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ module RR
4
+ module Adapters
5
+ module Rspec
6
+ describe InvocationMatcher do
7
+ describe "matching against a method with no doubles" do
8
+ before do
9
+ @matcher = InvocationMatcher.new(:foobar)
10
+ @result = @matcher.matches?(Object.new)
11
+ end
12
+
13
+ it "does not match" do
14
+ @result.should_not be
15
+ end
16
+ end
17
+
18
+ describe "defining an expectation using a method invocation" do
19
+ before do
20
+ @subject = Object.new
21
+ stub(@subject).foobar
22
+ @subject.foobar(:args)
23
+ @result = InvocationMatcher.new.foobar(:args).matches?(@subject)
24
+ end
25
+
26
+ it "uses the invoked method as the expected method" do
27
+ @result.should be
28
+ end
29
+ end
30
+
31
+ describe "matching against a stubbed method that was never called" do
32
+ before do
33
+ @subject = Object.new
34
+ stub(@subject).foobar
35
+ @matcher = InvocationMatcher.new(:foobar)
36
+ @result = @matcher.matches?(@subject)
37
+ end
38
+
39
+ it "does not match" do
40
+ @result.should_not be
41
+ end
42
+ end
43
+
44
+ describe "matching against a stubbed method that was called once" do
45
+ before do
46
+ @subject = Object.new
47
+ stub(@subject).foobar
48
+ @subject.foobar
49
+ @result = InvocationMatcher.new(:foobar).matches?(@subject)
50
+ end
51
+
52
+ it "does match" do
53
+ @result.should be
54
+ end
55
+ end
56
+
57
+ describe "matching against a stubbed method that was called with unexpected arguments" do
58
+ before do
59
+ @args = %w(one two)
60
+ @subject = Object.new
61
+ stub(@subject).foobar
62
+ @subject.foobar(:other)
63
+ @result = InvocationMatcher.new(:foobar).with(*@args).matches?(@subject)
64
+ end
65
+
66
+ it "does not match" do
67
+ @result.should_not be
68
+ end
69
+ end
70
+
71
+ describe "matching against a stubbed method that was called with expected arguments" do
72
+ before do
73
+ @args = %w(one two)
74
+ @subject = Object.new
75
+ stub(@subject).foobar
76
+ @subject.foobar(*@args)
77
+ @result = InvocationMatcher.new(:foobar).with(*@args).matches?(@subject)
78
+ end
79
+
80
+ it "does match" do
81
+ @result.should be
82
+ end
83
+ end
84
+
85
+ describe "defining a fulfilled argument expectation using a method invocation" do
86
+ before do
87
+ @args = %w(one two)
88
+ @subject = Object.new
89
+ stub(@subject).foobar
90
+ @subject.foobar(*@args)
91
+ @result = InvocationMatcher.new.foobar(*@args).matches?(@subject)
92
+ end
93
+
94
+ it "does match" do
95
+ @result.should be
96
+ end
97
+ end
98
+
99
+ describe "defining an unfulfilled argument expectation using a method invocation" do
100
+ before do
101
+ @args = %w(one two)
102
+ @subject = Object.new
103
+ stub(@subject).foobar
104
+ @subject.foobar(:other)
105
+ @result = InvocationMatcher.new.foobar(*@args).matches?(@subject)
106
+ end
107
+
108
+ it "does not match" do
109
+ @result.should_not be
110
+ end
111
+ end
112
+
113
+ describe "matching against a stubbed method that was called more than once" do
114
+ before do
115
+ @subject = Object.new
116
+ stub(@subject).foobar
117
+ 2.times { @subject.foobar }
118
+ @result = InvocationMatcher.new(:foobar).twice.matches?(@subject)
119
+ end
120
+
121
+ it "does match" do
122
+ @result.should be
123
+ end
124
+ end
125
+
126
+ describe "matching a stubbed method with any arguments" do
127
+ before do
128
+ @subject = Object.new
129
+ stub(@subject).foobar
130
+ @subject.foobar(:args)
131
+ @result = InvocationMatcher.new(:foobar).with_any_args.matches?(@subject)
132
+ end
133
+
134
+ it "does match" do
135
+ @result.should be
136
+ end
137
+ end
138
+
139
+ describe "matching a stubbed method with no arguments when arguments are not provided" do
140
+ before do
141
+ @subject = Object.new
142
+ stub(@subject).foobar
143
+ @subject.foobar
144
+ @result = InvocationMatcher.new(:foobar).with_no_args.matches?(@subject)
145
+ end
146
+
147
+ it "does match" do
148
+ @result.should be
149
+ end
150
+ end
151
+
152
+ describe "matching a stubbed method with no arguments when arguments are provided" do
153
+ before do
154
+ @subject = Object.new
155
+ stub(@subject).foobar
156
+ @subject.foobar(:args)
157
+ @result = InvocationMatcher.new(:foobar).with_no_args.matches?(@subject)
158
+ end
159
+
160
+ it "does not match" do
161
+ @result.should_not be
162
+ end
163
+ end
164
+
165
+ describe "matching a method that was called twice when expected once" do
166
+ before do
167
+ @subject = Object.new
168
+ stub(@subject).foobar
169
+ 2.times { @subject.foobar }
170
+ @matcher = InvocationMatcher.new(:foobar).times(1)
171
+ @result = @matcher.matches?(@subject)
172
+ end
173
+
174
+ it "does not match" do
175
+ @result.should_not be
176
+ end
177
+ end
178
+
179
+ describe "matching a method that was called twice when expected twice" do
180
+ before do
181
+ @subject = Object.new
182
+ stub(@subject).foobar
183
+ 2.times { @subject.foobar }
184
+ @result = InvocationMatcher.new(:foobar).times(2).matches?(@subject)
185
+ end
186
+
187
+ it "does match" do
188
+ @result.should be
189
+ end
190
+ end
191
+
192
+ describe "matching a method that was called twice when any number of times" do
193
+ before do
194
+ @subject = Object.new
195
+ stub(@subject).foobar
196
+ 2.times { @subject.foobar }
197
+ @result = InvocationMatcher.new(:foobar).any_number_of_times.matches?(@subject)
198
+ end
199
+
200
+ it "does match" do
201
+ @result.should be
202
+ end
203
+ end
204
+
205
+ describe "matching a method that was called three times when expected at most twice" do
206
+ before do
207
+ @subject = Object.new
208
+ stub(@subject).foobar
209
+ 3.times { @subject.foobar }
210
+ @result = InvocationMatcher.new(:foobar).at_most(2).matches?(@subject)
211
+ end
212
+
213
+ it "does not match" do
214
+ @result.should_not be
215
+ end
216
+ end
217
+
218
+ describe "matching a method that was called once when expected at most twice" do
219
+ before do
220
+ @subject = Object.new
221
+ stub(@subject).foobar
222
+ @subject.foobar
223
+ @result = InvocationMatcher.new(:foobar).at_most(2).matches?(@subject)
224
+ end
225
+
226
+ it "does match" do
227
+ @result.should be
228
+ end
229
+ end
230
+
231
+ describe "matching a method that was called once when expected at least twice" do
232
+ before do
233
+ @subject = Object.new
234
+ stub(@subject).foobar
235
+ @subject.foobar
236
+ @result = InvocationMatcher.new(:foobar).at_least(2).matches?(@subject)
237
+ end
238
+
239
+ it "does not match" do
240
+ @result.should_not be
241
+ end
242
+ end
243
+
244
+ describe "matching a method that was called three times when expected at least twice" do
245
+ before do
246
+ @subject = Object.new
247
+ stub(@subject).foobar
248
+ 3.times { @subject.foobar }
249
+ @result = InvocationMatcher.new(:foobar).at_least(2).matches?(@subject)
250
+ end
251
+
252
+ it "does match" do
253
+ @result.should be
254
+ end
255
+ end
256
+
257
+ describe "that does not match" do
258
+ before do
259
+ @error = Object.new
260
+ @message = 'Verification error message'
261
+ stub(RR::Space.instance.recorded_calls).match_error { @error }
262
+ stub(@error).message { @message }
263
+
264
+ @matcher = InvocationMatcher.new(:foobar)
265
+ @result = @matcher.matches?(Object.new)
266
+ end
267
+
268
+ it "returns false when matching" do
269
+ @result.should_not be
270
+ end
271
+
272
+ it "returns a failure messsage" do
273
+ @matcher.failure_message.should == @message
274
+ end
275
+ end
276
+ end
277
+ end
278
+ end
279
+ end