rr 0.3.11 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. data/CHANGES +8 -3
  2. data/README +130 -39
  3. data/Rakefile +6 -5
  4. data/lib/rr.rb +8 -8
  5. data/lib/rr/adapters/rr_methods.rb +228 -0
  6. data/lib/rr/adapters/rspec.rb +1 -1
  7. data/lib/rr/adapters/test_unit.rb +1 -1
  8. data/lib/rr/double.rb +294 -89
  9. data/lib/rr/{scenario_creator.rb → double_creator.rb} +65 -66
  10. data/lib/rr/{scenario_definition.rb → double_definition.rb} +36 -36
  11. data/lib/rr/{scenario_definition_builder.rb → double_definition_builder.rb} +3 -3
  12. data/lib/rr/double_insertion.rb +132 -0
  13. data/lib/rr/{scenario_matches.rb → double_matches.rb} +2 -2
  14. data/lib/rr/{scenario_method_proxy.rb → double_method_proxy.rb} +2 -2
  15. data/lib/rr/errors/argument_equality_error.rb +3 -3
  16. data/lib/rr/errors/rr_error.rb +13 -13
  17. data/lib/rr/errors/scenario_definition_error.rb +3 -3
  18. data/lib/rr/errors/scenario_not_found_error.rb +3 -3
  19. data/lib/rr/errors/scenario_order_error.rb +3 -3
  20. data/lib/rr/errors/times_called_error.rb +3 -3
  21. data/lib/rr/expectations/any_argument_expectation.rb +1 -1
  22. data/lib/rr/expectations/argument_equality_expectation.rb +1 -1
  23. data/lib/rr/expectations/times_called_expectation.rb +1 -1
  24. data/lib/rr/hash_with_object_id_key.rb +1 -1
  25. data/lib/rr/space.rb +40 -40
  26. data/lib/rr/times_called_matchers/any_times_matcher.rb +13 -13
  27. data/lib/rr/times_called_matchers/at_least_matcher.rb +11 -11
  28. data/lib/rr/times_called_matchers/at_most_matcher.rb +16 -16
  29. data/lib/rr/times_called_matchers/integer_matcher.rb +13 -13
  30. data/lib/rr/times_called_matchers/non_terminal.rb +21 -21
  31. data/lib/rr/times_called_matchers/proc_matcher.rb +7 -7
  32. data/lib/rr/times_called_matchers/range_matcher.rb +14 -14
  33. data/lib/rr/times_called_matchers/terminal.rb +16 -16
  34. data/lib/rr/times_called_matchers/times_called_matcher.rb +32 -32
  35. data/spec/core_spec_suite.rb +18 -0
  36. data/{examples → spec}/environment_fixture_setup.rb +0 -1
  37. data/{examples/high_level_example.rb → spec/high_level_spec.rb} +11 -11
  38. data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +67 -0
  39. data/spec/rr/adapters/rr_methods_creator_spec.rb +365 -0
  40. data/spec/rr/adapters/rr_methods_space_spec.rb +134 -0
  41. data/spec/rr/adapters/rr_methods_spec_helper.rb +11 -0
  42. data/{examples/rr/extensions/instance_methods_times_matcher_example.rb → spec/rr/adapters/rr_methods_times_matcher_spec.rb} +4 -4
  43. data/spec/rr/double/double_insertion_bind_spec.rb +78 -0
  44. data/spec/rr/double/double_insertion_dispatching_spec.rb +221 -0
  45. data/spec/rr/double/double_insertion_has_original_method_spec.rb +56 -0
  46. data/spec/rr/double/double_insertion_register_scenario_spec.rb +24 -0
  47. data/spec/rr/double/double_insertion_reset_spec.rb +89 -0
  48. data/spec/rr/double/double_insertion_spec.rb +66 -0
  49. data/spec/rr/double/double_insertion_verify_spec.rb +23 -0
  50. data/spec/rr/double_creator_spec.rb +454 -0
  51. data/{examples/rr/scenario_definition_example.rb → spec/rr/double_definition_spec.rb} +143 -143
  52. data/spec/rr/double_method_proxy_spec.rb +71 -0
  53. data/spec/rr/double_spec.rb +654 -0
  54. data/spec/rr/errors/rr_error_spec.rb +65 -0
  55. data/spec/rr/expectations/any_argument_expectation_spec.rb +47 -0
  56. data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +38 -0
  57. data/spec/rr/expectations/argument_equality_expectation_spec.rb +58 -0
  58. data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +53 -0
  59. data/spec/rr/expectations/duck_type_argument_equality_expectation_spec.rb +71 -0
  60. data/spec/rr/expectations/is_a_argument_equality_expectation_spec.rb +51 -0
  61. data/spec/rr/expectations/numeric_argument_equality_expectation_spec.rb +47 -0
  62. data/spec/rr/expectations/range_argument_equality_expectation_spec.rb +59 -0
  63. data/spec/rr/expectations/regexp_argument_equality_expectation_spec.rb +72 -0
  64. data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +43 -0
  65. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +67 -0
  66. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +71 -0
  67. data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +21 -0
  68. data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +103 -0
  69. data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +79 -0
  70. data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +81 -0
  71. data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +40 -0
  72. data/spec/rr/rspec/rspec_adapter_spec.rb +65 -0
  73. data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +52 -0
  74. data/spec/rr/rspec/rspec_usage_spec.rb +67 -0
  75. data/spec/rr/space/hash_with_object_id_key_spec.rb +88 -0
  76. data/spec/rr/space/space_create_spec.rb +278 -0
  77. data/spec/rr/space/space_helper.rb +7 -0
  78. data/spec/rr/space/space_register_spec.rb +32 -0
  79. data/spec/rr/space/space_reset_spec.rb +131 -0
  80. data/spec/rr/space/space_spec.rb +32 -0
  81. data/spec/rr/space/space_verify_spec.rb +181 -0
  82. data/{examples → spec}/rr/test_unit/test_helper.rb +1 -1
  83. data/{examples → spec}/rr/test_unit/test_unit_backtrace_test.rb +0 -0
  84. data/{examples → spec}/rr/test_unit/test_unit_integration_test.rb +4 -4
  85. data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +47 -0
  86. data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +55 -0
  87. data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +70 -0
  88. data/spec/rr/times_called_matchers/integer_matcher_spec.rb +70 -0
  89. data/spec/rr/times_called_matchers/proc_matcher_spec.rb +55 -0
  90. data/spec/rr/times_called_matchers/range_matcher_spec.rb +76 -0
  91. data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +118 -0
  92. data/spec/rspec_spec_suite.rb +16 -0
  93. data/spec/spec_helper.rb +9 -0
  94. data/{examples/example_suite.rb → spec/spec_suite.rb} +3 -3
  95. data/{examples/test_unit_example_suite.rb → spec/test_unit_spec_suite.rb} +0 -0
  96. metadata +93 -93
  97. data/examples/core_example_suite.rb +0 -31
  98. data/examples/example_helper.rb +0 -9
  99. data/examples/rr/double/double_bind_example.rb +0 -70
  100. data/examples/rr/double/double_dispatching_example.rb +0 -236
  101. data/examples/rr/double/double_example.rb +0 -66
  102. data/examples/rr/double/double_has_original_method_example.rb +0 -56
  103. data/examples/rr/double/double_register_scenario_example.rb +0 -24
  104. data/examples/rr/double/double_reset_example.rb +0 -89
  105. data/examples/rr/double/double_verify_example.rb +0 -23
  106. data/examples/rr/errors/rr_error_example.rb +0 -65
  107. data/examples/rr/expectations/any_argument_expectation_example.rb +0 -52
  108. data/examples/rr/expectations/anything_argument_equality_expectation_example.rb +0 -38
  109. data/examples/rr/expectations/argument_equality_expectation_example.rb +0 -62
  110. data/examples/rr/expectations/boolean_argument_equality_expectation_example.rb +0 -48
  111. data/examples/rr/expectations/duck_type_argument_equality_expectation_example.rb +0 -67
  112. data/examples/rr/expectations/is_a_argument_equality_expectation_example.rb +0 -50
  113. data/examples/rr/expectations/numeric_argument_equality_expectation_example.rb +0 -46
  114. data/examples/rr/expectations/range_argument_equality_expectation_example.rb +0 -59
  115. data/examples/rr/expectations/regexp_argument_equality_expectation_example.rb +0 -67
  116. data/examples/rr/expectations/times_called_expectation/times_called_expectation_any_times_example.rb +0 -50
  117. data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_least_example.rb +0 -73
  118. data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_most_example.rb +0 -77
  119. data/examples/rr/expectations/times_called_expectation/times_called_expectation_example.rb +0 -42
  120. data/examples/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +0 -20
  121. data/examples/rr/expectations/times_called_expectation/times_called_expectation_integer_example.rb +0 -111
  122. data/examples/rr/expectations/times_called_expectation/times_called_expectation_proc_example.rb +0 -88
  123. data/examples/rr/expectations/times_called_expectation/times_called_expectation_range_example.rb +0 -90
  124. data/examples/rr/extensions/instance_methods_argument_matcher_example.rb +0 -65
  125. data/examples/rr/extensions/instance_methods_creator_example.rb +0 -363
  126. data/examples/rr/extensions/instance_methods_example_helper.rb +0 -11
  127. data/examples/rr/extensions/instance_methods_space_example.rb +0 -122
  128. data/examples/rr/rspec/rspec_adapter_example.rb +0 -63
  129. data/examples/rr/rspec/rspec_backtrace_tweaking_example.rb +0 -36
  130. data/examples/rr/rspec/rspec_usage_example.rb +0 -65
  131. data/examples/rr/scenario_creator_example.rb +0 -459
  132. data/examples/rr/scenario_example.rb +0 -701
  133. data/examples/rr/scenario_method_proxy_example.rb +0 -71
  134. data/examples/rr/space/hash_with_object_id_key_example.rb +0 -86
  135. data/examples/rr/space/space_create_example.rb +0 -278
  136. data/examples/rr/space/space_example.rb +0 -29
  137. data/examples/rr/space/space_helper.rb +0 -7
  138. data/examples/rr/space/space_register_example.rb +0 -32
  139. data/examples/rr/space/space_reset_example.rb +0 -120
  140. data/examples/rr/space/space_verify_example.rb +0 -169
  141. data/examples/rr/times_called_matchers/any_times_matcher_example.rb +0 -63
  142. data/examples/rr/times_called_matchers/at_least_matcher_example.rb +0 -70
  143. data/examples/rr/times_called_matchers/at_most_matcher_example.rb +0 -85
  144. data/examples/rr/times_called_matchers/integer_matcher_example.rb +0 -91
  145. data/examples/rr/times_called_matchers/proc_matcher_example.rb +0 -77
  146. data/examples/rr/times_called_matchers/range_matcher_example.rb +0 -97
  147. data/examples/rr/times_called_matchers/times_called_matcher_example.rb +0 -53
  148. data/examples/rspec_example_suite.rb +0 -25
  149. data/lib/rr/extensions/instance_methods.rb +0 -228
  150. data/lib/rr/scenario.rb +0 -337
