jferris-rr 0.7.1.0.1239654108

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. data/CHANGES +196 -0
  2. data/README.rdoc +329 -0
  3. data/Rakefile +77 -0
  4. data/lib/rr.rb +84 -0
  5. data/lib/rr/adapters/rr_methods.rb +122 -0
  6. data/lib/rr/adapters/rspec.rb +58 -0
  7. data/lib/rr/adapters/test_unit.rb +29 -0
  8. data/lib/rr/double.rb +212 -0
  9. data/lib/rr/double_definitions/child_double_definition_creator.rb +27 -0
  10. data/lib/rr/double_definitions/double_definition.rb +346 -0
  11. data/lib/rr/double_definitions/double_definition_creator.rb +167 -0
  12. data/lib/rr/double_definitions/double_definition_creator_proxy.rb +37 -0
  13. data/lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb +15 -0
  14. data/lib/rr/double_definitions/strategies/implementation/proxy.rb +62 -0
  15. data/lib/rr/double_definitions/strategies/implementation/reimplementation.rb +14 -0
  16. data/lib/rr/double_definitions/strategies/implementation/strongly_typed_reimplementation.rb +17 -0
  17. data/lib/rr/double_definitions/strategies/scope/instance.rb +15 -0
  18. data/lib/rr/double_definitions/strategies/scope/instance_of_class.rb +46 -0
  19. data/lib/rr/double_definitions/strategies/scope/scope_strategy.rb +15 -0
  20. data/lib/rr/double_definitions/strategies/strategy.rb +70 -0
  21. data/lib/rr/double_definitions/strategies/verification/dont_allow.rb +34 -0
  22. data/lib/rr/double_definitions/strategies/verification/mock.rb +44 -0
  23. data/lib/rr/double_definitions/strategies/verification/stub.rb +45 -0
  24. data/lib/rr/double_definitions/strategies/verification/verification_strategy.rb +15 -0
  25. data/lib/rr/double_injection.rb +143 -0
  26. data/lib/rr/double_matches.rb +51 -0
  27. data/lib/rr/errors/argument_equality_error.rb +6 -0
  28. data/lib/rr/errors/double_definition_error.rb +6 -0
  29. data/lib/rr/errors/double_not_found_error.rb +6 -0
  30. data/lib/rr/errors/double_order_error.rb +6 -0
  31. data/lib/rr/errors/rr_error.rb +20 -0
  32. data/lib/rr/errors/spy_verification_errors/double_injection_not_found_error.rb +8 -0
  33. data/lib/rr/errors/spy_verification_errors/invocation_count_error.rb +8 -0
  34. data/lib/rr/errors/spy_verification_errors/spy_verification_error.rb +8 -0
  35. data/lib/rr/errors/subject_does_not_implement_method_error.rb +6 -0
  36. data/lib/rr/errors/subject_has_different_arity_error.rb +6 -0
  37. data/lib/rr/errors/times_called_error.rb +6 -0
  38. data/lib/rr/expectations/any_argument_expectation.rb +21 -0
  39. data/lib/rr/expectations/argument_equality_expectation.rb +41 -0
  40. data/lib/rr/expectations/times_called_expectation.rb +57 -0
  41. data/lib/rr/hash_with_object_id_key.rb +41 -0
  42. data/lib/rr/recorded_calls.rb +103 -0
  43. data/lib/rr/space.rb +123 -0
  44. data/lib/rr/spy_verification.rb +48 -0
  45. data/lib/rr/spy_verification_proxy.rb +18 -0
  46. data/lib/rr/times_called_matchers/any_times_matcher.rb +18 -0
  47. data/lib/rr/times_called_matchers/at_least_matcher.rb +15 -0
  48. data/lib/rr/times_called_matchers/at_most_matcher.rb +23 -0
  49. data/lib/rr/times_called_matchers/integer_matcher.rb +19 -0
  50. data/lib/rr/times_called_matchers/non_terminal.rb +27 -0
  51. data/lib/rr/times_called_matchers/proc_matcher.rb +11 -0
  52. data/lib/rr/times_called_matchers/range_matcher.rb +21 -0
  53. data/lib/rr/times_called_matchers/terminal.rb +20 -0
  54. data/lib/rr/times_called_matchers/times_called_matcher.rb +44 -0
  55. data/lib/rr/wildcard_matchers/anything.rb +18 -0
  56. data/lib/rr/wildcard_matchers/boolean.rb +23 -0
  57. data/lib/rr/wildcard_matchers/duck_type.rb +32 -0
  58. data/lib/rr/wildcard_matchers/hash_including.rb +29 -0
  59. data/lib/rr/wildcard_matchers/is_a.rb +25 -0
  60. data/lib/rr/wildcard_matchers/numeric.rb +13 -0
  61. data/lib/rr/wildcard_matchers/range.rb +7 -0
  62. data/lib/rr/wildcard_matchers/regexp.rb +7 -0
  63. data/lib/rr/wildcard_matchers/satisfy.rb +26 -0
  64. data/spec/core_spec_suite.rb +19 -0
  65. data/spec/environment_fixture_setup.rb +6 -0
  66. data/spec/high_level_spec.rb +368 -0
  67. data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +67 -0
  68. data/spec/rr/adapters/rr_methods_creator_spec.rb +149 -0
  69. data/spec/rr/adapters/rr_methods_space_spec.rb +115 -0
  70. data/spec/rr/adapters/rr_methods_spec_helper.rb +11 -0
  71. data/spec/rr/adapters/rr_methods_times_matcher_spec.rb +17 -0
  72. data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +112 -0
  73. data/spec/rr/double_definitions/double_definition_creator_proxy_spec.rb +155 -0
  74. data/spec/rr/double_definitions/double_definition_creator_spec.rb +502 -0
  75. data/spec/rr/double_definitions/double_definition_spec.rb +1159 -0
  76. data/spec/rr/double_injection/double_injection_bind_spec.rb +111 -0
  77. data/spec/rr/double_injection/double_injection_dispatching_spec.rb +244 -0
  78. data/spec/rr/double_injection/double_injection_has_original_method_spec.rb +55 -0
  79. data/spec/rr/double_injection/double_injection_reset_spec.rb +90 -0
  80. data/spec/rr/double_injection/double_injection_spec.rb +77 -0
  81. data/spec/rr/double_injection/double_injection_verify_spec.rb +29 -0
  82. data/spec/rr/double_spec.rb +352 -0
  83. data/spec/rr/errors/rr_error_spec.rb +67 -0
  84. data/spec/rr/expectations/any_argument_expectation_spec.rb +47 -0
  85. data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +14 -0
  86. data/spec/rr/expectations/argument_equality_expectation_spec.rb +135 -0
  87. data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +34 -0
  88. data/spec/rr/expectations/hash_including_argument_equality_expectation_spec.rb +82 -0
  89. data/spec/rr/expectations/hash_including_spec.rb +17 -0
  90. data/spec/rr/expectations/satisfy_argument_equality_expectation_spec.rb +59 -0
  91. data/spec/rr/expectations/satisfy_spec.rb +14 -0
  92. data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +46 -0
  93. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +69 -0
  94. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +71 -0
  95. data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +23 -0
  96. data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +104 -0
  97. data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +81 -0
  98. data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +83 -0
  99. data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +38 -0
  100. data/spec/rr/rspec/invocation_matcher_spec.rb +279 -0
  101. data/spec/rr/rspec/rspec_adapter_spec.rb +66 -0
  102. data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +31 -0
  103. data/spec/rr/rspec/rspec_backtrace_tweaking_spec_fixture.rb +11 -0
  104. data/spec/rr/rspec/rspec_usage_spec.rb +86 -0
  105. data/spec/rr/space/hash_with_object_id_key_spec.rb +88 -0
  106. data/spec/rr/space/space_spec.rb +542 -0
  107. data/spec/rr/test_unit/test_helper.rb +7 -0
  108. data/spec/rr/test_unit/test_unit_backtrace_test.rb +35 -0
  109. data/spec/rr/test_unit/test_unit_integration_test.rb +57 -0
  110. data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +47 -0
  111. data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +55 -0
  112. data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +70 -0
  113. data/spec/rr/times_called_matchers/integer_matcher_spec.rb +70 -0
  114. data/spec/rr/times_called_matchers/proc_matcher_spec.rb +55 -0
  115. data/spec/rr/times_called_matchers/range_matcher_spec.rb +76 -0
  116. data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +118 -0
  117. data/spec/rr/wildcard_matchers/anything_spec.rb +24 -0
  118. data/spec/rr/wildcard_matchers/boolean_spec.rb +36 -0
  119. data/spec/rr/wildcard_matchers/duck_type_spec.rb +52 -0
  120. data/spec/rr/wildcard_matchers/is_a_spec.rb +32 -0
  121. data/spec/rr/wildcard_matchers/numeric_spec.rb +32 -0
  122. data/spec/rr/wildcard_matchers/range_spec.rb +35 -0
  123. data/spec/rr/wildcard_matchers/regexp_spec.rb +43 -0
  124. data/spec/rr_spec.rb +28 -0
  125. data/spec/rspec_spec_suite.rb +16 -0
  126. data/spec/spec_helper.rb +107 -0
  127. data/spec/spec_suite.rb +27 -0
  128. data/spec/spy_verification_spec.rb +129 -0
  129. data/spec/test_unit_spec_suite.rb +21 -0
  130. metadata +187 -0
