rr 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +3 -0
- data/Rakefile +1 -1
- data/lib/rr/double_injection.rb +1 -1
- data/lib/rr/expectations/argument_equality_expectation.rb +10 -2
- data/lib/rr/wildcard_matchers/anything.rb +1 -0
- data/lib/rr/wildcard_matchers/boolean.rb +1 -0
- data/lib/rr/wildcard_matchers/duck_type.rb +1 -0
- data/lib/rr/wildcard_matchers/is_a.rb +1 -0
- data/spec/rr/expectations/argument_equality_expectation_spec.rb +86 -41
- metadata +1 -1
data/CHANGES
CHANGED
data/Rakefile
CHANGED
data/lib/rr/double_injection.rb
CHANGED
@@ -67,7 +67,7 @@ module RR
|
|
67
67
|
protected
|
68
68
|
def define_implementation_placeholder
|
69
69
|
me = self
|
70
|
-
meta.
|
70
|
+
meta.__send__(:define_method, placeholder_name) do |arguments|
|
71
71
|
me.__send__(:call_method, arguments.arguments, arguments.block)
|
72
72
|
end
|
73
73
|
end
|
@@ -8,7 +8,10 @@ module RR
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def exact_match?(*arguments)
|
11
|
-
|
11
|
+
return false unless arguments.length == @expected_arguments.length
|
12
|
+
arguments.each_with_index do |arg, index|
|
13
|
+
return false unless equality_match(@expected_arguments[index], arg)
|
14
|
+
end
|
12
15
|
end
|
13
16
|
|
14
17
|
def wildcard_match?(*arguments)
|
@@ -18,7 +21,7 @@ module RR
|
|
18
21
|
if expected_argument.respond_to?(:wildcard_match?)
|
19
22
|
return false unless expected_argument.wildcard_match?(arg)
|
20
23
|
else
|
21
|
-
return false unless expected_argument
|
24
|
+
return false unless equality_match(expected_argument, arg)
|
22
25
|
end
|
23
26
|
end
|
24
27
|
return true
|
@@ -27,6 +30,11 @@ module RR
|
|
27
30
|
def ==(other)
|
28
31
|
@expected_arguments == other.expected_arguments
|
29
32
|
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
def equality_match(arg1, arg2)
|
36
|
+
arg1.respond_to?(:__rr__eql?) ? arg1 == arg2 : arg1.eql?(arg2)
|
37
|
+
end
|
30
38
|
end
|
31
39
|
end
|
32
40
|
end
|
@@ -1,58 +1,103 @@
|
|
1
1
|
require "spec/spec_helper"
|
2
2
|
|
3
3
|
module RR
|
4
|
-
module Expectations
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "#expected_arguments" do
|
12
|
-
it "returns the passed in expected_arguments" do
|
13
|
-
expectation.expected_arguments.should == [1, 2, 3]
|
4
|
+
module Expectations
|
5
|
+
describe ArgumentEqualityExpectation do
|
6
|
+
attr_reader :expectation
|
7
|
+
before do
|
8
|
+
@expectation = ArgumentEqualityExpectation.new(1, 2, 3)
|
14
9
|
end
|
15
|
-
end
|
16
10
|
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
describe "#expected_arguments" do
|
12
|
+
it "returns the passed in expected_arguments" do
|
13
|
+
expectation.expected_arguments.should == [1, 2, 3]
|
14
|
+
end
|
20
15
|
end
|
21
16
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
17
|
+
describe "==" do
|
18
|
+
it "returns true when passed in expected_arguments are equal" do
|
19
|
+
expectation.should == ArgumentEqualityExpectation.new(1, 2, 3)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns false when passed in expected_arguments are not equal" do
|
23
|
+
expectation.should_not == ArgumentEqualityExpectation.new(1, 2)
|
24
|
+
expectation.should_not == ArgumentEqualityExpectation.new(1)
|
25
|
+
expectation.should_not == ArgumentEqualityExpectation.new(:something)
|
26
|
+
expectation.should_not == ArgumentEqualityExpectation.new()
|
27
|
+
end
|
27
28
|
end
|
28
|
-
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
describe "#exact_match?" do
|
31
|
+
it "returns true when all arguments exactly match" do
|
32
|
+
expectation.should be_exact_match(1, 2, 3)
|
33
|
+
expectation.should_not be_exact_match(1, 2)
|
34
|
+
expectation.should_not be_exact_match(1)
|
35
|
+
expectation.should_not be_exact_match()
|
36
|
+
expectation.should_not be_exact_match("does not match")
|
37
|
+
end
|
37
38
|
end
|
38
|
-
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
describe "#wildcard_match?" do
|
41
|
+
it "returns false when not exact match" do
|
42
|
+
expectation = ArgumentEqualityExpectation.new(1)
|
43
|
+
expectation.should_not be_wildcard_match(1, 2, 3)
|
44
|
+
expectation.should_not be_wildcard_match("whatever")
|
45
|
+
expectation.should_not be_wildcard_match("whatever", "else")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns true when exact match" do
|
49
|
+
expectation = ArgumentEqualityExpectation.new(1, 2)
|
50
|
+
expectation.should be_wildcard_match(1, 2)
|
51
|
+
expectation.should_not be_wildcard_match(1)
|
52
|
+
expectation.should_not be_wildcard_match("whatever", "else")
|
53
|
+
end
|
46
54
|
end
|
47
55
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
56
|
+
describe "Functional spec" do
|
57
|
+
class ArgumentEqualityFunctionalFixture
|
58
|
+
attr_reader :arg1, :arg2
|
59
|
+
def initialize(arg1, arg2)
|
60
|
+
@arg1, @arg2 = arg1, arg2
|
61
|
+
end
|
62
|
+
|
63
|
+
def ==(other)
|
64
|
+
arg1 == (other.arg1) &&
|
65
|
+
arg2 == (other.arg2)
|
66
|
+
end
|
67
|
+
|
68
|
+
def eql?(other)
|
69
|
+
arg1.eql?(other.arg1) &&
|
70
|
+
arg2.eql?(other.arg2)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
before(:each) do
|
75
|
+
@predicate1 = 'first' # these should be mocks, waiting on rr bug fix
|
76
|
+
@predicate2 = 'second'
|
77
|
+
@predicate3 = 'third'
|
78
|
+
end
|
79
|
+
|
80
|
+
it "when mock.proxy ==, does not have infinite recursion" do
|
81
|
+
mock.proxy(@predicate1) == @predicate1
|
82
|
+
mock.proxy(@predicate2) == @predicate2
|
83
|
+
ArgumentEqualityFunctionalFixture.new(@predicate1, @predicate2).should == ArgumentEqualityFunctionalFixture.new(@predicate1, @predicate2)
|
84
|
+
|
85
|
+
mock.proxy(@predicate1) == @predicate1
|
86
|
+
mock.proxy(@predicate2) == @predicate3
|
87
|
+
ArgumentEqualityFunctionalFixture.new(@predicate1, @predicate2).should_not == ArgumentEqualityFunctionalFixture.new(@predicate1, @predicate3)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "when mock.proxy .eql?, does not have infinite recursion" do
|
91
|
+
mock.proxy(@predicate1).eql? @predicate1
|
92
|
+
mock.proxy(@predicate2).eql? @predicate2
|
93
|
+
ArgumentEqualityFunctionalFixture.new(@predicate1, @predicate2).should be_eql(ArgumentEqualityFunctionalFixture.new(@predicate1, @predicate2))
|
94
|
+
|
95
|
+
mock.proxy(@predicate1).eql? @predicate1
|
96
|
+
mock.proxy(@predicate2).eql? @predicate3
|
97
|
+
ArgumentEqualityFunctionalFixture.new(@predicate1, @predicate2).should_not be_eql(ArgumentEqualityFunctionalFixture.new(@predicate1, @predicate3))
|
98
|
+
end
|
53
99
|
end
|
54
100
|
end
|
55
|
-
end
|
56
101
|
|
57
|
-
end
|
102
|
+
end
|
58
103
|
end
|
metadata
CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rr
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.4.
|
6
|
+
version: 0.4.5
|
7
7
|
date: 2008-01-15 00:00:00 -08:00
|
8
8
|
summary: RR (Double Ruby) is a double framework that features a rich selection of double techniques and a terse syntax. http://xunitpatterns.com/Test%20Double.html
|
9
9
|
require_paths:
|