@@ -1,20 +1,20 @@
1
1
  module RR
2
- module TimesCalledMatchers
3
- # Including this module marks the TimesCalledMatcher as Terminal.
4
- # Being Terminal the Scenario will "terminate" when times called is
5
- # finite.
6
- #
7
- # The Scenario that uses a Terminal TimesCalledMatcher will
8
- # eventually be passed over to the next Scenario when passed
9
- # the matching arguments enough times. This is done by the attempt?
10
- # method returning false when executed a finite number of times.
11
- #
12
- # This is in opposition to NonTerminal TimesCalledMatchers, where
13
- # attempt? will always return true.
14
- module Terminal
15
- def terminal?
16
- true
2
+ module TimesCalledMatchers
3
+ # Including this module marks the TimesCalledMatcher as Terminal.
4
+ # Being Terminal the Double will "terminate" when times called is
5
+ # finite.
6
+ #
7
+ # The Double that uses a Terminal TimesCalledMatcher will
8
+ # eventually be passed over to the next Double when passed
9
+ # the matching arguments enough times. This is done by the attempt?
10
+ # method returning false when executed a finite number of times.
11
+ #
12
+ # This is in opposition to NonTerminal TimesCalledMatchers, where
13
+ # attempt? will always return true.
14
+ module Terminal #:nodoc:
15
+ def terminal?
16
+ true
17
+ end
17
18
  end
