contrast 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/contrast.gemspec +1 -0
- data/lib/contrast/detective.rb +9 -1
- data/lib/contrast/matching_exception.rb +5 -0
- data/lib/contrast/version.rb +1 -1
- data/spec/contrast/detective_spec.rb +13 -5
- data/spec/contrast/matching_exception_spec.rb +29 -0
- data/spec/spec_helper.rb +3 -3
- metadata +20 -2
data/Gemfile
CHANGED
data/contrast.gemspec
CHANGED
data/lib/contrast/detective.rb
CHANGED
@@ -1,15 +1,23 @@
|
|
1
|
+
require 'subtle'
|
1
2
|
module Contrast
|
3
|
+
|
2
4
|
class Detective
|
3
5
|
def initialize(*args)
|
4
6
|
@fields = args
|
5
7
|
end
|
6
8
|
|
7
9
|
def examine(a, b)
|
8
|
-
@fields.select do |field|
|
10
|
+
keys = @fields.select do |field|
|
9
11
|
first = get_the_value(a, field)
|
10
12
|
second = get_the_value(b, field)
|
11
13
|
the_values_the_do_not_match(first, second)
|
12
14
|
end
|
15
|
+
result = {}
|
16
|
+
keys.each do |key|
|
17
|
+
result[key] = {:actual_value => get_the_value(a, key),
|
18
|
+
:expected_value => get_the_value(b, key)}
|
19
|
+
end
|
20
|
+
result
|
13
21
|
end
|
14
22
|
|
15
23
|
private
|
@@ -1,5 +1,10 @@
|
|
1
|
+
require 'awesome_print'
|
1
2
|
module Contrast
|
2
3
|
class MatchingException < StandardError
|
3
4
|
attr_accessor :results
|
5
|
+
def to_s
|
6
|
+
return 'The results did not match, but I cannot tell you why.' if results.nil? || results.empty?
|
7
|
+
return self.results.ai
|
8
|
+
end
|
4
9
|
end
|
5
10
|
end
|
data/lib/contrast/version.rb
CHANGED
@@ -32,7 +32,15 @@ describe Contrast::Detective do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should return the field" do
|
35
|
-
@result[0].must_equal :name
|
35
|
+
@result.keys[0].must_equal :name
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return the actual value" do
|
39
|
+
@result[:name][:actual_value].must_equal 'apple'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should return the expected value" do
|
43
|
+
@result[:name][:expected_value].must_equal 'orange'
|
36
44
|
end
|
37
45
|
end
|
38
46
|
end
|
@@ -71,7 +79,7 @@ describe Contrast::Detective do
|
|
71
79
|
end
|
72
80
|
|
73
81
|
it "should return the field" do
|
74
|
-
@result[0].must_equal :first_name
|
82
|
+
@result.keys[0].must_equal :first_name
|
75
83
|
end
|
76
84
|
end
|
77
85
|
|
@@ -91,7 +99,7 @@ describe Contrast::Detective do
|
|
91
99
|
end
|
92
100
|
|
93
101
|
it "should return the field" do
|
94
|
-
@result[0].must_equal :last_name
|
102
|
+
@result.keys[0].must_equal :last_name
|
95
103
|
end
|
96
104
|
end
|
97
105
|
|
@@ -111,8 +119,8 @@ describe Contrast::Detective do
|
|
111
119
|
end
|
112
120
|
|
113
121
|
it "should return the fields" do
|
114
|
-
@result[0].must_equal :first_name
|
115
|
-
@result[1].must_equal :last_name
|
122
|
+
@result.keys[0].must_equal :first_name
|
123
|
+
@result.keys[1].must_equal :last_name
|
116
124
|
end
|
117
125
|
end
|
118
126
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Contrast::MatchingException do
|
4
|
+
describe "#to_s" do
|
5
|
+
it 'no results: The results did not match, but I cannot tell you why.' do
|
6
|
+
[nil, []]. each do |value|
|
7
|
+
error = Contrast::MatchingException.new
|
8
|
+
error.results = value
|
9
|
+
get_message_for(error).must_equal 'The results did not match, but I cannot tell you why.'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "results: Run them through awesome print" do
|
14
|
+
error = Contrast::MatchingException.new
|
15
|
+
error.results = {:result => nil}
|
16
|
+
error.results.expects(:ai).returns('expected results')
|
17
|
+
get_message_for(error).must_equal 'expected results'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_message_for(error)
|
22
|
+
begin
|
23
|
+
raise error
|
24
|
+
rescue Exception => e
|
25
|
+
return e.message
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contrast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: subtle
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: awesome_print
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: mocha
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +96,7 @@ files:
|
|
80
96
|
- lib/contrast/version.rb
|
81
97
|
- lib/contrast_with.rb
|
82
98
|
- spec/contrast/detective_spec.rb
|
99
|
+
- spec/contrast/matching_exception_spec.rb
|
83
100
|
- spec/contrast_with_spec.rb
|
84
101
|
- spec/spec_helper.rb
|
85
102
|
homepage: ''
|
@@ -108,5 +125,6 @@ specification_version: 3
|
|
108
125
|
summary: Contrast two objects by a defined set of values
|
109
126
|
test_files:
|
110
127
|
- spec/contrast/detective_spec.rb
|
128
|
+
- spec/contrast/matching_exception_spec.rb
|
111
129
|
- spec/contrast_with_spec.rb
|
112
130
|
- spec/spec_helper.rb
|