@@ -0,0 +1,118 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ module RR
4
+ module TimesCalledMatchers
5
+ describe TimesCalledMatcher do
6
+ describe ".create" do
7
+ describe "when passed a AnyTimesMatcher" do
8
+ it "returns the passed in argument" do
9
+ matcher = AnyTimesMatcher.new
10
+ TimesCalledMatcher.create(matcher).should === matcher
11
+ end
12
+ end
13
+
14
+ describe "when passed a AtLeastMatcher" do
15
+ it "returns the passed in argument" do
16
+ matcher = AtLeastMatcher.new(5)
17
+ TimesCalledMatcher.create(matcher).should === matcher
18
+ end
19
+ end
20
+
21
+ describe "when passed a AtMostMatcher" do
22
+ it "returns the passed in argument" do
23
+ matcher = AtMostMatcher.new(5)
24
+ TimesCalledMatcher.create(matcher).should === matcher
25
+ end
26
+ end
27
+
28
+ describe "when passed a IntegerMatcher" do
29
+ it "returns the passed in argument" do
30
+ matcher = IntegerMatcher.new(5)
31
+ TimesCalledMatcher.create(matcher).should === matcher
32
+ end
33
+ end
34
+
35
+ describe "when passed a Integer" do
36
+ it "returns IntegerMatcher" do
37
+ TimesCalledMatcher.create(5).should == IntegerMatcher.new(5)
38
+ end
39
+ end
40
+
41
+ describe "when passed a ProcMatcher" do
42
+ it "returns the passed in argument" do
43
+ matcher = ProcMatcher.new(lambda {|other| other == 5})
44
+ TimesCalledMatcher.create(matcher).should === matcher
45
+ end
46
+ end
47
+
48
+ describe "when passed a Lambda" do
49
+ it "returns ProcMatcher" do
50
+ value = lambda {|other| other == 5}
51
+ TimesCalledMatcher.create(value).should == ProcMatcher.new(value)
52
+ end
53
+ end
54
+
55
+ describe "when passed a IntegerMatcher" do
56
+ it "returns the passed in argument" do
57
+ matcher = RangeMatcher.new(2..4)
58
+ TimesCalledMatcher.create(matcher).should === matcher
59
+ end
60
+ end
61
+
62
+ describe "when passed a Integer" do
63
+ it "returns RangeMatcher" do
64
+ TimesCalledMatcher.create(2..4).should == RangeMatcher.new(2..4)
65
+ end
66
+ end
67
+
68
+ describe "when passed a TimesCalledMatcher" do
69
+ it "returns the passed in argument" do
70
+ matcher = TimesCalledMatcher.new(5)
71
+ TimesCalledMatcher.create(matcher).should === matcher
72
+ end
73
+ end
74
+
75
+ describe "when passed an unsupported type" do
76
+ it "raises an ArgumentError" do
77
+ matcher = Object.new
78
+ lambda do
79
+ TimesCalledMatcher.create(matcher)
80
+ end.should raise_error(ArgumentError, "There is no TimesCalledMatcher for #{matcher.inspect}.")
81
+ end
82
+ end
83
+ end
84
+
85
+ describe "#error_message" do
86
+ before do
87
+ @times = 3
88
+ @matcher = TimesCalledMatcher.new(@times)
89
+ end
90
+
91
+ it "has an error message" do
92
+ @matcher.error_message(5).should == (
93
+ "Called 5 times.\nExpected 3 times."
94
+ )
95
+ end
96
+ end
97
+
98
+ describe "#==" do
99
+ before do
100
+ @times = 3
101
+ @matcher = TimesCalledMatcher.new(@times)
102
+ end
103
+
104
+ it "returns true when other is the same class and times are ==" do
105
+ @matcher.should == TimesCalledMatcher.new(@times)
106
+ end
107
+
108
+ it "returns false when other is a different class and times are ==" do
109
+ @matcher.should_not == IntegerMatcher.new(@times)
110
+ end
111
+
112
+ it "returns false when is the same class and times are not ==" do
113
+ @matcher.should_not == TimesCalledMatcher.new(1)
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ module RR
4
+ module WildcardMatchers
5
+ describe Anything do
6
+ attr_reader :matcher
7
+ before do
8
+ @matcher = Anything.new
9
+ end
10
+
11
+ describe "#wildcard_match?" do
12
+ it "returns true" do
13
+ matcher.should be_wildcard_match(Object.new)
14
+ end
15
+ end
16
+
17
+ describe "#inspect" do
18
+ it "returns anything" do
19
+ matcher.inspect.should == "anything"
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ module RR
4
+ module WildcardMatchers
5
+ describe Boolean do
6
+ attr_reader :matcher
7
+
8
+ before do
9
+ @matcher = Boolean.new
10
+ end
11
+
12
+ describe "#wildcard_match?" do
13
+ context "when passed a Boolean" do
14
+ it "returns true" do
15
+ matcher.should be_wildcard_match(true)
16
+ matcher.should be_wildcard_match(false)
17
+ end
18
+ end
19
+
20
+ context "when not passed a Boolean" do
21
+ it "returns false" do
22
+ matcher.should_not be_wildcard_match(:not_a_boolean)
23
+ end
24
+ end
25
+ end
26
+
27
+ describe Boolean do
28
+ describe "#inspect" do
29
+ it "returns boolean" do
30
+ matcher.inspect.should == "boolean"
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,52 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ module RR
4
+ module WildcardMatchers
5
+ describe DuckType do
6
+ attr_reader :matcher
7
+ before do
8
+ @matcher = DuckType.new(:quack, :waddle)
9
+ end
10
+
11
+ describe "#wildcard_match?" do
12
+ before do
13
+ @matching_object = Object.new
14
+ def @matching_object.quack
15
+ end
16
+ def @matching_object.waddle
17
+ end
18
+
19
+ @partial_matching_object = Object.new
20
+ def @partial_matching_object.quack
21
+ end
22
+
23
+ @not_match_object = Object.new
24
+ end
25
+
26
+ context "when passed-in object matches all required methods" do
27
+ it "returns true" do
28
+ matcher.should be_wildcard_match(@matching_object)
29
+ end
30
+ end
31
+
32
+ context "when passed-in object matches some required methods" do
33
+ it "returns false" do
34
+ matcher.should_not be_wildcard_match(@partial_matching_object)
35
+ end
36
+ end
37
+
38
+ context "when passed-in object matches no required methods" do
39
+ it "returns false" do
40
+ matcher.should_not be_wildcard_match(@not_match_object)
41
+ end
42
+ end
43
+ end
44
+
45
+ describe "#inspect" do
46
+ it "returns duck_type with methods" do
47
+ matcher.inspect.should == "duck_type(:quack, :waddle)"
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ module RR
4
+ module WildcardMatchers
5
+ describe IsA do
6
+ attr_reader :matcher
7
+ before do
8
+ @matcher = IsA.new(Symbol)
9
+ end
10
+
11
+ describe "#wildcard_match?" do
12
+ context "when passed an instance of the expected Module" do
13
+ it "returns true" do
14
+ matcher.should be_wildcard_match(:a_symbol)
15
+ end
16
+ end
17
+
18
+ context "when not passed an instance of the expected Module" do
19
+ it "returns false" do
20
+ matcher.should_not be_wildcard_match("not a symbol")
21
+ end
22
+ end
23
+ end
24
+
25
+ describe "#inspect" do
26
+ it "returns the is_a(ClassName)" do
27
+ matcher.inspect.should == "is_a(Symbol)"
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ module RR
4
+ module WildcardMatchers
5
+ describe Numeric do
6
+ attr_reader :matcher
7
+ before do
8
+ @matcher = Numeric.new
9
+ end
10
+
11
+ describe "#wildcard_match?" do
12
+ context "when passed a Numeric" do
13
+ it "returns true" do
14
+ matcher.should be_wildcard_match(99)
15
+ end
16
+ end
17
+
18
+ context "when not passed a Numeric" do
19
+ it "returns false" do
20
+ matcher.should_not be_wildcard_match(:not_a_numeric)
21
+ end
22
+ end
23
+ end
24
+
25
+ describe "#inspect" do
26
+ it "returns numeric" do
27
+ matcher.inspect.should == "numeric"
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,35 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ describe Range do
4
+ attr_reader :matcher
5
+
6
+ before do
7
+ @matcher = 2..3
8
+ end
9
+
10
+ describe "#wildcard_match?" do
11
+ context "when passed-in number falls within the Range" do
12
+ it "returns true" do
13
+ matcher.should be_wildcard_match(3)
14
+ end
15
+ end
16
+
17
+ context "when passed-in number does not fall within the Range" do
18
+ it "returns false" do
19
+ matcher.should_not be_wildcard_match(7)
20
+ end
21
+ end
22
+
23
+ context "when passed-in argument is not a number" do
24
+ it "returns false" do
25
+ matcher.should_not be_wildcard_match("Not a number")
26
+ end
27
+ end
28
+ end
29
+
30
+ describe "#inspect" do
31
+ it "returns the range" do
32
+ matcher.inspect.should == "2..3"
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,43 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ describe Regexp do
4
+ attr_reader :matcher
5
+
6
+ before do
7
+ @matcher = /foo/
8
+ end
9
+
10
+ describe "#wildcard_match?" do
11
+ before do
12
+ @matching_object = Object.new
13
+ def @matching_object.quack
14
+ end
15
+ def @matching_object.waddle
16
+ end
17
+
18
+ @partial_matching_object = Object.new
19
+ def @partial_matching_object.quack
20
+ end
21
+
22
+ @not_match_object = Object.new
23
+ end
24
+
25
+ context "when passed-in String matches the Regexp" do
26
+ it "returns true" do
27
+ matcher.should be_wildcard_match("foobarbaz")
28
+ end
29
+ end
30
+
31
+ context "when passed-in String does not match the Regexp" do
32
+ it "returns false" do
33
+ matcher.should_not be_wildcard_match("no match here")
34
+ end
35
+ end
36
+ end
37
+
38
+ describe "#inspect" do
39
+ it "returns the regexp" do
40
+ matcher.inspect.should == "/foo/"
41
+ end
42
+ end
43
+ end
data/spec/rr_spec.rb ADDED
@@ -0,0 +1,28 @@
1
+ require "#{File.dirname(__FILE__)}/spec_helper"
2
+
3
+ describe "RR" do
4
+ before do
5
+ Object.class_eval do
6
+ def verify
7
+ raise "Dont call me"
8
+ end
9
+ end
10
+ end
11
+
12
+ after do
13
+ Object.class_eval do
14
+ remove_method :verify
15
+ end
16
+ end
17
+
18
+ it "has proxy methods for each method defined directly on Space" do
19
+ space_instance_methods = RR::Space.instance_methods(false)
20
+ space_instance_methods.should_not be_empty
21
+
22
+ rr_instance_methods = RR.methods(false)
23
+ space_instance_methods.each do |space_instance_method|
24
+ rr_instance_methods.should include(space_instance_method)
25
+ end
26
+ RR.verify
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ require "rubygems"
2
+ require "spec"
3
+
4
+ class RspecExampleSuite
5
+ def run
6
+ puts "Running Rspec Example Suite"
7
+ dir = File.dirname(__FILE__)
8
+ Dir["#{dir}/rr/rspec/**/*_spec.rb"].each do |file|
9
+ require file
10
+ end
11
+ end
12
+ end
13
+
14
+ if $0 == __FILE__
15
+ RspecExampleSuite.new.run
16
+ end
@@ -0,0 +1,107 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/environment_fixture_setup"
3
+ require "#{dir}/rr/expectations/times_called_expectation/times_called_expectation_helper"
4
+ require "#{dir}/rr/adapters/rr_methods_spec_helper"
5
+
6
+ Spec::Runner.configure do |config|
7
+ config.mock_with RR::Adapters::Rspec
8
+ end
9
+
10
+ describe "Swapped Space", :shared => true do
11
+ attr_reader :space, :original_space
12
+ before do
13
+ @original_space = RR::Space.instance
14
+ RR::Space.instance = RR::Space.new
15
+ @space = RR::Space.instance
16
+ end
17
+
18
+ after(:each) do
19
+ RR::Space.instance = @original_space
20
+ end
21
+ end
22
+
23
+ module Spec::Example::ExampleMethods
24
+ def new_double(
25
+ double_injection=double_injection,
26
+ double_definition=RR::DoubleDefinitions::DoubleDefinition.new(creator = RR::DoubleDefinitions::DoubleDefinitionCreator.new, subject).with_any_args.any_number_of_times
27
+ )
28
+ RR::Double.new(
29
+ double_injection,
30
+ double_definition
31
+ )
32
+ end
33
+ end
34
+
35
+ module Spec::Example::ExampleGroupMethods
36
+ def macro(name, &implementation)
37
+ (class << self; self; end).class_eval do
38
+ define_method(name, &implementation)
39
+ end
40
+ end
41
+
42
+ define_method("normal strategy definition") do
43
+ describe "strategy definition" do
44
+ attr_reader :strategy_method_name
45
+
46
+ context "when passed a subject" do
47
+ it "returns a DoubleDefinitionCreatorProxy" do
48
+ double = call_strategy(subject).foobar
49
+ double.should be_instance_of(RR::DoubleDefinitions::DoubleDefinition)
50
+ end
51
+ end
52
+
53
+ context "when passed a method name and a definition_eval_block" do
54
+ it "raises an ArgumentError" do
55
+ lambda do
56
+ call_strategy(subject, :foobar) {}
57
+ end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ define_method("! strategy definition") do
64
+ describe "strategy definition" do
65
+ attr_reader :strategy_method_name
66
+
67
+ context "when not passed a method_name argument" do
68
+ it "returns a DoubleDefinitionCreatorProxy" do
69
+ call_strategy.should respond_to(:__subject__)
70
+ end
71
+
72
+ context "when passed a definition_eval_block argument" do
73
+ it "calls the definition_eval_block and passes in the DoubleDefinitionCreatorProxy" do
74
+ passed_in_proxy = nil
75
+ proxy = call_strategy do |proxy|
76
+ passed_in_proxy = proxy
77
+ end
78
+
79
+ passed_in_proxy.should == proxy
80
+ end
81
+ end
82
+ end
83
+
84
+ context "when passed a method_name argument" do
85
+ it "returns a DoubleDefinition" do
86
+ double_definition = call_strategy(:foobar)
87
+ double_definition.class.should == RR::DoubleDefinitions::DoubleDefinition
88
+ end
89
+
90
+ describe "the returned DoubleDefinition" do
91
+ it "has #subject set to an anonymous Object" do
92
+ double_definition = call_strategy(:foobar)
93
+ double_definition.subject.class.should == Object
94
+ end
95
+ end
96
+ end
97
+
98
+ context "when passed a method name and a definition_eval_block" do
99
+ it "raises an ArgumentError" do
100
+ lambda do
101
+ call_strategy(:foobar) {}
102
+ end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end