18
19
  end
19
- end
20
20
  end
@@ -1,44 +1,44 @@
1
1
  module RR
2
- module TimesCalledMatchers
3
- class TimesCalledMatcher
4
- class << self
5
- def create(value)
6
- return value if value.is_a?(TimesCalledMatcher)
7
- return IntegerMatcher.new(value) if value.is_a?(Integer)
8
- return RangeMatcher.new(value) if value.is_a?(Range )
9
- return ProcMatcher.new(value) if value.is_a?(Proc)
10
- raise ArgumentError, "There is no TimesCalledMatcher for #{value.inspect}."
2
+ module TimesCalledMatchers
3
+ class TimesCalledMatcher #:nodoc:
4
+ class << self
5
+ def create(value)
6
+ return value if value.is_a?(TimesCalledMatcher)
7
+ return IntegerMatcher.new(value) if value.is_a?(Integer)
8
+ return RangeMatcher.new(value) if value.is_a?(Range )
9
+ return ProcMatcher.new(value) if value.is_a?(Proc)
10
+ raise ArgumentError, "There is no TimesCalledMatcher for #{value.inspect}."
11
+ end
11
12
  end
12
- end
13
13
 
14
- attr_reader :times
15
-
16
- def initialize(times)
17
- @times = times
18
- end
14
+ attr_reader :times
19
15
 
