equalizer 0.0.11 → 1.0.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.
- checksums.yaml +5 -5
- data/.mutant.yml +24 -0
- data/.rubocop.yml +28 -0
- data/.yardopts +4 -0
- data/.yardstick.yml +32 -0
- data/CHANGELOG.md +148 -0
- data/LICENSE +18 -18
- data/README.md +300 -58
- data/Rakefile +53 -4
- data/Steepfile +10 -0
- data/lib/equalizer.rb +152 -91
- data/sig/equalizer.rbs +64 -0
- metadata +30 -63
- data/.gitignore +0 -39
- data/.rspec +0 -6
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/.travis.yml +0 -21
- data/Gemfile +0 -9
- data/config/devtools.yml +0 -2
- data/config/flay.yml +0 -4
- data/config/flog.yml +0 -3
- data/config/mutant.yml +0 -2
- data/config/reek.yml +0 -105
- data/config/rubocop.yml +0 -115
- data/config/yardstick.yml +0 -34
- data/equalizer.gemspec +0 -23
- data/lib/equalizer/version.rb +0 -6
- data/spec/spec_helper.rb +0 -31
- data/spec/support/config_alias.rb +0 -5
- data/spec/unit/equalizer/included_spec.rb +0 -50
- data/spec/unit/equalizer/methods/eql_predicate_spec.rb +0 -65
- data/spec/unit/equalizer/methods/equality_operator_spec.rb +0 -128
- data/spec/unit/equalizer/universal_spec.rb +0 -157
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
describe Equalizer, '.new' do
|
|
6
|
-
let(:object) { described_class }
|
|
7
|
-
let(:name) { 'User' }
|
|
8
|
-
let(:klass) { ::Class.new }
|
|
9
|
-
|
|
10
|
-
context 'with no keys' do
|
|
11
|
-
subject { object.new }
|
|
12
|
-
|
|
13
|
-
before do
|
|
14
|
-
# specify the class #name method
|
|
15
|
-
allow(klass).to receive(:name).and_return(name)
|
|
16
|
-
klass.send(:include, subject)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
let(:instance) { klass.new }
|
|
20
|
-
|
|
21
|
-
it { should be_instance_of(object) }
|
|
22
|
-
|
|
23
|
-
it { should be_frozen }
|
|
24
|
-
|
|
25
|
-
it 'defines #hash and #inspect methods dynamically' do
|
|
26
|
-
expect(subject.public_instance_methods(false).map(&:to_s).sort)
|
|
27
|
-
.to eql(%w[hash inspect])
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
describe '#eql?' do
|
|
31
|
-
context 'when the objects are similar' do
|
|
32
|
-
let(:other) { instance.dup }
|
|
33
|
-
|
|
34
|
-
it { expect(instance.eql?(other)).to be(true) }
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
context 'when the objects are different' do
|
|
38
|
-
let(:other) { double('other') }
|
|
39
|
-
|
|
40
|
-
it { expect(instance.eql?(other)).to be(false) }
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
describe '#==' do
|
|
45
|
-
context 'when the objects are similar' do
|
|
46
|
-
let(:other) { instance.dup }
|
|
47
|
-
|
|
48
|
-
it { expect(instance == other).to be(true) }
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
context 'when the objects are different' do
|
|
52
|
-
let(:other) { double('other') }
|
|
53
|
-
|
|
54
|
-
it { expect(instance == other).to be(false) }
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
describe '#hash' do
|
|
59
|
-
it 'has the expected arity' do
|
|
60
|
-
expect(klass.instance_method(:hash).arity).to be(0)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
it { expect(instance.hash).to eql([klass].hash) }
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
describe '#inspect' do
|
|
67
|
-
it 'has the expected arity' do
|
|
68
|
-
expect(klass.instance_method(:inspect).arity).to be(0)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it { expect(instance.inspect).to eql('#<User>') }
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
context 'with keys' do
|
|
76
|
-
subject { object.new(*keys) }
|
|
77
|
-
|
|
78
|
-
let(:keys) { %i[firstname lastname].freeze }
|
|
79
|
-
let(:firstname) { 'John' }
|
|
80
|
-
let(:lastname) { 'Doe' }
|
|
81
|
-
let(:instance) { klass.new(firstname, lastname) }
|
|
82
|
-
|
|
83
|
-
let(:klass) do
|
|
84
|
-
::Class.new do
|
|
85
|
-
attr_reader :firstname, :lastname
|
|
86
|
-
private :firstname, :lastname
|
|
87
|
-
|
|
88
|
-
def initialize(firstname, lastname)
|
|
89
|
-
@firstname, @lastname = firstname, lastname
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
before do
|
|
95
|
-
# specify the class #inspect method
|
|
96
|
-
allow(klass).to receive_messages(name: nil, inspect: name)
|
|
97
|
-
klass.send(:include, subject)
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
it { should be_instance_of(object) }
|
|
101
|
-
|
|
102
|
-
it { should be_frozen }
|
|
103
|
-
|
|
104
|
-
it 'defines #hash and #inspect methods dynamically' do
|
|
105
|
-
expect(subject.public_instance_methods(false).map(&:to_s).sort)
|
|
106
|
-
.to eql(%w[hash inspect])
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
describe '#eql?' do
|
|
110
|
-
context 'when the objects are similar' do
|
|
111
|
-
let(:other) { instance.dup }
|
|
112
|
-
|
|
113
|
-
it { expect(instance.eql?(other)).to be(true) }
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
context 'when the objects are different' do
|
|
117
|
-
let(:other) { double('other') }
|
|
118
|
-
|
|
119
|
-
it { expect(instance.eql?(other)).to be(false) }
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
describe '#==' do
|
|
124
|
-
context 'when the objects are similar' do
|
|
125
|
-
let(:other) { instance.dup }
|
|
126
|
-
|
|
127
|
-
it { expect(instance == other).to be(true) }
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
context 'when the objects are different type' do
|
|
131
|
-
let(:other) { klass.new('Foo', 'Bar') }
|
|
132
|
-
|
|
133
|
-
it { expect(instance == other).to be(false) }
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
context 'when the objects are from different type' do
|
|
137
|
-
let(:other) { double('other') }
|
|
138
|
-
|
|
139
|
-
it { expect(instance == other).to be(false) }
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
describe '#hash' do
|
|
144
|
-
it 'returns the expected hash' do
|
|
145
|
-
expect(instance.hash)
|
|
146
|
-
.to eql([firstname, lastname, klass].hash)
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
describe '#inspect' do
|
|
151
|
-
it 'returns the expected string' do
|
|
152
|
-
expect(instance.inspect)
|
|
153
|
-
.to eql('#<User firstname="John" lastname="Doe">')
|
|
154
|
-
end
|
|
155
|
-
end
|
|
156
|
-
end
|
|
157
|
-
end
|