hashdiff 1.1.0 → 1.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.
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'README.md' do
6
- it 'has correct examples' do
7
- File.read('README.md').scan(/```ruby(.*?)```/m).flatten(1).each do |block|
8
- begin
9
- eval block # rubocop:disable Security/Eval
10
- rescue Exception => e # rubocop:disable Lint/RescueException
11
- raise "README.md code block:\n#{block}\n\nhas error:\n#{e}"
12
- end
13
- end
14
- end
15
- end
@@ -1,116 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Hashdiff do
6
- it 'is able to decode property path' do
7
- decoded = described_class.send(:decode_property_path, 'a.b[0].c.city[5]')
8
- decoded.should == ['a', 'b', 0, 'c', 'city', 5]
9
- end
10
-
11
- it 'is able to decode property path with custom delimiter' do
12
- decoded = described_class.send(:decode_property_path, "a\tb[0]\tc\tcity[5]", "\t")
13
- decoded.should == ['a', 'b', 0, 'c', 'city', 5]
14
- end
15
-
16
- it 'is able to tell similiar hash' do
17
- a = { 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5 }
18
- b = { 'a' => 1, 'b' => 2, 'c' => 3, 'e' => 5 }
19
- described_class.similar?(a, b).should be true
20
- described_class.similar?(a, b, similarity: 1).should be false
21
- end
22
-
23
- it 'is able to tell similiar empty hash' do
24
- described_class.similar?({}, {}, similarity: 1).should be true
25
- end
26
-
27
- it 'is able to tell similiar empty array' do
28
- described_class.similar?([], [], similarity: 1).should be true
29
- end
30
-
31
- it 'is able to tell similiar hash with values within tolerance' do
32
- a = { 'a' => 1.5, 'b' => 2.25, 'c' => 3, 'd' => 4, 'e' => 5 }
33
- b = { 'a' => 1.503, 'b' => 2.22, 'c' => 3, 'e' => 5 }
34
- described_class.similar?(a, b, numeric_tolerance: 0.05).should be true
35
- described_class.similar?(a, b).should be false
36
- end
37
-
38
- it 'is able to tell numbers and strings' do
39
- described_class.similar?(1, 2).should be false
40
- described_class.similar?('a', 'b').should be false
41
- described_class.similar?('a', [1, 2, 3]).should be false
42
- described_class.similar?(1, 'a' => 1, 'b' => 2, 'c' => 3, 'e' => 5).should be false
43
- end
44
-
45
- it 'is able to tell true when similarity == 0.5' do
46
- a = { 'value' => 'New1', 'onclick' => 'CreateNewDoc()' }
47
- b = { 'value' => 'New', 'onclick' => 'CreateNewDoc()' }
48
-
49
- described_class.similar?(a, b, similarity: 0.5).should be true
50
- end
51
-
52
- it 'is able to tell false when similarity == 0.5' do
53
- a = { 'value' => 'New1', 'onclick' => 'open()' }
54
- b = { 'value' => 'New', 'onclick' => 'CreateNewDoc()' }
55
-
56
- described_class.similar?(a, b, similarity: 0.5).should be false
57
- end
58
-
59
- describe '.compare_values' do
60
- it 'compares numeric values exactly when no tolerance' do
61
- expect(described_class.compare_values(10.004, 10.003)).to be false
62
- end
63
-
64
- it 'allows tolerance with numeric values' do
65
- expect(described_class.compare_values(10.004, 10.003, numeric_tolerance: 0.01)).to be true
66
- end
67
-
68
- it 'compares different objects without tolerance' do
69
- expect(described_class.compare_values('hats', 'ninjas')).to be false
70
- end
71
-
72
- it 'compares other objects with tolerance' do
73
- expect(described_class.compare_values('hats', 'ninjas', numeric_tolerance: 0.01)).to be false
74
- end
75
-
76
- it 'compares same objects without tolerance' do
77
- expect(described_class.compare_values('horse', 'horse')).to be true
78
- end
79
-
80
- it 'compares strings for spaces exactly by default' do
81
- expect(described_class.compare_values(' horse', 'horse')).to be false
82
- end
83
-
84
- it 'compares strings for capitalization exactly by default' do
85
- expect(described_class.compare_values('horse', 'Horse')).to be false
86
- end
87
-
88
- it 'strips strings before comparing when requested' do
89
- expect(described_class.compare_values(' horse', 'horse', strip: true)).to be true
90
- end
91
-
92
- it 'ignores string case when requested' do
93
- expect(described_class.compare_values('horse', 'Horse', case_insensitive: true)).to be true
94
- end
95
- end
96
-
97
- describe '.comparable?' do
98
- it 'identifies hashes as comparable' do
99
- expect(described_class.comparable?({}, {})).to be true
100
- end
101
-
102
- it 'identifies a subclass of Hash to be comparable with a Hash' do
103
- other = Class.new(Hash)
104
- expect(described_class.comparable?(other.new, {})).to be true
105
- end
106
-
107
- it 'identifies a Hash to be comparable with a subclass of Hash' do
108
- other = Class.new(Hash)
109
- expect(described_class.comparable?({}, other.new)).to be true
110
- end
111
-
112
- it 'does not identify a Numeric as comparable with a Hash' do
113
- expect(described_class.comparable?(1, {})).to be false
114
- end
115
- end
116
- end
data/spec/spec_helper.rb DELETED
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
-
5
- require 'rubygems'
6
- require 'rspec'
7
- require 'rspec/autorun'
8
-
9
- require 'hashdiff'
10
-
11
- RSpec.configure do |config|
12
- config.mock_framework = :rspec
13
-
14
- config.include RSpec::Matchers
15
- end