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 File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ describe "spy" do
4
+ attr_reader :subject
5
+ before(:each) do
6
+ @subject = Object.new
7
+ extend RR::Adapters::RRMethods
8
+ end
9
+
10
+ after(:each) do
11
+ RR.reset
12
+ end
13
+
14
+ it "should record all method invocations" do
15
+ subject = Object.new
16
+
17
+ def subject.something
18
+ end
19
+
20
+ def subject.something_else
21
+ end
22
+
23
+ spy(subject)
24
+
25
+ subject.something
26
+ subject.something_else
27
+ subject.to_s
28
+
29
+ received(subject).something.call
30
+ received(subject).something_else.call
31
+ received(subject).to_s.call
32
+ end
33
+
34
+ describe "RR recorded_calls" do
35
+ it "should verify method calls after the fact" do
36
+ stub(subject).pig_rabbit
37
+ subject.pig_rabbit("bacon", "bunny meat")
38
+ #subject.should have_received.pig_rabitt("bacon", "bunny meat")
39
+ received(subject).pig_rabbit("bacon", "bunny meat").call
40
+ end
41
+
42
+ it "should verify method calls after the fact" do
43
+ stub(subject).pig_rabbit
44
+ lambda do
45
+ received(subject).pig_rabbit("bacon", "bunny meat").call
46
+ end.should raise_error(RR::Errors::SpyVerificationErrors::SpyVerificationError)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,87 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ class StrongSpecFixture
4
+ def method_with_no_arguments
5
+ end
6
+
7
+ def method_with_one_argument(string)
8
+ end
9
+
10
+ def method_with_two_arguments(string, integer)
11
+ end
12
+
13
+ def method_with_three_arguments_including_varargs(string, integer, *args)
14
+ end
15
+
16
+ def method_with_varargs(*args)
17
+ end
18
+ end
19
+
20
+ describe "strong" do
21
+ attr_reader :subject
22
+ before(:each) do
23
+ @subject = Object.new
24
+ extend RR::Adapters::RRMethods
25
+ end
26
+
27
+ after(:each) do
28
+ RR.reset
29
+ end
30
+
31
+ context "when the method does not exist" do
32
+ it "raises an exception" do
33
+ lambda do
34
+ strong.stub(StrongSpecFixture.new).something
35
+ end.should raise_error(RR::Errors::SubjectDoesNotImplementMethodError)
36
+ end
37
+ end
38
+
39
+ context "when the method exists with no arguments" do
40
+ it "does not raise an exception" do
41
+ strong.stub(StrongSpecFixture.new).method_with_no_arguments
42
+ end
43
+ end
44
+
45
+ context "when the method has a different arity" do
46
+ it "raises an exception" do
47
+ lambda do
48
+ strong.stub(StrongSpecFixture.new).method_with_one_argument
49
+ end.should raise_error(RR::Errors::SubjectHasDifferentArityError)
50
+ end
51
+ end
52
+
53
+ context "when the method has accepts a variable number of arguments" do
54
+ it "does not raise an exception" do
55
+ strong.stub(StrongSpecFixture.new).method_with_varargs
56
+ end
57
+ end
58
+
59
+ context "when the method does not provide the required parameters before varargs" do
60
+ it "raises an exception" do
61
+ lambda do
62
+ strong.stub(StrongSpecFixture.new).method_with_three_arguments_including_varargs
63
+ end.should raise_error(RR::Errors::SubjectHasDifferentArityError)
64
+ end
65
+ end
66
+
67
+ context "when the minimum number of parameters are provided" do
68
+ it "does not raise an exception" do
69
+ strong.stub(StrongSpecFixture.new).method_with_three_arguments_including_varargs("one", 2)
70
+ end
71
+ end
72
+
73
+ context "when using instance_of and the method does not exist" do
74
+ it "raises an exception" do
75
+ lambda do
76
+ strong.stub.instance_of(StrongSpecFixture).something
77
+ StrongSpecFixture.new
78
+ end.should raise_error(RR::Errors::SubjectDoesNotImplementMethodError)
79
+ end
80
+ end
81
+
82
+ context "when using instance_of and the method does exist" do
83
+ it "does not raise an exception" do
84
+ strong.stub.instance_of(StrongSpecFixture).method_with_no_arguments
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,152 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ class StubSpecFixture
4
+ attr_reader :initialize_arguments
5
+
6
+ def initialize(*args)
7
+ @initialize_arguments = args
8
+ yield if block_given?
9
+ method_run_in_initialize
10
+ end
11
+
12
+ def method_run_in_initialize
13
+
14
+ end
15
+ end
16
+
17
+ describe "stub" do
18
+ attr_reader :subject
19
+ before(:each) do
20
+ @subject = Object.new
21
+ extend RR::Adapters::RRMethods
22
+ end
23
+
24
+ after(:each) do
25
+ RR.reset
26
+ end
27
+
28
+ it "stubs via inline call" do
29
+ stub(subject).to_s {"a value"}
30
+ subject.to_s.should == "a value"
31
+ end
32
+
33
+ describe ".once.ordered" do
34
+ it "returns the values in the ordered called" do
35
+ stub(subject).to_s {"value 1"}.once.ordered
36
+ stub(subject).to_s {"value 2"}.once.ordered
37
+
38
+ subject.to_s.should == "value 1"
39
+ subject.to_s.should == "value 2"
40
+ end
41
+ end
42
+
43
+ context "when the subject is a proxy for the object with the defined method" do
44
+ it "stubs the method on the proxy object" do
45
+ proxy_target = Class.new {def foobar; :original_foobar; end}.new
46
+ proxy = Class.new do
47
+ def initialize(target)
48
+ @target = target
49
+ end
50
+
51
+ instance_methods.each do |m|
52
+ unless m =~ /^_/ || m.to_s == 'object_id' || m.to_s == 'method_missing'
53
+ alias_method "__blank_slated_#{m}", m
54
+ undef_method m
55
+ end
56
+ end
57
+
58
+ def method_missing(method_name, *args, &block)
59
+ @target.send(method_name, *args, &block)
60
+ end
61
+ end.new(proxy_target)
62
+ proxy.methods.should =~ proxy_target.methods
63
+
64
+ stub(proxy).foobar {:new_foobar}
65
+ proxy.foobar.should == :new_foobar
66
+ end
67
+ end
68
+
69
+ it "stubs via block with argument" do
70
+ stub subject do |d|
71
+ d.to_s {"a value"}
72
+ d.to_sym {:crazy}
73
+ end
74
+ subject.to_s.should == "a value"
75
+ subject.to_sym.should == :crazy
76
+ end
77
+
78
+ it "stubs via block without argument" do
79
+ stub subject do
80
+ to_s {"a value"}
81
+ to_sym {:crazy}
82
+ end
83
+ subject.to_s.should == "a value"
84
+ subject.to_sym.should == :crazy
85
+ end
86
+
87
+ it "stubs instance_of" do
88
+ stub.instance_of(StubSpecFixture) do |o|
89
+ o.to_s {"High Level Spec"}
90
+ end
91
+ StubSpecFixture.new.to_s.should == "High Level Spec"
92
+ end
93
+
94
+ it "stubs methods without letters" do
95
+ stub(subject).__send__(:==) {:equality}
96
+ (subject == 55).should == :equality
97
+ end
98
+
99
+ it "stubs methods invoked in #initialize while passing along the #initialize arg" do
100
+ method_run_in_initialize_stubbed = false
101
+ stub.instance_of(StubSpecFixture) do |o|
102
+ o.method_run_in_initialize {method_run_in_initialize_stubbed = true}
103
+ end
104
+ StubSpecFixture.new
105
+ method_run_in_initialize_stubbed.should be_true
106
+ end
107
+
108
+ it "passed the arguments and block passed to #initialize" do
109
+ block_called = false
110
+ stub.instance_of(StubSpecFixture) do |o|
111
+ o.method_run_in_initialize
112
+ end
113
+ instance = StubSpecFixture.new(1, 2) {block_called = true}
114
+ instance.initialize_arguments.should == [1, 2]
115
+ block_called.should be_true
116
+ end
117
+
118
+ context "mock then stub" do
119
+ it "stubs any calls not matching the mock" do
120
+ mock(subject).foobar(3) {:baz3}
121
+ stub(subject).foobar {:baz}
122
+ subject.foobar(3).should == :baz3
123
+ subject.foobar(4).should == :baz
124
+ end
125
+ end
126
+
127
+ context "stub that yields" do
128
+ context "when yields called without any arguments" do
129
+ it "yields only once" do
130
+ called_from_block = mock!.foo.once.subject
131
+ block_caller = stub!.bar.yields.subject
132
+ block_caller.bar { called_from_block.foo }
133
+ end
134
+ end
135
+
136
+ context "when yields called with an argument" do
137
+ it "yields only once" do
138
+ called_from_block = mock!.foo(1).once.subject
139
+ block_caller = stub!.bar.yields(1).subject
140
+ block_caller.bar { |argument| called_from_block.foo(argument) }
141
+ end
142
+ end
143
+
144
+ context "when yields calls are chained" do
145
+ it "yields several times" do
146
+ called_from_block = mock!.foo(1).once.then.foo(2).once.subject
147
+ block_caller = stub!.bar.yields(1).yields(2).subject
148
+ block_caller.bar { |argument| called_from_block.foo(argument) }
149
+ end
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,18 @@
1
+ require "#{File.dirname(__FILE__)}/spec_helper"
2
+
3
+ class CoreExampleSuite
4
+ def run
5
+ files = Dir["#{File.dirname(__FILE__)}/**/*_spec.rb"]
6
+ files.delete_if {|file| file.include?('rspec/')}
7
+ files.delete_if {|file| file.include?('test_unit/')}
8
+ puts "Running Rspec Example Suite"
9
+ files.each do |file|
10
+ require File.expand_path(file)
11
+ # puts "require '#{file}'"
12
+ end
13
+ end
14
+ end
15
+
16
+ if $0 == __FILE__
17
+ CoreExampleSuite.new.run
18
+ end
@@ -0,0 +1,7 @@
1
+ require "rubygems"
2
+ require "rspec"
3
+ require "bundler"
4
+
5
+ $LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/../lib")
6
+ require "rr"
7
+ require "pp"
@@ -0,0 +1,21 @@
1
+ require "rubygems"
2
+ require "spec"
3
+
4
+ class MiniTestTestSuite
5
+ def run
6
+ require_tests
7
+
8
+ puts "Running MiniTest Test Suite"
9
+ end
10
+
11
+ def require_tests
12
+ dir = File.dirname(__FILE__)
13
+ Dir["#{dir}/rr/minitest/**/*_test.rb"].each do |file|
14
+ require File.expand_path(file)
15
+ end
16
+ end
17
+ end
18
+
19
+ if $0 == __FILE__
20
+ MiniTestTestSuite.new.run
21
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
2
+
3
+ module RR
4
+ describe ProcFromBlock do
5
+ describe "#==" do
6
+ it "acts the same as #== on a Proc" do
7
+ original_proc = lambda {}
8
+ Proc.new(&original_proc).should == original_proc
9
+
10
+ ProcFromBlock.new(&original_proc).should == original_proc
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,67 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ module RR
4
+ module Adapters
5
+ describe RRMethods do
6
+ describe "#anything" do
7
+ it_should_behave_like "RR::Adapters::RRMethods"
8
+
9
+ it "returns an Anything matcher" do
10
+ anything.should == RR::WildcardMatchers::Anything.new
11
+ end
12
+
13
+ it "rr_anything returns an Anything matcher" do
14
+ rr_anything.should == RR::WildcardMatchers::Anything.new
15
+ end
16
+ end
17
+
18
+ describe "#is_a" do
19
+ it_should_behave_like "RR::Adapters::RRMethods"
20
+
21
+ it "returns an IsA matcher" do
22
+ is_a(Integer).should == RR::WildcardMatchers::IsA.new(Integer)
23
+ end
24
+
25
+ it "rr_is_a returns an IsA matcher" do
26
+ rr_is_a(Integer).should == RR::WildcardMatchers::IsA.new(Integer)
27
+ end
28
+ end
29
+
30
+ describe "#numeric" do
31
+ it_should_behave_like "RR::Adapters::RRMethods"
32
+
33
+ it "returns an Numeric matcher" do
34
+ numeric.should == RR::WildcardMatchers::Numeric.new
35
+ end
36
+
37
+ it "rr_numeric returns an Numeric matcher" do
38
+ rr_numeric.should == RR::WildcardMatchers::Numeric.new
39
+ end
40
+ end
41
+
42
+ describe "#boolean" do
43
+ it_should_behave_like "RR::Adapters::RRMethods"
44
+
45
+ it "returns an Boolean matcher" do
46
+ boolean.should == RR::WildcardMatchers::Boolean.new
47
+ end
48
+
49
+ it "rr_boolean returns an Boolean matcher" do
50
+ rr_boolean.should == RR::WildcardMatchers::Boolean.new
51
+ end
52
+ end
53
+
54
+ describe "#duck_type" do
55
+ it_should_behave_like "RR::Adapters::RRMethods"
56
+
57
+ it "returns a DuckType matcher" do
58
+ duck_type(:one, :two).should == RR::WildcardMatchers::DuckType.new(:one, :two)
59
+ end
60
+
61
+ it "rr_duck_type returns a DuckType matcher" do
62
+ rr_duck_type(:one, :two).should == RR::WildcardMatchers::DuckType.new(:one, :two)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,137 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ module RR
4
+ module Adapters
5
+ describe RRMethods do
6
+ attr_reader :subject
7
+ before(:each) do
8
+ @subject = Object.new
9
+ end
10
+
11
+ after(:each) do
12
+ RR.reset
13
+ end
14
+
15
+ describe "normal strategy definitions" do
16
+ attr_reader :strategy_method_name
17
+ def call_strategy(*args, &block)
18
+ __send__(strategy_method_name, *args, &block)
19
+ end
20
+
21
+ describe "#mock" do
22
+ before do
23
+ @strategy_method_name = :mock
24
+ end
25
+
26
+ context "when passing no args" do
27
+ it "returns a DoubleDefinitionCreate" do
28
+ call_strategy.class.should == RR::DoubleDefinitions::DoubleDefinitionCreate
29
+ end
30
+ end
31
+
32
+ context "when passed a method_name argument" do
33
+ it "creates a mock Double for method" do
34
+ double_definition = mock(subject, :foobar).returns {:baz}
35
+ double_definition.times_matcher.should == RR::TimesCalledMatchers::IntegerMatcher.new(1)
36
+ double_definition.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
37
+ double_definition.argument_expectation.expected_arguments.should == []
38
+ subject.foobar.should == :baz
39
+ end
40
+ end
41
+ end
42
+
43
+ describe "#stub" do
44
+ before do
45
+ @strategy_method_name = :stub
46
+ end
47
+
48
+ context "when passing no args" do
49
+ it "returns a DoubleDefinitionCreate" do
50
+ call_strategy.class.should == RR::DoubleDefinitions::DoubleDefinitionCreate
51
+ end
52
+ end
53
+
54
+ context "when passed a method_name argument" do
55
+ it "creates a stub Double for method when passed a method_name argument" do
56
+ double_definition = stub(subject, :foobar).returns {:baz}
57
+ double_definition.times_matcher.should == RR::TimesCalledMatchers::AnyTimesMatcher.new
58
+ double_definition.argument_expectation.class.should == RR::Expectations::AnyArgumentExpectation
59
+ subject.foobar.should == :baz
60
+ end
61
+ end
62
+ end
63
+
64
+ describe "#dont_allow" do
65
+ before do
66
+ @strategy_method_name = :dont_allow
67
+ end
68
+
69
+ context "when passing no args" do
70
+ it "returns a DoubleDefinitionCreate" do
71
+ call_strategy.class.should == RR::DoubleDefinitions::DoubleDefinitionCreate
72
+ end
73
+ end
74
+
75
+ context "when passed a method_name argument_expectation" do
76
+ it "creates a mock Double for method" do
77
+ double_definition = dont_allow(subject, :foobar)
78
+ double_definition.times_matcher.should == RR::TimesCalledMatchers::NeverMatcher.new
79
+ double_definition.argument_expectation.class.should == RR::Expectations::AnyArgumentExpectation
80
+
81
+ lambda do
82
+ subject.foobar
83
+ end.should raise_error(RR::Errors::TimesCalledError)
84
+ RR.reset
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ describe "! strategy definitions" do
91
+ attr_reader :strategy_method_name
92
+ def call_strategy(*args, &definition_eval_block)
93
+ __send__(strategy_method_name, *args, &definition_eval_block)
94
+ end
95
+
96
+ describe "#mock!" do
97
+ before do
98
+ @strategy_method_name = :mock!
99
+ end
100
+
101
+ context "when passed a method_name argument" do
102
+ it "sets #verification_strategy to Mock" do
103
+ proxy = mock!(:foobar)
104
+ proxy.double_definition_create.verification_strategy.class.should == RR::DoubleDefinitions::Strategies::Verification::Mock
105
+ end
106
+ end
107
+ end
108
+
109
+ describe "#stub!" do
110
+ before do
111
+ @strategy_method_name = :stub!
112
+ end
113
+
114
+ context "when passed a method_name argument" do
115
+ it "sets #verification_strategy to Stub" do
116
+ proxy = stub!(:foobar)
117
+ proxy.double_definition_create.verification_strategy.class.should == RR::DoubleDefinitions::Strategies::Verification::Stub
118
+ end
119
+ end
120
+ end
121
+
122
+ describe "#dont_allow!" do
123
+ before do
124
+ @strategy_method_name = :dont_allow!
125
+ end
126
+
127
+ context "when passed a method_name argument" do
128
+ it "sets #verification_strategy to DontAllow" do
129
+ proxy = dont_allow!(:foobar)
130
+ proxy.double_definition_create.verification_strategy.class.should == RR::DoubleDefinitions::Strategies::Verification::DontAllow
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end