contrast 1.0.0 → 1.1.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
@@ -8,7 +8,7 @@ gem 'subtle'
8
8
  gem 'awesome_print'
9
9
 
10
10
  group :development do
11
- gem 'minitest'
11
+ gem 'minitest', '3.5.0'
12
12
  gem 'mocha'
13
13
  gem 'guard'
14
14
  gem 'guard-minitest', :git => 'git://github.com/aspiers/guard-minitest.git'
data/README.md CHANGED
@@ -41,3 +41,9 @@ john.contrast_with { first_name: 'Dagny', gender: 'f' }, [:gender]
41
41
  # {:gender=>{:actual_value=>"m", :expected_value=>"f"}}
42
42
  ````
43
43
 
44
+ If you pass a hash to contrast_with, it will use the keys in the hash if a list of fields is not supplied.
45
+
46
+ ````ruby
47
+ john.contrast_with { first_name: 'Dagny', gender: 'f' }
48
+ # {:gender=>{:actual_value=>"m", :expected_value=>"f"}}
49
+ ````
@@ -1,3 +1,3 @@
1
1
  module Contrast
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -1,10 +1,10 @@
1
1
  class Object
2
- def contrast_with(other, fields)
2
+ def contrast_with(other, fields = other.keys)
3
3
  detective = Contrast::Detective.new(*fields)
4
4
  detective.examine(self, other)
5
5
  end
6
6
 
7
- def contrast_with!(other, fields)
7
+ def contrast_with!(other, fields = other.keys)
8
8
  results = self.contrast_with(other, fields)
9
9
  raise Contrast::MatchingException.new(results) if results.any?
10
10
  end
@@ -119,8 +119,8 @@ describe Contrast::Detective do
119
119
  end
120
120
 
121
121
  it "should return the fields" do
122
- @result.keys[0].must_equal :first_name
123
- @result.keys[1].must_equal :last_name
122
+ @result.keys.include?(:first_name).must_equal true
123
+ @result.keys.include?(:last_name).must_equal true
124
124
  end
125
125
  end
126
126
 
@@ -105,5 +105,24 @@ describe "examples" do
105
105
  rescue
106
106
  end
107
107
  end
108
+
109
+ it "should use the keys of the argument if it is a hash" do
110
+ fields = [:first_name, :last_name, :city, :state, :zip]
111
+ first = { :first_name => 'a',
112
+ :last_name => 'b',
113
+ :city => 'c',
114
+ :state => 'd',
115
+ :zip => 'e' }
116
+ second = { :first_name => 'z',
117
+ :last_name => 'b',
118
+ :city => 'c',
119
+ :state => 'd',
120
+ :zip => 'e' }
121
+
122
+ first.contrast_with(second).count.must_equal 1
123
+ first.contrast_with({ :first_name => 'a' }).count.must_equal 0
124
+ first.contrast_with({ :last_name => 'b' }).count.must_equal 0
125
+ first.contrast_with({ :last_name => 'c' }).count.must_equal 1
126
+ end
108
127
 
109
128
  end
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: 1.0.0
4
+ version: 1.1.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-17 00:00:00.000000000 Z
12
+ date: 2012-11-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: subtle
@@ -113,18 +113,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
113
  - - ! '>='
114
114
  - !ruby/object:Gem::Version
115
115
  version: '0'
116
- segments:
117
- - 0
118
- hash: -1837560623878563679
119
116
  required_rubygems_version: !ruby/object:Gem::Requirement
120
117
  none: false
121
118
  requirements:
122
119
  - - ! '>='
123
120
  - !ruby/object:Gem::Version
124
121
  version: '0'
125
- segments:
126
- - 0
127
- hash: -1837560623878563679
128
122
  requirements: []
129
123
  rubyforge_project:
130
124
  rubygems_version: 1.8.24