20
- def matches?(times_called)
21
- end
16
+ def initialize(times)
17
+ @times = times
18
+ end
22
19
 
23
- def attempt?(times_called)
24
- end
20
+ def matches?(times_called)
21
+ end
25
22
 
26
- def error_message(times_called)
27
- "Called #{times_called.inspect} #{pluralized_time(times_called)}.\n#{expected_message_part}"
28
- end
23
+ def attempt?(times_called)
24
+ end
29
25
 
30
- def ==(other)
31
- self.class == other.class && self.times == other.times
32
- end
26
+ def error_message(times_called)
27
+ "Called #{times_called.inspect} #{pluralized_time(times_called)}.\n#{expected_message_part}"
28
+ end
33
29
 
34
- protected
35
- def expected_message_part
36
- "Expected #{@times.inspect} times."
37
- end
30
+ def ==(other)
31
+ self.class == other.class && self.times == other.times
32
+ end
38
33
 
39
- def pluralized_time(times_called)
40
- (times_called == 1) ? "time" : "times"
34
+ protected
35
+ def expected_message_part
36
+ "Expected #{@times.inspect} times."
37
+ end
38
+
39
+ def pluralized_time(times_called)
40
+ (times_called == 1) ? "time" : "times"
41
+ end
41
42
  end
42
43
  end
43
- end
44
44
  end
@@ -0,0 +1,18 @@
1
+ require "rubygems"
2
+ require "spec"
3
+
4
+ class CoreExampleSuite
5
+ def run
6
+ files = Dir["#{File.dirname(__FILE__)}/**/*_spec.rb"]
7
+ files.delete_if {|file| file.include?('rspec/')}
8
+ files.delete_if {|file| file.include?('test_unit/')}
9
+ puts "Running Rspec Example Suite"
10
+ files.each do |file|
11
+ require file
12
+ end
13
+ end
14
+ end
15
+
16
+ if $0 == __FILE__
17
+ CoreExampleSuite.new.run
18
+ end
@@ -3,5 +3,4 @@ require "spec"
3
3
  dir = File.dirname(__FILE__)
4
4
  $LOAD_PATH.unshift "#{dir}/../lib"
5
5
  require "rr"
6
- require "ruby-debug"
7
6
  require "pp"
@@ -1,10 +1,10 @@
1
1
  dir = File.dirname(__FILE__)
2
- require "#{dir}/example_helper"
2
+ require "#{dir}/spec_helper"
3
3
 
4
4
  describe "RR", :shared => true do
5
5
  before(:each) do
6
6
  @obj = Object.new
7
- extend RR::Extensions::InstanceMethods
7
+ extend RR::Adapters::RRMethods
8
8
  end
