crimp 0.1.1 → 0.1.2
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 +4 -4
- data/Guardfile +2 -2
- data/Rakefile +2 -2
- data/lib/crimp.rb +4 -4
- data/lib/crimp/version.rb +1 -1
- data/spec/consistency_spec.rb +9 -9
- data/spec/crimp_spec.rb +56 -36
- data/spec/spec_helper.rb +1 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f951279d5308025d1f3184b1a823a1577d13ebad
|
4
|
+
data.tar.gz: 9444429cbc53f722f053815ced9db784e29a5374
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f91307d9094be916d32b3e95ca5c620db68979ec5d3eb465efaa2e0876df96543d51a43fad76331d20f04baa34ed254ab355587886ad66db7453badff1afcf3b
|
7
|
+
data.tar.gz: 092f330b087472fd4ebda5653ccb6ba86857597d205e71d15636562fd2ec2b2626cce2598b733d74acd7a7a637796148526f43d91e0bb569a67aee494ea3c98b
|
data/Guardfile
CHANGED
data/Rakefile
CHANGED
data/lib/crimp.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'crimp/version'
|
2
|
+
require 'digest'
|
3
3
|
|
4
4
|
module Crimp
|
5
5
|
def self.signature(obj)
|
@@ -36,7 +36,7 @@ module Crimp
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def self.parse_array(array)
|
39
|
-
array.map
|
39
|
+
array.map { |e| stringify(e) }.sort
|
40
40
|
end
|
41
41
|
|
42
42
|
def self.parse_hash(hash)
|
@@ -44,6 +44,6 @@ module Crimp
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def self.to_string(obj)
|
47
|
-
"#{obj
|
47
|
+
"#{obj}#{obj.class}"
|
48
48
|
end
|
49
49
|
end
|
data/lib/crimp/version.rb
CHANGED
data/spec/consistency_spec.rb
CHANGED
@@ -6,38 +6,38 @@ describe Crimp do
|
|
6
6
|
context 'given a Hash' do
|
7
7
|
let(:hash) do
|
8
8
|
{
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
9
|
+
a: 123,
|
10
|
+
b: 1.23,
|
11
|
+
c: 'string',
|
12
|
+
d: :sym
|
13
13
|
}
|
14
14
|
end
|
15
15
|
let(:md5) { '1dd744d51279187cc08cabe240f98be2' }
|
16
16
|
|
17
|
-
specify { expect(subject.signature
|
17
|
+
specify { expect(subject.signature(hash)).to eq md5 }
|
18
18
|
end
|
19
19
|
|
20
20
|
context 'given legacy Hash' do
|
21
21
|
let(:hash) do
|
22
|
-
{:
|
22
|
+
{ a: { b: 'b', c: 'c' }, d: 'd' }
|
23
23
|
end
|
24
24
|
let(:md5) { '68d07febc4f47f56fa6ef5de063a77b1' }
|
25
25
|
|
26
|
-
specify { expect(subject.signature
|
26
|
+
specify { expect(subject.signature(hash)).to eq md5 }
|
27
27
|
end
|
28
28
|
|
29
29
|
context 'given an Array' do
|
30
30
|
let(:array) { [123, 1.23, 'string', :sym] }
|
31
31
|
let(:md5) { 'cd29980f258eef3faceca4f4da02ec65' }
|
32
32
|
|
33
|
-
specify { expect(subject.signature
|
33
|
+
specify { expect(subject.signature(array)).to eq md5 }
|
34
34
|
end
|
35
35
|
|
36
36
|
context 'given legacy Array' do
|
37
37
|
let(:array) { [1, 2, 3, [4, [5, 6]]] }
|
38
38
|
let(:md5) { '4dc4e1161c9315db0bc43c0201b3ec05' }
|
39
39
|
|
40
|
-
specify { expect(subject.signature
|
40
|
+
specify { expect(subject.signature(array)).to eq md5 }
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
data/spec/crimp_spec.rb
CHANGED
@@ -1,59 +1,79 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Crimp do
|
4
|
-
let (:hash) { {:
|
5
|
-
let (:hash_unordered) { {:
|
4
|
+
let (:hash) { { a: { b: 'b', c: 'c' }, d: 'd' } }
|
5
|
+
let (:hash_unordered) { { d: 'd', a: { c: 'c', b: 'b' } } }
|
6
6
|
let (:array) { [1, 2, 3, [4, [5, 6]]] }
|
7
7
|
let (:array_unordered) { [3, 2, 1, [[5, 6], 4]] }
|
8
8
|
|
9
|
-
describe
|
10
|
-
context
|
11
|
-
specify { expect(subject.signature
|
9
|
+
describe '.signature' do
|
10
|
+
context 'given a Hash' do
|
11
|
+
specify { expect(subject.signature(hash)).to be_a String }
|
12
12
|
|
13
|
-
it
|
14
|
-
expect(
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
it 'returns MD5 hash of stringified Hash' do
|
14
|
+
expect(subject.signature(hash)).to eq(Digest::MD5.hexdigest(subject.stringify(hash)))
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'does not modify original hash' do
|
18
|
+
original_hash = { d: 'd', a: { c: 'c', b: 'b' } }
|
19
|
+
expected_hash = { d: 'd', a: { c: 'c', b: 'b' } }
|
20
|
+
|
21
|
+
subject.signature(original_hash)
|
22
|
+
|
23
|
+
expect(original_hash).to eq(expected_hash)
|
19
24
|
end
|
20
25
|
end
|
21
26
|
|
22
|
-
context
|
23
|
-
specify { expect(subject.signature
|
27
|
+
context 'given an Array' do
|
28
|
+
specify { expect(subject.signature(array)).to be_a String }
|
29
|
+
|
30
|
+
it 'returns MD5 hash of stringified Array' do
|
31
|
+
expect(subject.signature(array)).to eq(Digest::MD5.hexdigest(subject.stringify(array)))
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'does not modify original array' do
|
35
|
+
original_array = [5, 4, 2, 6, [5, 7, 2]]
|
36
|
+
expected_array = [5, 4, 2, 6, [5, 7, 2]]
|
37
|
+
|
38
|
+
subject.signature(original_array)
|
24
39
|
|
25
|
-
|
26
|
-
expect(
|
27
|
-
subject.signature(array)
|
28
|
-
).to eq(
|
29
|
-
Digest::MD5.hexdigest(subject.stringify(array))
|
30
|
-
)
|
40
|
+
expect(original_array).to eq(expected_array)
|
31
41
|
end
|
32
42
|
end
|
33
43
|
end
|
34
44
|
|
35
|
-
describe
|
36
|
-
context
|
37
|
-
specify { expect(subject.stringify
|
45
|
+
describe '.stringify' do
|
46
|
+
context 'given a Hash' do
|
47
|
+
specify { expect(subject.stringify(hash)).to be_a String }
|
38
48
|
|
39
|
-
it
|
40
|
-
expect(
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
49
|
+
it 'returns equal strings for differently ordered hashes' do
|
50
|
+
expect(subject.stringify(hash)).to eq(subject.stringify(hash_unordered))
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'does not modify original hash' do
|
54
|
+
original_hash = { d: 'd', a: { c: 'c', b: 'b' } }
|
55
|
+
expected_hash = { d: 'd', a: { c: 'c', b: 'b' } }
|
56
|
+
|
57
|
+
subject.signature(original_hash)
|
58
|
+
|
59
|
+
expect(original_hash).to eq(expected_hash)
|
45
60
|
end
|
46
61
|
end
|
47
62
|
|
48
|
-
context
|
49
|
-
specify { expect(subject.stringify
|
63
|
+
context 'given an Array' do
|
64
|
+
specify { expect(subject.stringify(array)).to be_a String }
|
65
|
+
|
66
|
+
it 'returns equal strings for differently ordered arrays' do
|
67
|
+
expect(subject.stringify(array)).to eq(subject.stringify(array_unordered))
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'does not modify original array' do
|
71
|
+
original_array = [5, 4, 2, 6, [5, 7, 2]]
|
72
|
+
expected_array = [5, 4, 2, 6, [5, 7, 2]]
|
73
|
+
|
74
|
+
subject.signature(original_array)
|
50
75
|
|
51
|
-
|
52
|
-
expect(
|
53
|
-
subject.stringify(array)
|
54
|
-
).to eq(
|
55
|
-
subject.stringify(array_unordered)
|
56
|
-
)
|
76
|
+
expect(original_array).to eq(expected_array)
|
57
77
|
end
|
58
78
|
end
|
59
79
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crimp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BBC News
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|