equatable 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/LICENSE.txt +2 -2
- data/README.md +9 -5
- data/lib/equatable.rb +2 -2
- data/lib/equatable/version.rb +1 -1
- metadata +18 -41
- data/Rakefile +0 -10
- data/equatable.gemspec +0 -34
- data/examples/point.rb +0 -48
- data/spec/equatable/eql_spec.rb +0 -52
- data/spec/equatable/equal_spec.rb +0 -82
- data/spec/equatable/include_spec.rb +0 -174
- data/spec/equatable/subclass_spec.rb +0 -61
- data/spec/spec_helper.rb +0 -45
- data/tasks/console.rake +0 -9
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 260460daef33f12a7c0995243cf628bbd2eb81f9e42f0bf00a7b0d226e91eadf
|
4
|
+
data.tar.gz: f38cd2a3d53cabb2f9fdbaa8c4e446be59aecc08b6121385acf4de2d5c72d116
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b7074a4d0d50f379e5831530ea473745b9a22257d0583d67d974830998f9e85d5418cedb37990ff6e5a1607556626343746025e2e3c937a93e7217b0a662daa
|
7
|
+
data.tar.gz: 9e980c6ee681d0e359200803502f0a17c6be5a655a863cf6fd9de5fea17b2419f71a7eb5b6ccea6c4bcd729327f1d3653bd8f98c60b2a0c0aa39ba3776f03381
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## [v0.7.0] - 2021-04-05
|
4
|
+
|
5
|
+
### Changed
|
6
|
+
* Change gemspec to remove test and rake files to reduce gem size
|
7
|
+
* Change to remove bundler as a dev dependency and relax rspec upper constraint
|
8
|
+
* Change to require Ruby 2.0 or higher
|
9
|
+
|
3
10
|
## [v0.6.1] - 2019-06-26
|
4
11
|
|
5
12
|
### Added
|
@@ -18,6 +25,7 @@
|
|
18
25
|
|
19
26
|
* Initial implementation and release
|
20
27
|
|
28
|
+
[v0.7.0]: https://github.com/piotrmurach/equatable/compare/v0.6.1...v0.7.0
|
21
29
|
[v0.6.1]: https://github.com/piotrmurach/equatable/compare/v0.6.0...v0.6.1
|
22
30
|
[v0.6.0]: https://github.com/piotrmurach/equatable/compare/v0.5.0...v0.6.0
|
23
31
|
[v0.5.0]: https://github.com/piotrmurach/equatable/compare/v0.4.0...v0.5.0
|
data/LICENSE.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2012 Piotr Murach
|
1
|
+
Copyright (c) 2012 Piotr Murach (piotrmurach.com)
|
2
2
|
|
3
3
|
MIT License
|
4
4
|
|
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
# Equatable
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/equatable.svg)][gem]
|
4
|
-
[![
|
4
|
+
[![Actions CI](https://github.com/piotrmurach/equatable/workflows/CI/badge.svg?branch=master)][gh_actions_ci]
|
5
5
|
[![Build status](https://ci.appveyor.com/api/projects/status/lsb02nm0g4c6guiu?svg=true)][appveyor]
|
6
6
|
[![Code Climate](https://codeclimate.com/github/piotrmurach/equatable/badges/gpa.svg)][codeclimate]
|
7
7
|
[![Coverage Status](https://coveralls.io/repos/github/piotrmurach/equatable/badge.svg)][coverage]
|
8
8
|
[![Inline docs](http://inch-ci.org/github/piotrmurach/equatable.svg?branch=master)][inchpages]
|
9
9
|
|
10
10
|
[gem]: http://badge.fury.io/rb/equatable
|
11
|
-
[
|
11
|
+
[gh_actions_ci]: https://github.com/piotrmurach/equatable/actions?query=workflow%3ACI
|
12
12
|
[appveyor]: https://ci.appveyor.com/project/piotrmurach/equatable
|
13
13
|
[codeclimate]: https://codeclimate.com/github/piotrmurach/equatable
|
14
14
|
[coverage]: https://coveralls.io/github/piotrmurach/equatable
|
15
15
|
[inchpages]: http://inch-ci.org/github/piotrmurach/equatable
|
16
16
|
|
17
|
-
|
17
|
+
> Provide equality comparison methods for objects based on their attributes.
|
18
18
|
|
19
|
-
By including this module, a class indicates that its instances have explicit general contracts for `
|
19
|
+
By including this module, a class indicates that its instances have explicit general contracts for `==`, `eql?` and `hash` methods. Specifically the `eql?` contract requires that it implements an equivalence relation. By default, each instance of a class is equal only to itself. This is the right behaviour when you have distinct objects. However, it is the responsibility of any class to clearly define its equality. Failure to do so may prevent instances from behaving as expected when tested for uniqueness in Array#uniq or when used as Hash keys.
|
20
20
|
|
21
21
|
## Installation
|
22
22
|
|
23
23
|
Add this line to your application's Gemfile:
|
24
24
|
|
25
|
-
gem
|
25
|
+
gem "equatable"
|
26
26
|
|
27
27
|
And then execute:
|
28
28
|
|
@@ -103,6 +103,10 @@ The `ColorPoint` class demonstrates that extending a class with extra value prop
|
|
103
103
|
4. Push to the branch (`git push origin my-new-feature`)
|
104
104
|
5. Create new Pull Request
|
105
105
|
|
106
|
+
## Code of Conduct
|
107
|
+
|
108
|
+
Everyone interacting in the Equatable project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/piotrmurach/equatable/blob/master/CODE_OF_CONDUCT.md).
|
109
|
+
|
106
110
|
## Copyright
|
107
111
|
|
108
112
|
Copyright (c) 2012 Piotr Murach. See LICENSE for further details.
|
data/lib/equatable.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "equatable/version"
|
4
4
|
|
5
5
|
# Make it easy to define equality and hash methods.
|
6
6
|
module Equatable
|
@@ -72,7 +72,7 @@ module Equatable
|
|
72
72
|
#
|
73
73
|
# @api private
|
74
74
|
def define_comparison_attrs
|
75
|
-
instance_variable_set(
|
75
|
+
instance_variable_set("@comparison_attrs", [])
|
76
76
|
end
|
77
77
|
|
78
78
|
# Define a #compare? method to check if the receiver is the same
|
data/lib/equatable/version.rb
CHANGED
metadata
CHANGED
@@ -1,82 +1,59 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: equatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Murach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '3.1'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '3.1'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
31
|
- - ">="
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
33
|
+
version: '3.0'
|
48
34
|
type: :development
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
38
|
- - ">="
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
description:
|
56
|
-
|
57
|
-
contracts for `hash`, `==` and `eql?` methods.
|
40
|
+
version: '3.0'
|
41
|
+
description: Provide equality comparison methods for objects based on their attributes
|
42
|
+
by generating implementations for the ==, eql?, hash and inspect methods.
|
58
43
|
email:
|
59
|
-
-
|
44
|
+
- piotr@piotrmurach.com
|
60
45
|
executables: []
|
61
46
|
extensions: []
|
62
|
-
extra_rdoc_files:
|
47
|
+
extra_rdoc_files:
|
48
|
+
- README.md
|
49
|
+
- CHANGELOG.md
|
50
|
+
- LICENSE.txt
|
63
51
|
files:
|
64
52
|
- CHANGELOG.md
|
65
53
|
- LICENSE.txt
|
66
54
|
- README.md
|
67
|
-
- Rakefile
|
68
|
-
- equatable.gemspec
|
69
|
-
- examples/point.rb
|
70
55
|
- lib/equatable.rb
|
71
56
|
- lib/equatable/version.rb
|
72
|
-
- spec/equatable/eql_spec.rb
|
73
|
-
- spec/equatable/equal_spec.rb
|
74
|
-
- spec/equatable/include_spec.rb
|
75
|
-
- spec/equatable/subclass_spec.rb
|
76
|
-
- spec/spec_helper.rb
|
77
|
-
- tasks/console.rake
|
78
|
-
- tasks/coverage.rake
|
79
|
-
- tasks/spec.rake
|
80
57
|
homepage: https://github.com/piotrmurach/equatable
|
81
58
|
licenses:
|
82
59
|
- MIT
|
@@ -84,7 +61,7 @@ metadata:
|
|
84
61
|
allowed_push_host: https://rubygems.org
|
85
62
|
bug_tracker_uri: https://github.com/piotrmurach/equatable/issues
|
86
63
|
changelog_uri: https://github.com/piotrmurach/equatable/blob/master/CHANGELOG.md
|
87
|
-
documentation_uri: https://www.rubydoc.info/
|
64
|
+
documentation_uri: https://www.rubydoc.info/github/piotrmurach/equatable
|
88
65
|
homepage_uri: https://github.com/piotrmurach/equatable
|
89
66
|
source_code_uri: https://github.com/piotrmurach/equatable
|
90
67
|
post_install_message:
|
@@ -95,15 +72,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
72
|
requirements:
|
96
73
|
- - ">="
|
97
74
|
- !ruby/object:Gem::Version
|
98
|
-
version:
|
75
|
+
version: 2.0.0
|
99
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
77
|
requirements:
|
101
78
|
- - ">="
|
102
79
|
- !ruby/object:Gem::Version
|
103
80
|
version: '0'
|
104
81
|
requirements: []
|
105
|
-
rubygems_version: 3.
|
82
|
+
rubygems_version: 3.1.2
|
106
83
|
signing_key:
|
107
84
|
specification_version: 4
|
108
|
-
summary:
|
85
|
+
summary: Provide equality comparison methods for objects based on their attributes.
|
109
86
|
test_files: []
|
data/Rakefile
DELETED
data/equatable.gemspec
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
lib = File.expand_path('../lib', __FILE__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require 'equatable/version'
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "equatable"
|
7
|
-
spec.version = Equatable::VERSION
|
8
|
-
spec.authors = ["Piotr Murach"]
|
9
|
-
spec.email = ["me@piotrmurach.com"]
|
10
|
-
spec.summary = %q{Extends Ruby objects with equality comparison and inspection methods.}
|
11
|
-
spec.description = %q{Extends Ruby objects with equality comparison and inspection methods. By including this module, a class indicates that its instances have explicit general contracts for `hash`, `==` and `eql?` methods.}
|
12
|
-
spec.homepage = "https://github.com/piotrmurach/equatable"
|
13
|
-
spec.license = "MIT"
|
14
|
-
if spec.respond_to?(:metadata=)
|
15
|
-
spec.metadata = {
|
16
|
-
"allowed_push_host" => "https://rubygems.org",
|
17
|
-
"bug_tracker_uri" => "#{spec.homepage}/issues",
|
18
|
-
"changelog_uri" => "#{spec.homepage}/blob/master/CHANGELOG.md",
|
19
|
-
"documentation_uri" => "https://www.rubydoc.info/gems/equatable",
|
20
|
-
"homepage_uri" => spec.homepage,
|
21
|
-
"source_code_uri" => spec.homepage
|
22
|
-
}
|
23
|
-
end
|
24
|
-
spec.files = Dir['{lib,spec,examples}/**/*.rb']
|
25
|
-
spec.files += Dir['tasks/*', 'equatable.gemspec']
|
26
|
-
spec.files += Dir['README.md', 'CHANGELOG.md', 'LICENSE.txt', 'Rakefile']
|
27
|
-
spec.require_paths = ["lib"]
|
28
|
-
|
29
|
-
spec.required_ruby_version = '>= 1.8.7'
|
30
|
-
|
31
|
-
spec.add_development_dependency 'bundler', '>= 1.5.0'
|
32
|
-
spec.add_development_dependency 'rspec', '~> 3.1'
|
33
|
-
spec.add_development_dependency 'rake'
|
34
|
-
end
|
data/examples/point.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__), '../lib')
|
2
|
-
|
3
|
-
require 'equatable'
|
4
|
-
|
5
|
-
class Point
|
6
|
-
include Equatable
|
7
|
-
|
8
|
-
attr_reader :x, :y
|
9
|
-
|
10
|
-
def initialize(x, y)
|
11
|
-
@x, @y = x, y
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class ColorPoint < Point
|
16
|
-
attr_reader :color
|
17
|
-
|
18
|
-
def initialize(x, y, color)
|
19
|
-
super(x, y)
|
20
|
-
@color = color
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
point_1 = Point.new(1, 1)
|
25
|
-
point_2 = Point.new(1, 1)
|
26
|
-
point_3 = Point.new(2, 1)
|
27
|
-
|
28
|
-
puts point_1 == point_2
|
29
|
-
puts point_1.hash == point_2.hash
|
30
|
-
puts point_1.eql?(point_2)
|
31
|
-
puts point_1.equal?(point_2)
|
32
|
-
|
33
|
-
puts point_1 == point_3
|
34
|
-
puts point_1.hash == point_3.hash
|
35
|
-
puts point_1.eql?(point_3)
|
36
|
-
puts point_1.equal?(point_3)
|
37
|
-
|
38
|
-
puts point_1.inspect
|
39
|
-
|
40
|
-
point = Point.new(1, 1)
|
41
|
-
color_point = ColorPoint.new(1, 1, :red)
|
42
|
-
|
43
|
-
puts 'Subtypes'
|
44
|
-
puts point == color_point
|
45
|
-
puts color_point == point
|
46
|
-
puts point.hash == color_point.hash
|
47
|
-
puts point.eql?(color_point)
|
48
|
-
puts point.equal?(color_point)
|
data/spec/equatable/eql_spec.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Equatable, '#eql?' do
|
4
|
-
let(:name) { 'Value' }
|
5
|
-
let(:value) { 11 }
|
6
|
-
|
7
|
-
let(:klass) {
|
8
|
-
::Class.new do
|
9
|
-
include Equatable
|
10
|
-
|
11
|
-
attr_reader :value
|
12
|
-
|
13
|
-
def initialize(value)
|
14
|
-
@value = value
|
15
|
-
end
|
16
|
-
end
|
17
|
-
}
|
18
|
-
|
19
|
-
let(:object) { klass.new(value) }
|
20
|
-
|
21
|
-
subject { object.eql?(other) }
|
22
|
-
|
23
|
-
context 'with the same object' do
|
24
|
-
let(:other) { object }
|
25
|
-
|
26
|
-
it { is_expected.to eql(true) }
|
27
|
-
|
28
|
-
it 'is symmetric' do
|
29
|
-
is_expected.to eql(other.eql?(object))
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'with an equivalent object' do
|
34
|
-
let(:other) { object.dup }
|
35
|
-
|
36
|
-
it { is_expected.to eql(true) }
|
37
|
-
|
38
|
-
it 'is symmetric' do
|
39
|
-
is_expected.to eql(other.eql?(object))
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context 'with an equivalent object of a subclass' do
|
44
|
-
let(:other) { ::Class.new(klass).new(value) }
|
45
|
-
|
46
|
-
it { is_expected.to eql(false) }
|
47
|
-
|
48
|
-
it 'is symmetric' do
|
49
|
-
is_expected.to eql(other.eql?(object))
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Equatable, '#==' do
|
4
|
-
let(:name) { 'Value' }
|
5
|
-
let(:value) { 11 }
|
6
|
-
|
7
|
-
let(:super_klass) {
|
8
|
-
::Class.new do
|
9
|
-
include Equatable
|
10
|
-
|
11
|
-
attr_reader :value
|
12
|
-
|
13
|
-
def initialize(value)
|
14
|
-
@value = value
|
15
|
-
end
|
16
|
-
end
|
17
|
-
}
|
18
|
-
|
19
|
-
let(:klass) { Class.new(super_klass) }
|
20
|
-
|
21
|
-
let(:object) { klass.new(value) }
|
22
|
-
|
23
|
-
subject { object == other }
|
24
|
-
|
25
|
-
context 'with the same object' do
|
26
|
-
let(:other) { object }
|
27
|
-
|
28
|
-
it { is_expected.to eql(true) }
|
29
|
-
|
30
|
-
it 'is symmetric' do
|
31
|
-
is_expected.to eql(other == object)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'with an equivalent object' do
|
36
|
-
let(:other) { object.dup }
|
37
|
-
|
38
|
-
it { is_expected.to eql(true) }
|
39
|
-
|
40
|
-
it 'is symmetric' do
|
41
|
-
is_expected.to eql(other == object)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'with an equivalent object of a subclass' do
|
46
|
-
let(:other) { ::Class.new(klass).new(value) }
|
47
|
-
|
48
|
-
it { is_expected.to eql(true) }
|
49
|
-
|
50
|
-
it 'is not symmetric' do
|
51
|
-
# LSP, any equality for type should work for subtype but
|
52
|
-
# not the other way
|
53
|
-
is_expected.not_to eql(other == object)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context 'with an equivalent object of a superclass' do
|
58
|
-
let(:other) { super_klass.new(value) }
|
59
|
-
|
60
|
-
it { is_expected.to eql(false) }
|
61
|
-
|
62
|
-
it 'is not symmetric' do
|
63
|
-
is_expected.not_to eql(other == object)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'with an object with a different interface' do
|
68
|
-
let(:other) { Object.new }
|
69
|
-
|
70
|
-
it { is_expected.to eql(false) }
|
71
|
-
end
|
72
|
-
|
73
|
-
context 'with an object of another class' do
|
74
|
-
let(:other) { Class.new.new }
|
75
|
-
|
76
|
-
it { is_expected.to eql(false) }
|
77
|
-
|
78
|
-
it 'is symmetric' do
|
79
|
-
is_expected.to eql(other == object)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
@@ -1,174 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Equatable, '#include' do
|
4
|
-
let(:name) { 'Value' }
|
5
|
-
let(:object) { described_class }
|
6
|
-
|
7
|
-
context 'without attributes' do
|
8
|
-
let(:klass) { ::Class.new }
|
9
|
-
|
10
|
-
subject { klass.new }
|
11
|
-
|
12
|
-
before {
|
13
|
-
allow(klass).to receive(:name).and_return(name)
|
14
|
-
klass.send(:include, object)
|
15
|
-
}
|
16
|
-
|
17
|
-
it { is_expected.to respond_to(:compare?) }
|
18
|
-
|
19
|
-
it { is_expected.to be_instance_of(klass) }
|
20
|
-
|
21
|
-
it 'has no attribute names' do
|
22
|
-
expect(klass.comparison_attrs).to eq([])
|
23
|
-
end
|
24
|
-
|
25
|
-
describe '#inspect' do
|
26
|
-
it { expect(subject.inspect).to eql('#<Value>') }
|
27
|
-
end
|
28
|
-
|
29
|
-
describe '#hash' do
|
30
|
-
it { expect(subject.hash).to eql([klass].hash) }
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#eql?' do
|
34
|
-
context 'when objects are similar' do
|
35
|
-
let(:other) { subject.dup }
|
36
|
-
|
37
|
-
it { expect(subject.eql?(other)).to eql(true) }
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'when objects are different' do
|
41
|
-
let(:other) { double('other') }
|
42
|
-
|
43
|
-
it { expect(subject.eql?(other)).to eql(false) }
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe '#==' do
|
48
|
-
context 'when objects are similar' do
|
49
|
-
let(:other) { subject.dup }
|
50
|
-
|
51
|
-
it { expect(subject == other).to eql(true) }
|
52
|
-
end
|
53
|
-
|
54
|
-
context 'when objects are different' do
|
55
|
-
let(:other) { double('other') }
|
56
|
-
|
57
|
-
it { expect(subject == other).to eql(false) }
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context 'equivalence relation' do
|
62
|
-
let(:other) { subject.dup }
|
63
|
-
let(:another) { other.dup }
|
64
|
-
|
65
|
-
it 'is not equal to nil reference' do
|
66
|
-
expect(subject.eql?(nil)).to eql(false)
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'is reflexive' do
|
70
|
-
expect(subject.eql?(subject)).to eql(true)
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'is symmetric' do
|
74
|
-
expect(subject.eql?(other)).to eql( other.eql?(subject) )
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'is transitive' do
|
78
|
-
expect(subject.eql?(other) && other.eql?(another)).to eql(subject.eql?(another))
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context 'with attributes' do
|
84
|
-
let(:value) { 11 }
|
85
|
-
let(:klass) {
|
86
|
-
::Class.new do
|
87
|
-
include Equatable
|
88
|
-
|
89
|
-
attr_reader :value
|
90
|
-
|
91
|
-
def initialize(value)
|
92
|
-
@value = value
|
93
|
-
end
|
94
|
-
end
|
95
|
-
}
|
96
|
-
|
97
|
-
before { allow(klass).to receive(:name).and_return(name) }
|
98
|
-
|
99
|
-
subject { klass.new(value) }
|
100
|
-
|
101
|
-
it 'dynamically defines #hash method' do
|
102
|
-
expect(klass.method_defined?(:hash)).to eql(true)
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'dynamically defines #inspect method' do
|
106
|
-
expect(klass.method_defined?(:inspect)).to eql(true)
|
107
|
-
end
|
108
|
-
|
109
|
-
it { is_expected.to respond_to(:compare?) }
|
110
|
-
|
111
|
-
it { is_expected.to respond_to(:eql?) }
|
112
|
-
|
113
|
-
it 'has comparison attribute names' do
|
114
|
-
expect(klass.comparison_attrs).to eq([:value])
|
115
|
-
end
|
116
|
-
|
117
|
-
describe '#eql?' do
|
118
|
-
context 'when objects are similar' do
|
119
|
-
let(:other) { subject.dup }
|
120
|
-
|
121
|
-
it { expect(subject.eql?(other)).to eql(true) }
|
122
|
-
end
|
123
|
-
|
124
|
-
context 'when objects are different' do
|
125
|
-
let(:other) { double('other') }
|
126
|
-
|
127
|
-
it { expect(subject.eql?(other)).to eql(false) }
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe '#==' do
|
132
|
-
context 'when objects are similar' do
|
133
|
-
let(:other) { subject.dup }
|
134
|
-
|
135
|
-
it { expect(subject == other).to eql(true) }
|
136
|
-
end
|
137
|
-
|
138
|
-
context 'when objects are different' do
|
139
|
-
let(:other) { double('other') }
|
140
|
-
|
141
|
-
it { expect(subject == other).to eql(false) }
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
describe '#inspect' do
|
146
|
-
it { expect(subject.inspect).to eql('#<Value value=11>') }
|
147
|
-
end
|
148
|
-
|
149
|
-
describe '#hash' do
|
150
|
-
it { expect(subject.hash).to eql( ([klass] + [value]).hash) }
|
151
|
-
end
|
152
|
-
|
153
|
-
context 'equivalence relation' do
|
154
|
-
let(:other) { subject.dup }
|
155
|
-
let(:another) { other.dup }
|
156
|
-
|
157
|
-
it 'is not equal to nil reference' do
|
158
|
-
expect(subject.eql?(nil)).to eql(false)
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'is reflexive' do
|
162
|
-
expect(subject.eql?(subject)).to eql(true)
|
163
|
-
end
|
164
|
-
|
165
|
-
it 'is symmetric' do
|
166
|
-
expect(subject.eql?(other)).to eql( other.eql?(subject) )
|
167
|
-
end
|
168
|
-
|
169
|
-
it 'is transitive' do
|
170
|
-
expect(subject.eql?(other) && other.eql?(another)).to eql(subject.eql?(another))
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Equatable, 'subclass' do
|
4
|
-
let(:name) { 'Value' }
|
5
|
-
|
6
|
-
context 'when subclass' do
|
7
|
-
let(:value) { 11 }
|
8
|
-
let(:klass) {
|
9
|
-
::Class.new do
|
10
|
-
include Equatable
|
11
|
-
|
12
|
-
attr_reader :value
|
13
|
-
|
14
|
-
def initialize(value)
|
15
|
-
@value = value
|
16
|
-
end
|
17
|
-
end
|
18
|
-
}
|
19
|
-
let(:subclass) { ::Class.new(klass) }
|
20
|
-
|
21
|
-
subject { subclass.new(value) }
|
22
|
-
|
23
|
-
before { allow(klass).to receive(:name).and_return(name) }
|
24
|
-
|
25
|
-
it { expect(subclass.superclass).to eq(klass) }
|
26
|
-
|
27
|
-
it { is_expected.to respond_to(:value) }
|
28
|
-
|
29
|
-
describe '#inspect' do
|
30
|
-
it { expect(subject.inspect).to eql('#<Value value=11>') }
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#eql?' do
|
34
|
-
context 'when objects are similar' do
|
35
|
-
let(:other) { subject.dup }
|
36
|
-
|
37
|
-
it { expect(subject.eql?(other)).to eql(true) }
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'when objects are different' do
|
41
|
-
let(:other) { double('other') }
|
42
|
-
|
43
|
-
it { expect(subject.eql?(other)).to eql(false) }
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe '#==' do
|
48
|
-
context 'when objects are similar' do
|
49
|
-
let(:other) { subject.dup }
|
50
|
-
|
51
|
-
it { expect(subject == other).to eql(true) }
|
52
|
-
end
|
53
|
-
|
54
|
-
context 'when objects are different' do
|
55
|
-
let(:other) { double('other') }
|
56
|
-
|
57
|
-
it { expect(subject == other).to eql(false) }
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
if RUBY_VERSION > '1.9' and (ENV['COVERAGE'] || ENV['TRAVIS'])
|
4
|
-
require 'simplecov'
|
5
|
-
require 'coveralls'
|
6
|
-
|
7
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
8
|
-
SimpleCov::Formatter::HTMLFormatter,
|
9
|
-
Coveralls::SimpleCov::Formatter
|
10
|
-
]
|
11
|
-
|
12
|
-
SimpleCov.start do
|
13
|
-
command_name 'spec'
|
14
|
-
add_filter 'spec'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
require 'equatable'
|
19
|
-
|
20
|
-
RSpec.configure do |config|
|
21
|
-
config.expect_with :rspec do |expectations|
|
22
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
23
|
-
end
|
24
|
-
|
25
|
-
config.mock_with :rspec do |mocks|
|
26
|
-
mocks.verify_partial_doubles = true
|
27
|
-
end
|
28
|
-
|
29
|
-
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
30
|
-
config.disable_monkey_patching!
|
31
|
-
|
32
|
-
# This setting enables warnings. It's recommended, but in some cases may
|
33
|
-
# be too noisy due to issues in dependencies.
|
34
|
-
config.warnings = true
|
35
|
-
|
36
|
-
if config.files_to_run.one?
|
37
|
-
config.default_formatter = 'doc'
|
38
|
-
end
|
39
|
-
|
40
|
-
config.profile_examples = 2
|
41
|
-
|
42
|
-
config.order = :random
|
43
|
-
|
44
|
-
Kernel.srand config.seed
|
45
|
-
end
|
data/tasks/console.rake
DELETED
data/tasks/coverage.rake
DELETED