9
9
 
10
10
  after(:each) do
@@ -58,26 +58,26 @@ describe "RR mock:" do
58
58
  ).should == "value 1"
59
59
  proc do
60
60
  @obj.foobar(:failure)
61
- end.should raise_error( RR::Errors::ScenarioNotFoundError )
61
+ end.should raise_error( RR::Errors::DoubleNotFoundError )
62
62
  end
63
63
  end
64
64
 
65
- describe "RR probe or proxy:" do
65
+ describe "RR proxy:" do
66
66
  it_should_behave_like "RR"
67
67
 
68
- it "probes via inline call" do
68
+ it "proxies via inline call" do
69
69
  expected_to_s_value = @obj.to_s
70
- mock.probe(@obj).to_s
70
+ mock.proxy(@obj).to_s
71
71
  @obj.to_s.should == expected_to_s_value
72
72
  proc {@obj.to_s}.should raise_error
73
73
  end
74
74
 
75
- it "probe allows ordering" do
75
+ it "proxy allows ordering" do
76
76
  def @obj.to_s(arg)
77
77
  "Original to_s with arg #{arg}"
78
78
  end
79
- mock.probe(@obj).to_s(:foo).ordered
80
- mock.probe(@obj).to_s(:bar).twice.ordered
79
+ mock.proxy(@obj).to_s(:foo).ordered
80
+ mock.proxy(@obj).to_s(:bar).twice.ordered
81
81
 
82
82
  @obj.to_s(:foo).should == "Original to_s with arg foo"
83
83
  @obj.to_s(:bar).should == "Original to_s with arg bar"
@@ -98,7 +98,7 @@ describe "RR probe or proxy:" do
98
98
  proc {@obj.to_s(:bar)}.should raise_error(RR::Errors::TimesCalledError)
99
99
  end
100
100
 
101
- it "probes via block" do
101
+ it "proxies via block" do
102
102
  def @obj.foobar_1(*args)
103
103
  :original_value_1
104
104
  end
@@ -107,7 +107,7 @@ describe "RR probe or proxy:" do
107
107
  :original_value_2
108
108
  end
109
109
 
110
- mock.probe @obj do |c|
110
+ mock.proxy @obj do |c|
111
111
  c.foobar_1(1)
112
112
  c.foobar_2
113
113
  end
