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 CHANGED
@@ -1,3 +1,6 @@
1
+ * 0.4.5
2
+ - Fixed doubles for == and #eql? methods
3
+
1
4
  * 0.4.4
2
5
  - Doc improvements
3
6
  - Methods that are not alphabetic, such as ==, can be doubles
data/Rakefile CHANGED
@@ -26,7 +26,7 @@ def run_suite
26
26
  end
27
27
 
28
28
  PKG_NAME = "rr"
29
- PKG_VERSION = "0.4.4"
29
+ PKG_VERSION = "0.4.5"
30
30
  PKG_FILES = FileList[
31
31
  '[A-Z]*',
32
32
  '*.rb',
@@ -67,7 +67,7 @@ module RR
67
67
  protected
68
68
  def define_implementation_placeholder
69
69
  me = self
70
- meta.send(:define_method, placeholder_name) do |arguments|
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
- @expected_arguments == arguments
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 == arg
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
@@ -8,6 +8,7 @@ module RR
8
8
  def ==(other)
9
9
  other.is_a?(self.class)
10
10
  end
11
+ alias_method :eql?, :==
11
12
 
12
13
  def inspect
13
14
  'anything'
@@ -8,6 +8,7 @@ module RR
8
8
  def ==(other)
9
9
  other.is_a?(self.class)
10
10
  end
11
+ alias_method :eql?, :==
11
12
 
12
13
  def inspect
13
14
  'boolean'
@@ -26,6 +26,7 @@ module RR
26
26
  return false unless other.is_a?(self.class)
27
27
  self.required_methods == other.required_methods
28
28
  end
29
+ alias_method :eql?, :==
29
30
  end
30
31
  end
31
32
  end
@@ -19,6 +19,7 @@ module RR
19
19
  return false unless other.is_a?(self.class)
20
20
  self.klass == other.klass
21
21
  end
22
+ alias_method :eql?, :==
22
23
  end
23
24
  end
24
25
  end
@@ -1,58 +1,103 @@
1
1
  require "spec/spec_helper"
2
2
 
3
3
  module RR
4
- module Expectations
5
- describe ArgumentEqualityExpectation do
6
- attr_reader :expectation
7
- before do
8
- @expectation = ArgumentEqualityExpectation.new(1, 2, 3)
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
- describe "==" do
18
- it "returns true when passed in expected_arguments are equal" do
19
- expectation.should == ArgumentEqualityExpectation.new(1, 2, 3)
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
- 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()
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
- 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")
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
- 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")
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
- 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")
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.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: