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,49 @@
1
+ require "rake"
2
+ require 'rake/contrib/rubyforgepublisher'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/rdoctask'
6
+
7
+ desc "Runs the Rspec suite"
8
+ task(:default) do
9
+ run_suite
10
+ end
11
+
12
+ desc "Runs the Rspec suite"
13
+ task(:spec) do
14
+ run_suite
15
+ end
16
+
17
+ def run_suite
18
+ dir = File.dirname(__FILE__)
19
+ system("ruby #{dir}/spec/spec_suite.rb") || raise("Spec Suite failed")
20
+ end
21
+
22
+ begin
23
+ require 'jeweler'
24
+ Jeweler::Tasks.new do |s|
25
+ s.name = "mcmire-rr"
26
+ s.summary = "RR (Double Ruby) is a double framework that features a rich " <<
27
+ "selection of double techniques and a terse syntax. " <<
28
+ "http://xunitpatterns.com/Test%20Double.html"
29
+ s.email = "brian@pivotallabs.com"
30
+ s.homepage = "http://pivotallabs.com"
31
+ s.description = "RR (Double Ruby) is a double framework that features a rich " <<
32
+ "selection of double techniques and a terse syntax. " <<
33
+ "http://xunitpatterns.com/Test%20Double.html"
34
+ s.authors = ["Brian Takita"]
35
+ s.files = FileList[
36
+ '[A-Z]*',
37
+ '*.rb',
38
+ 'lib/**/*.rb',
39
+ 'spec/**/*.rb'
40
+ ].to_a
41
+ s.test_files = Dir.glob('spec/*_spec.rb')
42
+ s.has_rdoc = true
43
+ s.extra_rdoc_files = [ "README.rdoc", "CHANGES" ]
44
+ s.rdoc_options = ["--main", "README.rdoc", "--inline-source", "--line-numbers"]
45
+ end
46
+ rescue LoadError
47
+ puts "Jeweler not available. Install it with: gem install jeweler"
48
+ end
49
+ Jeweler::RubygemsDotOrgTasks.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.5.rc1
@@ -0,0 +1,101 @@
1
+ dir = File.dirname(__FILE__)
2
+ require 'forwardable'
3
+
4
+ require "#{dir}/rr/class_instance_method_defined"
5
+ require "#{dir}/rr/blank_slate"
6
+
7
+ require "#{dir}/rr/errors/rr_error"
8
+ require "#{dir}/rr/errors/subject_does_not_implement_method_error"
9
+ require "#{dir}/rr/errors/subject_has_different_arity_error"
10
+ require "#{dir}/rr/errors/double_definition_error"
11
+ require "#{dir}/rr/errors/double_not_found_error"
12
+ require "#{dir}/rr/errors/double_order_error"
13
+ require "#{dir}/rr/errors/argument_equality_error"
14
+ require "#{dir}/rr/errors/times_called_error"
15
+ require "#{dir}/rr/errors/spy_verification_errors/spy_verification_error"
16
+ require "#{dir}/rr/errors/spy_verification_errors/double_injection_not_found_error"
17
+ require "#{dir}/rr/errors/spy_verification_errors/invocation_count_error"
18
+
19
+ require "#{dir}/rr/space"
20
+
21
+ require "#{dir}/rr/double_definitions/strategies/strategy"
22
+ require "#{dir}/rr/double_definitions/strategies/strategy_methods"
23
+ require "#{dir}/rr/double_definitions/strategies/verification/verification_strategy"
24
+ require "#{dir}/rr/double_definitions/strategies/verification/mock"
25
+ require "#{dir}/rr/double_definitions/strategies/verification/stub"
26
+ require "#{dir}/rr/double_definitions/strategies/verification/dont_allow"
27
+ require "#{dir}/rr/double_definitions/strategies/implementation/implementation_strategy"
28
+ require "#{dir}/rr/double_definitions/strategies/implementation/reimplementation"
29
+ require "#{dir}/rr/double_definitions/strategies/implementation/strongly_typed_reimplementation"
30
+ require "#{dir}/rr/double_definitions/strategies/implementation/proxy"
31
+ require "#{dir}/rr/double_definitions/strategies/double_injection/double_injection_strategy"
32
+ require "#{dir}/rr/double_definitions/strategies/double_injection/instance"
33
+ require "#{dir}/rr/double_definitions/strategies/double_injection/any_instance_of"
34
+ require "#{dir}/rr/adapters/rr_methods"
35
+ require "#{dir}/rr/double_definitions/double_injections/instance"
36
+ require "#{dir}/rr/double_definitions/double_injections/any_instance_of"
37
+ require "#{dir}/rr/double_definitions/double_definition"
38
+
39
+ require "#{dir}/rr/injections/injection"
40
+ require "#{dir}/rr/injections/double_injection"
41
+ require "#{dir}/rr/injections/method_missing_injection"
42
+ require "#{dir}/rr/injections/singleton_method_added_injection"
43
+ require "#{dir}/rr/method_dispatches/base_method_dispatch"
44
+ require "#{dir}/rr/method_dispatches/method_dispatch"
45
+ require "#{dir}/rr/method_dispatches/method_missing_dispatch"
46
+ require "#{dir}/rr/hash_with_object_id_key"
47
+ require "#{dir}/rr/recorded_calls"
48
+ require "#{dir}/rr/proc_from_block"
49
+
50
+ require "#{dir}/rr/double_definitions/double_definition_create_blank_slate"
51
+ require "#{dir}/rr/double_definitions/double_definition_create"
52
+ require "#{dir}/rr/double_definitions/child_double_definition_create"
53
+
54
+ require "#{dir}/rr/double"
55
+ require "#{dir}/rr/double_matches"
56
+
57
+ require "#{dir}/rr/expectations/argument_equality_expectation"
58
+ require "#{dir}/rr/expectations/any_argument_expectation"
59
+ require "#{dir}/rr/expectations/times_called_expectation"
60
+
61
+ require "#{dir}/rr/wildcard_matchers/anything"
62
+ require "#{dir}/rr/wildcard_matchers/is_a"
63
+ require "#{dir}/rr/wildcard_matchers/numeric"
64
+ require "#{dir}/rr/wildcard_matchers/boolean"
65
+ require "#{dir}/rr/wildcard_matchers/duck_type"
66
+ require "#{dir}/rr/wildcard_matchers/regexp"
67
+ require "#{dir}/rr/wildcard_matchers/range"
68
+ require "#{dir}/rr/wildcard_matchers/satisfy"
69
+ require "#{dir}/rr/wildcard_matchers/hash_including"
70
+
71
+ require "#{dir}/rr/times_called_matchers/terminal"
72
+ require "#{dir}/rr/times_called_matchers/non_terminal"
73
+ require "#{dir}/rr/times_called_matchers/times_called_matcher"
74
+ require "#{dir}/rr/times_called_matchers/never_matcher"
75
+ require "#{dir}/rr/times_called_matchers/any_times_matcher"
76
+ require "#{dir}/rr/times_called_matchers/integer_matcher"
77
+ require "#{dir}/rr/times_called_matchers/range_matcher"
78
+ require "#{dir}/rr/times_called_matchers/proc_matcher"
79
+ require "#{dir}/rr/times_called_matchers/at_least_matcher"
80
+ require "#{dir}/rr/times_called_matchers/at_most_matcher"
81
+
82
+ require "#{dir}/rr/spy_verification_proxy"
83
+ require "#{dir}/rr/spy_verification"
84
+
85
+ require "#{dir}/rr/adapters/rspec"
86
+ require "#{dir}/rr/adapters/rspec2"
87
+ require "#{dir}/rr/adapters/test_unit"
88
+ require "#{dir}/rr/adapters/minitest"
89
+
90
+ module RR
91
+ class << self
92
+ include Adapters::RRMethods
93
+ (RR::Space.instance_methods - Object.instance_methods).each do |method_name|
94
+ class_eval((<<-METHOD), __FILE__, __LINE__ + 1)
95
+ def #{method_name}(*args, &block)
96
+ RR::Space.instance.__send__(:#{method_name}, *args, &block)
97
+ end
98
+ METHOD
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,31 @@
1
+ module RR
2
+ module Adapters
3
+ module MiniTest
4
+ include RRMethods
5
+ def self.included(mod)
6
+ RR.trim_backtrace = true
7
+ mod.class_eval do
8
+ unless instance_methods.any? { |method_name| method_name.to_sym == :setup_with_rr }
9
+ alias_method :setup_without_rr, :setup
10
+ def setup_with_rr
11
+ setup_without_rr
12
+ RR.reset
13
+ end
14
+ alias_method :setup, :setup_with_rr
15
+
16
+ alias_method :teardown_without_rr, :teardown
17
+ def teardown_with_rr
18
+ RR.verify
19
+ teardown_without_rr
20
+ end
21
+ alias_method :teardown, :teardown_with_rr
22
+ end
23
+ end
24
+ end
25
+
26
+ def assert_received(subject, &block)
27
+ block.call(received(subject)).call
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,146 @@
1
+ module RR
2
+ module Adapters
3
+ module RRMethods
4
+ include ::RR::DoubleDefinitions::Strategies::StrategyMethods
5
+ def mock(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
6
+ double_definition_create = DoubleDefinitions::DoubleDefinitionCreate.new
7
+ double_definition_create.mock(subject, method_name, &definition_eval_block)
8
+ end
9
+
10
+ def stub(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
11
+ double_definition_create = DoubleDefinitions::DoubleDefinitionCreate.new
12
+ double_definition_create.stub(subject, method_name, &definition_eval_block)
13
+ end
14
+
15
+ def dont_allow(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
16
+ double_definition_create = DoubleDefinitions::DoubleDefinitionCreate.new
17
+ double_definition_create.dont_allow(subject, method_name, &definition_eval_block)
18
+ end
19
+
20
+ def proxy(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
21
+ double_definition_create = DoubleDefinitions::DoubleDefinitionCreate.new
22
+ double_definition_create.proxy(subject, method_name, &definition_eval_block)
23
+ end
24
+
25
+ def strong(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
26
+ double_definition_create = DoubleDefinitions::DoubleDefinitionCreate.new
27
+ double_definition_create.strong(subject, method_name, &definition_eval_block)
28
+ end
29
+
30
+ def instance_of(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
31
+ double_definition_create = DoubleDefinitions::DoubleDefinitionCreate.new
32
+ double_definition_create.instance_of(subject, method_name, &definition_eval_block)
33
+ end
34
+ alias_method :any_instance_of, :instance_of
35
+ alias_method :all_instances_of, :instance_of
36
+
37
+ # Verifies all the DoubleInjection objects have met their
38
+ # TimesCalledExpectations.
39
+ def verify
40
+ RR::Space.instance.verify_doubles
41
+ end
42
+
43
+ # Resets the registered Doubles and ordered Doubles
44
+ def reset
45
+ RR::Space.instance.reset
46
+ end
47
+
48
+ # Returns a AnyTimesMatcher. This is meant to be passed in as an argument
49
+ # to Double#times.
50
+ #
51
+ # mock(object).method_name(anything).times(any_times) {return_value}
52
+ def any_times
53
+ TimesCalledMatchers::AnyTimesMatcher.new
54
+ end
55
+
56
+ # Sets up an Anything wildcard ArgumentEqualityExpectation
57
+ # that succeeds when passed any argument.
58
+ # mock(object).method_name(anything) {return_value}
59
+ # object.method_name("an arbitrary value") # passes
60
+ def anything
61
+ RR::WildcardMatchers::Anything.new
62
+ end
63
+
64
+ # Sets up an IsA wildcard ArgumentEqualityExpectation
65
+ # that succeeds when passed an argument of a certain type.
66
+ # mock(object).method_name(is_a(String)) {return_value}
67
+ # object.method_name("A String") # passes
68
+ def is_a(klass)
69
+ RR::WildcardMatchers::IsA.new(klass)
70
+ end
71
+
72
+ # Sets up an Numeric wildcard ArgumentEqualityExpectation
73
+ # that succeeds when passed an argument that is ::Numeric.
74
+ # mock(object).method_name(numeric) {return_value}
75
+ # object.method_name(99) # passes
76
+ def numeric
77
+ RR::WildcardMatchers::Numeric.new
78
+ end
79
+
80
+ # Sets up an Boolean wildcard ArgumentEqualityExpectation
81
+ # that succeeds when passed an argument that is a ::Boolean.
82
+ # mock(object).method_name(boolean) {return_value}
83
+ # object.method_name(false) # passes
84
+ def boolean
85
+ RR::WildcardMatchers::Boolean.new
86
+ end
87
+
88
+ # Sets up a DuckType wildcard ArgumentEqualityExpectation
89
+ # that succeeds when the passed argument implements the methods.
90
+ # arg = Object.new
91
+ # def arg.foo; end
92
+ # def arg.bar; end
93
+ # mock(object).method_name(duck_type(:foo, :bar)) {return_value}
94
+ # object.method_name(arg) # passes
95
+ def duck_type(*args)
96
+ RR::WildcardMatchers::DuckType.new(*args)
97
+ end
98
+
99
+ # Sets up a HashIncluding wildcard ArgumentEqualityExpectation
100
+ # that succeeds when the passed argument contains at least those keys
101
+ # and values of the expectation.
102
+ # mock(object).method_name(hash_including(:foo => 1)) {return_value}
103
+ # object.method_name({:foo => 1, :bar => 2) # passes
104
+ def hash_including(expected_hash)
105
+ RR::WildcardMatchers::HashIncluding.new(expected_hash)
106
+ end
107
+
108
+ # Sets up a Satisfy wildcard ArgumentEqualityExpectation
109
+ # that succeeds when the passed argument causes the expectation's
110
+ # proc to return true.
111
+ # mock(object).method_name(satisfy {|arg| arg == :foo}) {return_value}
112
+ # object.method_name(:foo) # passes
113
+ def satisfy(expectation_proc=nil, &block)
114
+ expectation_proc ||= block
115
+ RR::WildcardMatchers::Satisfy.new(expectation_proc)
116
+ end
117
+
118
+ def spy(subject)
119
+ methods_to_stub = subject.public_methods.map {|method_name| method_name.to_sym} -
120
+ [:methods, :==, :__send__, :__id__, :object_id, :class]
121
+ methods_to_stub.each do |method|
122
+ stub.proxy(subject, method)
123
+ end
124
+ end
125
+
126
+ def received(subject)
127
+ RR::SpyVerificationProxy.new(subject)
128
+ end
129
+
130
+ def new_instance_of(*args, &block)
131
+ RR::DoubleDefinitions::DoubleInjections::NewInstanceOf.call(*args, &block)
132
+ end
133
+
134
+ def any_instance_of(*args, &block)
135
+ RR::DoubleDefinitions::DoubleInjections::AnyInstanceOf.call(*args, &block)
136
+ end
137
+
138
+ instance_methods.each do |name|
139
+ alias_method "rr_#{name}", name
140
+ end
141
+ end
142
+ end
143
+ module Extensions
144
+ InstanceMethods = Adapters::RRMethods
145
+ end
146
+ end
@@ -0,0 +1,61 @@
1
+ module RR
2
+ module Adapters
3
+ module Rspec
4
+ def self.included(mod)
5
+ patterns = ::Spec::Runner::QuietBacktraceTweaker::IGNORE_PATTERNS
6
+ unless patterns.include?(RR::Errors::BACKTRACE_IDENTIFIER)
7
+ patterns.push(RR::Errors::BACKTRACE_IDENTIFIER)
8
+ end
9
+ end
10
+
11
+ include RRMethods
12
+ def setup_mocks_for_rspec
13
+ RR.reset
14
+ end
15
+ def verify_mocks_for_rspec
16
+ RR.verify
17
+ end
18
+ def teardown_mocks_for_rspec
19
+ RR.reset
20
+ end
21
+
22
+ def have_received(method = nil)
23
+ InvocationMatcher.new(method)
24
+ end
25
+
26
+ class InvocationMatcher < SpyVerificationProxy
27
+ attr_reader :failure_message, :spy_verification_proxy
28
+
29
+ def initialize(method = nil)
30
+ @verification = nil
31
+ @subject = nil
32
+ method_missing(method) if method
33
+ end
34
+
35
+ def matches?(subject)
36
+ @verification.subject = subject
37
+ calls = RR::Space.instance.recorded_calls
38
+ if error = calls.match_error(@verification)
39
+ @failure_message = error.message
40
+ false
41
+ else
42
+ true
43
+ end
44
+ end
45
+
46
+ def nil?
47
+ false
48
+ end
49
+
50
+ def method_missing(method_name, *args, &block)
51
+ if @verification
52
+ @verification.send(method_name, *args)
53
+ else
54
+ @verification = super
55
+ end
56
+ self
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,22 @@
1
+ module RR
2
+ module Adapters
3
+ module RSpec2
4
+
5
+ include RRMethods
6
+
7
+ def setup_mocks_for_rspec
8
+ RR.reset
9
+ end
10
+ def verify_mocks_for_rspec
11
+ RR.verify
12
+ end
13
+ def teardown_mocks_for_rspec
14
+ RR.reset
15
+ end
16
+
17
+ def have_received(method = nil)
18
+ RR::Adapters::Rspec::InvocationMatcher.new(method)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,31 @@
1
+ module RR
2
+ module Adapters
3
+ module TestUnit
4
+ include RRMethods
5
+ def self.included(mod)
6
+ RR.trim_backtrace = true
7
+ mod.class_eval do
8
+ unless instance_methods.detect {|method_name| method_name.to_sym == :setup_with_rr}
9
+ alias_method :setup_without_rr, :setup
10
+ def setup_with_rr
11
+ setup_without_rr
12
+ RR.reset
13
+ end
14
+ alias_method :setup, :setup_with_rr
15
+
16
+ alias_method :teardown_without_rr, :teardown
17
+ def teardown_with_rr
18
+ RR.verify
19
+ teardown_without_rr
20
+ end
21
+ alias_method :teardown, :teardown_with_rr
22
+ end
23
+ end
24
+ end
25
+
26
+ def assert_received(subject, &block)
27
+ block.call(received(subject)).call
28
+ end
29
+ end
30
+ end
31
+ end