contrast 0.1.4 → 0.2.0

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.
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ gemspec
5
5
 
6
6
  gem 'rake'
7
7
  gem 'subtle'
8
+ gem 'awesome_print'
8
9
 
9
10
  group :development do
10
11
  gem 'mocha'
data/contrast.gemspec CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Contrast::VERSION
17
17
 
18
18
  gem.add_runtime_dependency 'subtle'
19
+ gem.add_runtime_dependency 'awesome_print'
19
20
  gem.add_development_dependency 'mocha'
20
21
  gem.add_development_dependency 'rake'
21
22
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Contrast
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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
@@ -1,5 +1,5 @@
1
- require 'mocha'
2
- require 'minitest/spec'
3
- require 'minitest/autorun'
4
1
  require './lib/contrast.rb'
5
2
  require 'subtle'
3
+ require 'minitest/spec'
4
+ require 'minitest/autorun'
5
+ require 'mocha'
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.1.4
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-09 00:00:00.000000000 Z
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