rr 0.4.10 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. data/CHANGES +14 -0
  2. data/README.rdoc +67 -13
  3. data/Rakefile +1 -1
  4. data/lib/rr.rb +29 -9
  5. data/lib/rr/adapters/rr_methods.rb +38 -158
  6. data/lib/rr/double.rb +46 -41
  7. data/lib/rr/double_definitions/child_double_definition_creator.rb +23 -0
  8. data/lib/rr/double_definitions/double_definition.rb +212 -0
  9. data/lib/rr/double_definitions/double_definition_creator.rb +153 -0
  10. data/lib/rr/double_definitions/double_definition_creator_proxy.rb +25 -0
  11. data/lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb +15 -0
  12. data/lib/rr/double_definitions/strategies/implementation/proxy.rb +62 -0
  13. data/lib/rr/double_definitions/strategies/implementation/reimplementation.rb +14 -0
  14. data/lib/rr/double_definitions/strategies/scope/instance.rb +15 -0
  15. data/lib/rr/double_definitions/strategies/scope/instance_of_class.rb +43 -0
  16. data/lib/rr/double_definitions/strategies/scope/scope_strategy.rb +15 -0
  17. data/lib/rr/double_definitions/strategies/strategy.rb +70 -0
  18. data/lib/rr/double_definitions/strategies/verification/dont_allow.rb +34 -0
  19. data/lib/rr/double_definitions/strategies/verification/mock.rb +44 -0
  20. data/lib/rr/double_definitions/strategies/verification/stub.rb +45 -0
  21. data/lib/rr/double_definitions/strategies/verification/verification_strategy.rb +15 -0
  22. data/lib/rr/double_injection.rb +21 -15
  23. data/lib/rr/expectations/argument_equality_expectation.rb +2 -1
  24. data/lib/rr/space.rb +23 -22
  25. data/lib/rr/wildcard_matchers/hash_including.rb +29 -0
  26. data/lib/rr/wildcard_matchers/satisfy.rb +26 -0
  27. data/spec/high_level_spec.rb +111 -64
  28. data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +1 -1
  29. data/spec/rr/adapters/rr_methods_creator_spec.rb +99 -315
  30. data/spec/rr/adapters/rr_methods_space_spec.rb +90 -109
  31. data/spec/rr/adapters/rr_methods_spec_helper.rb +1 -1
  32. data/spec/rr/adapters/rr_methods_times_matcher_spec.rb +1 -1
  33. data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +103 -0
  34. data/spec/rr/double_definitions/double_definition_creator_proxy_spec.rb +83 -0
  35. data/spec/rr/double_definitions/double_definition_creator_spec.rb +495 -0
  36. data/spec/rr/double_definitions/double_definition_spec.rb +1116 -0
  37. data/spec/rr/double_injection/double_injection_bind_spec.rb +111 -0
  38. data/spec/rr/double_injection/double_injection_dispatching_spec.rb +245 -0
  39. data/spec/rr/{double → double_injection}/double_injection_has_original_method_spec.rb +9 -9
  40. data/spec/rr/double_injection/double_injection_reset_spec.rb +90 -0
  41. data/spec/rr/double_injection/double_injection_spec.rb +77 -0
  42. data/spec/rr/double_injection/double_injection_verify_spec.rb +29 -0
  43. data/spec/rr/double_spec.rb +156 -136
  44. data/spec/rr/errors/rr_error_spec.rb +1 -1
  45. data/spec/rr/expectations/any_argument_expectation_spec.rb +1 -1
  46. data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +6 -30
  47. data/spec/rr/expectations/argument_equality_expectation_spec.rb +35 -18
  48. data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +22 -41
  49. data/spec/rr/expectations/hash_including_argument_equality_expectation_spec.rb +82 -0
  50. data/spec/rr/expectations/hash_including_spec.rb +17 -0
  51. data/spec/rr/expectations/satisfy_argument_equality_expectation_spec.rb +59 -0
  52. data/spec/rr/expectations/satisfy_spec.rb +14 -0
  53. data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +30 -28
  54. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +55 -54
  55. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +49 -48
  56. data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +9 -7
  57. data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +77 -76
  58. data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +58 -57
  59. data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +59 -58
  60. data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +25 -24
  61. data/spec/rr/rspec/rspec_adapter_spec.rb +12 -11
  62. data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +10 -8
  63. data/spec/rr/rspec/rspec_usage_spec.rb +1 -1
  64. data/spec/rr/space/hash_with_object_id_key_spec.rb +1 -1
  65. data/spec/rr/space/space_spec.rb +330 -192
  66. data/spec/rr/test_unit/test_helper.rb +1 -2
  67. data/spec/rr/test_unit/test_unit_backtrace_test.rb +1 -2
  68. data/spec/rr/test_unit/test_unit_integration_test.rb +1 -2
  69. data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +1 -1
  70. data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +1 -1
  71. data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +1 -1
  72. data/spec/rr/times_called_matchers/integer_matcher_spec.rb +1 -1
  73. data/spec/rr/times_called_matchers/proc_matcher_spec.rb +1 -1
  74. data/spec/rr/times_called_matchers/range_matcher_spec.rb +1 -1
  75. data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +1 -1
  76. data/spec/rr/wildcard_matchers/anything_spec.rb +24 -0
  77. data/spec/rr/wildcard_matchers/boolean_spec.rb +36 -0
  78. data/spec/rr/wildcard_matchers/duck_type_spec.rb +52 -0
  79. data/spec/rr/wildcard_matchers/is_a_spec.rb +32 -0
  80. data/spec/rr/wildcard_matchers/numeric_spec.rb +32 -0
  81. data/spec/rr/wildcard_matchers/range_spec.rb +35 -0
  82. data/spec/rr/wildcard_matchers/regexp_spec.rb +43 -0
  83. data/spec/rr_spec.rb +28 -0
  84. data/spec/spec_helper.rb +84 -0
  85. metadata +43 -29
  86. data/lib/rr/double_creator.rb +0 -271
  87. data/lib/rr/double_definition.rb +0 -179
  88. data/lib/rr/double_definition_builder.rb +0 -44
  89. data/lib/rr/double_definition_creator.rb +0 -156
  90. data/lib/rr/double_definition_creator_proxy.rb +0 -20
  91. data/spec/rr/double/double_injection_bind_spec.rb +0 -105
  92. data/spec/rr/double/double_injection_dispatching_spec.rb +0 -228
  93. data/spec/rr/double/double_injection_reset_spec.rb +0 -86
  94. data/spec/rr/double/double_injection_spec.rb +0 -72
  95. data/spec/rr/double/double_injection_verify_spec.rb +0 -24
  96. data/spec/rr/double_definition_creator_proxy_spec.rb +0 -85
  97. data/spec/rr/double_definition_creator_spec.rb +0 -496
  98. data/spec/rr/double_definition_spec.rb +0 -815
  99. data/spec/rr/expectations/anything_spec.rb +0 -14
  100. data/spec/rr/expectations/boolean_spec.rb +0 -14
  101. data/spec/rr/expectations/duck_type_argument_equality_expectation_spec.rb +0 -71
  102. data/spec/rr/expectations/duck_type_spec.rb +0 -14
  103. data/spec/rr/expectations/is_a_argument_equality_expectation_spec.rb +0 -51
  104. data/spec/rr/expectations/is_a_spec.rb +0 -14
  105. data/spec/rr/expectations/numeric_argument_equality_expectation_spec.rb +0 -47
  106. data/spec/rr/expectations/numeric_spec.rb +0 -14
  107. data/spec/rr/expectations/range_argument_equality_expectation_spec.rb +0 -59
  108. data/spec/rr/expectations/range_spec.rb +0 -10
  109. data/spec/rr/expectations/regexp_argument_equality_expectation_spec.rb +0 -72
  110. data/spec/rr/expectations/regexp_spec.rb +0 -10