@@ -0,0 +1,67 @@
1
+ require "spec/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 == WildcardMatchers::Anything.new
11
+ end
12
+
13
+ it "rr_anything returns an Anything matcher" do
14
+ rr_anything.should == 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 == WildcardMatchers::IsA.new(Integer)
23
+ end
24
+
25
+ it "rr_is_a returns an IsA matcher" do
26
+ rr_is_a(Integer).should == 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 == WildcardMatchers::Numeric.new
35
+ end
36
+
37
+ it "rr_numeric returns an Numeric matcher" do
38
+ rr_numeric.should == 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 == WildcardMatchers::Boolean.new
47
+ end
48
+
49
+ it "rr_boolean returns an Boolean matcher" do
50
+ rr_boolean.should == 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 == 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 == WildcardMatchers::DuckType.new(:one, :two)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,365 @@
1
+ require "spec/spec_helper"
2
+
3
+ module RR
4
+ module Adapters
5
+ describe RRMethods do
6
+ describe "#mock" do
7
+ it_should_behave_like "RR::Adapters::RRMethods"
8
+
9
+ before do
10
+ @subject = Object.new
11
+ class << @subject
12
+ def foobar(*args)
13
+ :original_value
14
+ end
15
+ end
16
+ end
17
+
18
+ it "returns a DoubleCreator when passed no arguments" do
19
+ mock.should be_instance_of(DoubleCreator)
20
+ end
21
+
22
+ it "sets up the RR mock call chain" do
23
+ creates_mock_call_chain(mock(@subject))
24
+ end
25
+
26
+ it "#rr_mock sets up the RR mock call chain" do
27
+ creates_mock_call_chain(rr_mock(@subject))
28
+ end
29
+
30
+ it "creates a mock Double for method when passed a second argument" do
31
+ creates_scenario_with_method_name(mock(@subject, :foobar))
32
+ end
33
+
34
+ it "creates a mock Double for method when passed a second argument with rr_mock" do
35
+ creates_scenario_with_method_name(rr_mock(@subject, :foobar))
36
+ end
37
+
38
+ it "raises error if passed a method name and a block" do
39
+ proc do
40
+ mock(@object, :foobar) {}
41
+ end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
42
+ end
43
+
44
+ def creates_scenario_with_method_name(scenario)
45
+ scenario.with(1, 2) {:baz}
46
+ scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
47
+ scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
48
+ scenario.argument_expectation.expected_arguments.should == [1, 2]
49
+
50
+ @subject.foobar(1, 2).should == :baz
51
+ end
52
+
53
+ def creates_mock_call_chain(creator)
54
+ scenario = creator.foobar(1, 2) {:baz}
55
+ scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
56
+ scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
57
+ scenario.argument_expectation.expected_arguments.should == [1, 2]
58
+
59
+ @subject.foobar(1, 2).should == :baz
60
+ end
61
+ end
62
+
63
+ describe "#stub" do
64
+ it_should_behave_like "RR::Adapters::RRMethods"
65
+
66
+ before do
67
+ @subject = Object.new
68
+ class << @subject
69
+ def foobar(*args)
70
+ :original_value
71
+ end
72
+ end
73
+ end
74
+
75
+ it "returns a DoubleCreator when passed no arguments" do
76
+ stub.should be_instance_of(DoubleCreator)
77
+ end
78
+
79
+ it "sets up the RR stub call chain" do
80
+ creates_stub_call_chain(stub(@subject))
81
+ end
82
+
83
+ it "#rr_stub sets up the RR stub call chain" do
84
+ creates_stub_call_chain(rr_stub(@subject))
85
+ end
86
+
87
+ it "creates a stub Double for method when passed a second argument" do
88
+ creates_scenario_with_method_name(stub(@subject, :foobar))
89
+ end
90
+
91
+ it "#rr_stub creates a stub Double for method when passed a second argument" do
92
+ creates_scenario_with_method_name(rr_stub(@subject, :foobar))
93
+ end
94
+
95
+ it "raises error if passed a method name and a block" do
96
+ proc do
97
+ stub(@object, :foobar) {}
98
+ end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
99
+ end
100
+
101
+ def creates_scenario_with_method_name(scenario)
102
+ scenario.with(1, 2) {:baz}
103
+ scenario.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
104
+ scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
105
+ @subject.foobar(1, 2).should == :baz
106
+ end
107
+
108
+ def creates_stub_call_chain(creator)
109
+ scenario = creator.foobar(1, 2) {:baz}
110
+ scenario.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
111
+ scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
112
+ @subject.foobar(1, 2).should == :baz
113
+ end
114
+ end
115
+
116
+ describe "#proxy and #mock" do
117
+ it_should_behave_like "RR::Adapters::RRMethods"
118
+
119
+ before do
120
+ @subject = Object.new
121
+ class << @subject
122
+ def foobar(*args)
123
+ :original_value
124
+ end
125
+ end
126
+ end
127
+
128
+ it "#proxy returns a DoubleCreator when passed no arguments" do
129
+ proxy.should be_instance_of(DoubleCreator)
130
+ end
131
+
132
+ it "#proxy sets up the RR proxy call chain" do
133
+ creates_mock_proxy_call_chain(mock.proxy(@subject))
134
+ end
135
+
136
+ it "#rr_proxy sets up the RR proxy call chain" do
137
+ creates_mock_proxy_call_chain(rr_mock.proxy(@subject))
138
+ end
139
+
140
+ it "#mock_proxy sets up the RR proxy call chain" do
141
+ creates_mock_proxy_call_chain(mock.proxy(@subject))
142
+ end
143
+
144
+ it "#rr_mock_proxy sets up the RR proxy call chain with rr_proxy" do
145
+ creates_mock_proxy_call_chain(rr_mock.proxy(@subject))
146
+ end
147
+
148
+ it "#proxy creates a mock Double for method when passed a second argument" do
149
+ creates_scenario_with_method_name(mock.proxy(@subject, :foobar))
150
+ end
151
+
152
+ it "#rr_proxy creates a mock Double for method when passed a second argument with rr_mock" do
153
+ creates_scenario_with_method_name(rr_proxy.mock(@subject, :foobar))
154
+ end
155
+
156
+ it "#mock_proxy creates a mock Double for method when passed a second argument" do
157
+ creates_scenario_with_method_name(mock.proxy(@subject, :foobar))
158
+ end
159
+
160
+ it "#rr_mock_proxy creates a mock Double for method when passed a second argument with rr_mock" do
161
+ creates_scenario_with_method_name(rr_mock.proxy(@subject, :foobar))
162
+ end
163
+
164
+ it "raises error if passed a method name and a block" do
165
+ proc do
166
+ mock.proxy(@object, :foobar) {}
167
+ end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
168
+ end
169
+
170
+ def creates_scenario_with_method_name(scenario)
171
+ scenario.with(1, 2)
172
+ scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
173
+ scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
174
+ scenario.argument_expectation.expected_arguments.should == [1, 2]
175
+
176
+ @subject.foobar(1, 2).should == :original_value
177
+ end
178
+
179
+ def creates_mock_proxy_call_chain(creator)
180
+ scenario = creator.foobar(1, 2)
181
+ scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
182
+ scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
183
+ scenario.argument_expectation.expected_arguments.should == [1, 2]
184
+
185
+ @subject.foobar(1, 2).should == :original_value
186
+ end
187
+ end
188
+
189
+ describe "#stub and #proxy" do
190
+ it_should_behave_like "RR::Adapters::RRMethods"
191
+
192
+ before do
193
+ @subject = Object.new
194
+ class << @subject
195
+ def foobar(*args)
196
+ :original_value
197
+ end
198
+ end
199
+ end
200
+
201
+ it "returns a DoubleCreator when passed no arguments" do
202
+ stub.proxy.should be_instance_of(DoubleCreator)
203
+ end
204
+
205
+ it "sets up the RR proxy call chain" do
206
+ creates_stub_proxy_call_chain(stub.proxy(@subject))
207
+ end
208
+
209
+ it "sets up the RR proxy call chain" do
210
+ creates_stub_proxy_call_chain(rr_stub.proxy(@subject))
211
+ end
212
+
213
+ it "#stub.proxy creates a stub Double for method when passed a second argument" do
214
+ creates_scenario_with_method_name(stub.proxy(@subject, :foobar))
215
+ end
216
+
217
+ it "#rr_stub.proxy creates a stub Double for method when passed a second argument with rr_stub" do
218
+ creates_scenario_with_method_name(rr_stub.proxy(@subject, :foobar))
219
+ end
220
+
221
+ it "raises error if passed a method name and a block" do
222
+ proc do
223
+ stub.proxy(@object, :foobar) {}
224
+ end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
225
+ end
226
+
227
+ def creates_scenario_with_method_name(scenario)
228
+ scenario.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
229
+ scenario.argument_expectation.class.should == RR::Expectations::AnyArgumentExpectation
230
+
231
+ @subject.foobar(:something).should == :original_value
232
+ end
233
+
234
+ def creates_stub_proxy_call_chain(creator)
235
+ scenario = creator.foobar
236
+ scenario.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
237
+ scenario.argument_expectation.class.should == RR::Expectations::AnyArgumentExpectation
238
+
239
+ @subject.foobar(1, 2).should == :original_value
240
+ end
241
+ end
242
+
243
+ describe "#do_not_allow" do
244
+ it_should_behave_like "RR::Adapters::RRMethods"
245
+
246
+ before do
247
+ @subject = Object.new
248
+ class << @subject
249
+ def foobar(*args)
250
+ :original_value
251
+ end
252
+ end
253
+ end
254
+
255
+ it "returns a DoubleCreator when passed no arguments" do
256
+ do_not_allow.should be_instance_of(DoubleCreator)
257
+ end
258
+
259
+ it "sets up the RR do_not_allow call chain" do
260
+ creates_do_not_allow_call_chain(dont_allow(@subject))
261
+ creates_do_not_allow_call_chain(rr_dont_allow(@subject))
262
+ creates_do_not_allow_call_chain(dont_call(@subject))
263
+ creates_do_not_allow_call_chain(rr_dont_call(@subject))
264
+ creates_do_not_allow_call_chain(do_not_allow(@subject))
265
+ creates_do_not_allow_call_chain(rr_do_not_allow(@subject))
266
+ creates_do_not_allow_call_chain(dont_allow(@subject))
267
+ creates_do_not_allow_call_chain(rr_dont_allow(@subject))
268
+ end
269
+
270
+ it "creates a mock Double for method when passed a second argument" do
271
+ creates_scenario_with_method_name(dont_allow(@subject, :foobar))
272
+ creates_scenario_with_method_name(rr_dont_allow(@subject, :foobar))
273
+ creates_scenario_with_method_name(dont_call(@subject, :foobar))
274
+ creates_scenario_with_method_name(rr_dont_call(@subject, :foobar))
275
+ creates_scenario_with_method_name(do_not_allow(@subject, :foobar))
276
+ creates_scenario_with_method_name(rr_do_not_allow(@subject, :foobar))
277
+ creates_scenario_with_method_name(dont_allow(@subject, :foobar))
278
+ creates_scenario_with_method_name(rr_dont_allow(@subject, :foobar))
279
+ end
280
+
281
+ it "raises error if passed a method name and a block" do
282
+ proc do
283
+ do_not_allow(@object, :foobar) {}
284
+ end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
285
+ end
286
+
287
+ def creates_scenario_with_method_name(scenario)
288
+ scenario.with(1, 2)
289
+ scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(0)
290
+ scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
291
+ scenario.argument_expectation.expected_arguments.should == [1, 2]
292
+
293
+ proc do
294
+ @subject.foobar(1, 2)
295
+ end.should raise_error(Errors::TimesCalledError)
296
+ reset
297
+ nil
298
+ end
299
+
300
+ def creates_do_not_allow_call_chain(creator)
301
+ scenario = creator.foobar(1, 2)
302
+ scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(0)
303
+ scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
304
+ scenario.argument_expectation.expected_arguments.should == [1, 2]
305
+
306
+ proc do
307
+ @subject.foobar(1, 2)
308
+ end.should raise_error(Errors::TimesCalledError)
309
+ reset
310
+ nil
311
+ end
312
+ end
313
+
314
+ describe DoubleCreator, "#instance_of and #mock" do
315
+ before do
316
+ @klass = Class.new
317
+ end
318
+
319
+ it "returns a DoubleCreator when passed no arguments" do
320
+ instance_of.instance_of.should be_instance_of(DoubleCreator)
321
+ end
322
+
323
+ it "sets up the RR instance_of call chain" do
324
+ creates_instance_of_call_chain(instance_of.mock(@klass))
325
+ end
326
+
327
+ it "#rr_instance_of sets up the RR instance_of call chain" do
328
+ creates_instance_of_call_chain(rr_instance_of.mock(@klass))
329
+ end
330
+
331
+ it "creates a instance_of Double for method when passed a second argument" do
332
+ creates_scenario_with_method_name(instance_of.mock(@klass, :foobar))
333
+ end
334
+
335
+ it "creates a instance_of Double for method when passed a second argument with rr_instance_of" do
336
+ creates_scenario_with_method_name(rr_instance_of.mock(@klass, :foobar))
337
+ end
338
+
339
+ it "raises error if passed a method name and a block" do
340
+ proc do
341
+ instance_of.mock(@klass, :foobar) {}
342
+ end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
343
+ end
344
+
345
+ def creates_scenario_with_method_name(scenario)
346
+ scenario.with(1, 2) {:baz}
347
+ scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
348
+ scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
349
+ scenario.argument_expectation.expected_arguments.should == [1, 2]
350
+
351
+ @klass.new.foobar(1, 2).should == :baz
352
+ end
353
+
354
+ def creates_instance_of_call_chain(creator)
355
+ scenario = creator.foobar(1, 2) {:baz}
356
+ scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
357
+ scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
358
+ scenario.argument_expectation.expected_arguments.should == [1, 2]
359
+
360
+ @klass.new.foobar(1, 2).should == :baz
361
+ end
362
+ end
363
+ end
364
+ end
365
+ end