@@ -1,14 +0,0 @@
1
- require "spec/spec_helper"
2
-
3
- module RR
4
- module WildcardMatchers
5
- describe Anything do
6
- describe "#inspect" do
7
- it "returns anything" do
8
- matcher = Anything.new
9
- matcher.inspect.should == "anything"
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- require "spec/spec_helper"
2
-
3
- module RR
4
- module WildcardMatchers
5
- describe Boolean do
6
- describe "#inspect" do
7
- it "returns boolean" do
8
- matcher = Boolean.new
9
- matcher.inspect.should == "boolean"
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -1,71 +0,0 @@
1
- require "spec/spec_helper"
2
-
3
- module RR
4
- module Expectations
5
- describe ArgumentEqualityExpectation, "with DuckType argument" do
6
- attr_reader :expectation
7
-
8
- describe "#exact_match?" do
9
- before do
10
- @expectation = ArgumentEqualityExpectation.new(duck_type(:to_s))
11
- end
12
-
13
- it "returns true when passed in an DuckType matcher with the same argument list" do
14
- expectation.should be_exact_match(WildcardMatchers::DuckType.new(:to_s))
15
- end
16
-
17
- it "returns false when passed in an DuckType matcher with a different argument list" do
18
- expectation.should_not be_exact_match(WildcardMatchers::DuckType.new(:to_s, :to_i))
19
- end
20
-
21
- it "returns false otherwise" do
22
- expectation.should_not be_exact_match("hello")
23
- expectation.should_not be_exact_match(:hello)
24
- expectation.should_not be_exact_match(1)
25
- expectation.should_not be_exact_match(nil)
26
- expectation.should_not be_exact_match(true)
27
- expectation.should_not be_exact_match()
28
- end
29
- end
30
-
31
- describe "#wildcard_match?" do
32
- before do
33
- @matching_object = Object.new
34
- def @matching_object.quack
35
- end
36
- def @matching_object.waddle
37
- end
38
-
39
- @partial_matching_object = Object.new
40
- def @partial_matching_object.quack
41
- end
42
-
43
- @not_match_object = Object.new
44
-
45
- @expectation = ArgumentEqualityExpectation.new(duck_type(:quack, :waddle))
46
- end
47
-
48
- it "returns true when object matches all required methods" do
49
- expectation.should be_wildcard_match(@matching_object)
50
- end
51
-
52
- it "returns false when object matches some required methods" do
53
- expectation.should_not be_wildcard_match(@partial_matching_object)
54
- end
55
-
56
- it "returns false when passed an object that matches no required methods" do
57
- expectation.should_not be_wildcard_match(@not_match_object)
58
- end
59
-
60
- it "returns true when an exact match" do
61
- expectation.should be_wildcard_match(duck_type(:quack, :waddle))
62
- end
63
-
64
- it "returns false when not passed correct number of arguments" do
65
- expectation.should_not be_wildcard_match()
66
- expectation.should_not be_wildcard_match(@matching_object, @matching_object)
67
- end
68
- end
69
- end
70
- end
71
- end
@@ -1,14 +0,0 @@
1
- require "spec/spec_helper"
2
-
3
- module RR
4
- module WildcardMatchers
5
- describe DuckType do
6
- describe "#inspect" do
7
- it "returns duck_type with methods" do
8
- matcher = DuckType.new(:foo, :bar, :baz)
9
- matcher.inspect.should == "duck_type(:foo, :bar, :baz)"
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -1,51 +0,0 @@
1
- require "spec/spec_helper"
2
-
3
- module RR
4
- module Expectations
5
- describe ArgumentEqualityExpectation, "with is_a string matcher" do
6
- attr_reader :expectation
7
-
8
- before do
9
- @expectation = ArgumentEqualityExpectation.new(is_a(String))
10
- end
11
-
12
- describe "#exact_match?" do
13
- it "returns true when passed in an IsA module" do
14
- expectation.should be_exact_match(WildcardMatchers::IsA.new(String))
15
- end
16
-
17
- it "returns false when passed in an IsA object with a different module" do
18
- expectation.should_not be_exact_match(WildcardMatchers::IsA.new(Integer))
19
- end
20
-
21
- it "returns false otherwise" do
22
- expectation.should_not be_exact_match("hello")
23
- expectation.should_not be_exact_match(:hello)
24
- expectation.should_not be_exact_match(1)
25
- expectation.should_not be_exact_match(nil)
26
- expectation.should_not be_exact_match()
27
- end
28
- end
29
-
30
- describe "#wildcard_match?" do
31
- it "returns true when passed a String" do
32
- expectation.should be_wildcard_match("Hello")
33
- end
34
-
35
- it "returns false when not passed a String" do
36
- expectation.should_not be_wildcard_match(:not_a_string)
37
- end
38
-
39
- it "returns true when an exact match" do
40
- expectation.should be_wildcard_match(is_a(String))
41
- end
42
-
43
- it "returns false when not passed correct number of arguments" do
44
- expectation.should_not be_wildcard_match()
45
- expectation.should_not be_wildcard_match("one", "two")
46
- end
47
- end
48
- end
49
-
50
- end
51
- end
@@ -1,14 +0,0 @@
1
- require "spec/spec_helper"
2
-
3
- module RR
4
- module WildcardMatchers
5
- describe IsA do
6
- describe "#inspect" do
7
- it "returns the is_a(ClassName)" do
8
- matcher = IsA.new(Symbol)
9
- matcher.inspect.should == "is_a(Symbol)"
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -1,47 +0,0 @@
1
- require "spec/spec_helper"
2
-
3
- module RR
4
- module Expectations
5
- describe ArgumentEqualityExpectation, "with numeric argument" do
6
- attr_reader :expectation
7
-
8
- before do
9
- @expectation = ArgumentEqualityExpectation.new(numeric)
10
- end
11
-
12
- describe "#exact_match?" do
13
- it "returns true when passed in an IsA module" do
14
- expectation.should be_exact_match(WildcardMatchers::Numeric.new)
15
- end
16
-
17
- it "returns false otherwise" do
18
- expectation.should_not be_exact_match("hello")
19
- expectation.should_not be_exact_match(:hello)
20
- expectation.should_not be_exact_match(1)
21
- expectation.should_not be_exact_match(nil)
22
- expectation.should_not be_exact_match()
23
- end
24
- end
25
-
26
- describe "#wildcard_match?" do
27
- it "returns true when passed a Numeric" do
28
- expectation.should be_wildcard_match(99)
29
- end
30
-
31
- it "returns false when not passed a Numeric" do
32
- expectation.should_not be_wildcard_match(:not_a_numeric)
33
- end
34
-
35
- it "returns true when an exact match" do
36
- expectation.should be_wildcard_match(numeric)
37
- end
38
-
39
- it "returns false when not passed correct number of arguments" do
40
- expectation.should_not be_wildcard_match()
41
- expectation.should_not be_wildcard_match(1, 2)
42
- end
43
- end
44
- end
45
-
46
- end
47
- end
@@ -1,14 +0,0 @@
1
- require "spec/spec_helper"
2
-
3
- module RR
4
- module WildcardMatchers
5
- describe Numeric do
6
- describe "#inspect" do
7
- it "returns numeric" do
8
- matcher = Numeric.new
9
- matcher.inspect.should == "numeric"
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -1,59 +0,0 @@
1
- require "spec/spec_helper"
2
-
3
- module RR
4
- module Expectations
5
- describe ArgumentEqualityExpectation, "with range argument" do
6
- attr_reader :expectation
7
- before do
8
- @expectation = ArgumentEqualityExpectation.new(2..5)
9
- end
10
-
11
- describe "#exact_match?" do
12
- it "returns true when passed in an Range matcher with the same argument list" do
13
- expectation.should be_exact_match(2..5)
14
- end
15
-
16
- it "returns false when passed in an Range matcher with a different argument list" do
17
- expectation.should_not be_exact_match(3..6)
18
- end
19
-
20
- it "returns false otherwise" do
21
- expectation.should_not be_exact_match(2)
22
- expectation.should_not be_exact_match(:hello)
23
- expectation.should_not be_exact_match(3)
24
- expectation.should_not be_exact_match(nil)
25
- expectation.should_not be_exact_match(true)
26
- expectation.should_not be_exact_match()
27
- end
28
- end
29
-
30
- describe "#wildcard_match?" do
31
- it "returns true when string matches the range" do
32
- expectation.should be_wildcard_match(3)
33
- end
34
-
35
- it "returns false when string does not match the range" do
36
- expectation.should_not be_wildcard_match(7)
37
- end
38
-
39
- it "returns true when an exact match" do
40
- expectation.should be_wildcard_match(2..5)
41
- end
42
-
43
- it "returns false when not an exact match" do
44
- expectation.should_not be_wildcard_match(3..9)
45
- end
46
-
47
- it "returns false when not a number" do
48
- expectation.should_not be_wildcard_match("Not a number")
49
- end
50
-
51
- it "returns false when not passed correct number of arguments" do
52
- expectation.should_not be_wildcard_match()
53
- expectation.should_not be_wildcard_match(2, 3)
54
- end
55
- end
56
- end
57
-
58
- end
59
- end
@@ -1,10 +0,0 @@
1
- require "spec/spec_helper"
2
-
3
- describe Range do
4
- describe "#inspect" do
5
- it "returns the range" do
6
- matcher = 2..3
7
- matcher.inspect.should == "2..3"
8
- end
9
- end
10
- end
@@ -1,72 +0,0 @@
1
- require "spec/spec_helper"
2
-
3
- module RR
4
- module Expectations
5
- describe ArgumentEqualityExpectation, "with regexp matcher" do
6
- attr_reader :expectation
7
-
8
- before do
9
- @expectation = ArgumentEqualityExpectation.new(/abc/)
10
- end
11
-
12
- describe "#exact_match?" do
13
- it "returns true when passed in an Regexp matcher with the same argument list" do
14
- expectation.should be_exact_match(/abc/)
15
- end
16
-
17
- it "returns false when passed in an Regexp matcher with a different argument list" do
18
- expectation.should_not be_exact_match(/def/)
19
- end
20
-
21
- it "returns false otherwise" do
22
- expectation.should_not be_exact_match("abc")
23
- expectation.should_not be_exact_match(:hello)
24
- expectation.should_not be_exact_match(1)
25
- expectation.should_not be_exact_match(nil)
26
- expectation.should_not be_exact_match(true)
27
- expectation.should_not be_exact_match()
28
- end
29
- end
30
-
31
- describe "#wildcard_match?" do
32
- before do
33
- @matching_object = Object.new
34
- def @matching_object.quack
35
- end
36
- def @matching_object.waddle
37
- end
38
-
39
- @partial_matching_object = Object.new
40
- def @partial_matching_object.quack
41
- end
42
-
43
- @not_match_object = Object.new
44
-
45
- expectation = ArgumentEqualityExpectation.new(/abc/)
46
- end
47
-
48
- it "returns true when string matches the regexp" do
49
- expectation.should be_wildcard_match("Tabcola")
50
- end
51
-
52
- it "returns false when string does not match the regexp" do
53
- expectation.should_not be_wildcard_match("no match here")
54
- end
55
-
56
- it "returns true when an exact match" do
57
- expectation.should be_wildcard_match(/abc/)
58
- end
59
-
60
- it "returns false when not an exact match" do
61
- expectation.should_not be_wildcard_match(/def/)
62
- end
63
-
64
- it "returns false when not passed correct number of arguments" do
65
- expectation.should_not be_wildcard_match()
66
- expectation.should_not be_wildcard_match('abc', 'abc')
67
- end
68
- end
69
- end
70
-
71
- end
72
- end
@@ -1,10 +0,0 @@
1
- require "spec/spec_helper"
2
-
3
- describe Regexp do
4
- describe "#inspect" do
5
- it "returns the regexp" do
6
- matcher = /foo/
7
- matcher.inspect.should == "/foo/"
8
- end
9
- end
10
- end