hashes_equal 0.1.3 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/.travis.yml +0 -1
- data/Makefile +1 -0
- data/hashes_equal.gemspec +1 -1
- data/lib/hashes_equal/enumerable_compare_helper.rb +18 -0
- data/lib/hashes_equal/time_coarsener.rb +88 -0
- data/lib/hashes_equal/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c3f58541f24e3ec2f1a3310fd0e448c3fe2a47be3d2daf91dc3e9c5a0a5f40d
|
4
|
+
data.tar.gz: 4d5946c5a183bc8b3ae0e5e2ebb9fdf3a31c25c8323d29ae936c3508da66e80e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6983a719e59f9ee723d9c947ea4c680ea2814a79fa8041beff585dacd8b00dc18a7b629ce12f1f98fdc7c647ae4321bc120b03708d59de400e3d049edd28a36
|
7
|
+
data.tar.gz: 0a59126f5089b13d038bbf229a8dab8521650d5bfbe119d4c6ed6d8ec0c99f5c826944c1e205ddca64d8c862fff4bd6457a87f0b4425c773c41d3add0267935c
|
data/.rubocop.yml
CHANGED
@@ -3,6 +3,7 @@ require:
|
|
3
3
|
|
4
4
|
AllCops:
|
5
5
|
TargetRubyVersion: 2.6
|
6
|
+
NewCops: enable
|
6
7
|
|
7
8
|
Layout/EmptyLinesAroundAttributeAccessor:
|
8
9
|
Enabled: true
|
@@ -94,6 +95,9 @@ Style/RedundantRegexpEscape:
|
|
94
95
|
Style/SlicingWithRange:
|
95
96
|
Enabled: true
|
96
97
|
|
98
|
+
Style/StringConcatenation:
|
99
|
+
Enabled: false
|
100
|
+
|
97
101
|
# Metrics/ClassLength:
|
98
102
|
# Max: 250
|
99
103
|
|
data/.travis.yml
CHANGED
data/Makefile
CHANGED
data/hashes_equal.gemspec
CHANGED
@@ -46,7 +46,7 @@ Gem::Specification.new do |spec|
|
|
46
46
|
spec.add_development_dependency 'mocha', '~> 1.11'
|
47
47
|
spec.add_development_dependency 'pry', '~> 0.13'
|
48
48
|
spec.add_development_dependency 'rake', '~> 13.0'
|
49
|
-
spec.add_development_dependency 'rubocop', '
|
49
|
+
spec.add_development_dependency 'rubocop', '0.93.1'
|
50
50
|
spec.add_development_dependency 'rubocop-performance', '~> 1.5'
|
51
51
|
spec.add_development_dependency 'simplecov', '~> 0.18.5'
|
52
52
|
end
|
@@ -1,9 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'hashes_equal/enumerable_diff_displayer'
|
4
|
+
require 'hashes_equal/time_coarsener'
|
4
5
|
|
5
6
|
module HashesEqual
|
6
7
|
module EnumerableCompareHelper
|
8
|
+
def assert_time_aware_enumerable_equal(
|
9
|
+
expected,
|
10
|
+
actual,
|
11
|
+
time_granularity:,
|
12
|
+
verbose: true
|
13
|
+
)
|
14
|
+
time_coarsener = TimeCoarsener.new(time_granularity)
|
15
|
+
time_coarsened_expected = time_coarsener.call(expected)
|
16
|
+
time_coarsened_actual = time_coarsener.call(actual)
|
17
|
+
|
18
|
+
assert_enumerable_equal(
|
19
|
+
time_coarsened_expected,
|
20
|
+
time_coarsened_actual,
|
21
|
+
verbose: verbose
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
7
25
|
def assert_enumerable_equal(expected, actual, verbose: true)
|
8
26
|
displayable_diff = EnumerableDiffDisplayer.new(
|
9
27
|
expected: expected,
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ansi'
|
4
|
+
require 'assertable'
|
5
|
+
require 'hashdiff'
|
6
|
+
|
7
|
+
module HashesEqual
|
8
|
+
class TimeCoarsener
|
9
|
+
include Assertable
|
10
|
+
|
11
|
+
class InvalidTimeGranularity < ArgumentError; end
|
12
|
+
|
13
|
+
VALID_TIME_GRANULARITY = %i[
|
14
|
+
sec
|
15
|
+
usec
|
16
|
+
].freeze
|
17
|
+
|
18
|
+
def initialize(time_granularity)
|
19
|
+
@time_granularity = time_granularity
|
20
|
+
assert_send :time_granularity
|
21
|
+
check_valid_granularity_for_time_aware_comparison
|
22
|
+
end
|
23
|
+
|
24
|
+
# Either an enumerable or a Time object
|
25
|
+
def call(object_to_convert)
|
26
|
+
@object_to_convert = object_to_convert
|
27
|
+
assert_send :object_to_convert
|
28
|
+
|
29
|
+
convert_object(object_to_convert)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
attr_reader :object_to_convert, :time_granularity
|
35
|
+
|
36
|
+
def convert_object(object)
|
37
|
+
return convert_hash(object) if object.is_a?(Hash)
|
38
|
+
return convert_enumerable(object) if object.is_a?(Enumerable)
|
39
|
+
return convert_time(object) if object.is_a?(Time)
|
40
|
+
|
41
|
+
object
|
42
|
+
end
|
43
|
+
|
44
|
+
def convert_hash(hash_to_convert)
|
45
|
+
hash_to_convert.transform_values do |value|
|
46
|
+
convert_object(value)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def convert_enumerable(enumerable_to_convert)
|
51
|
+
enumerable_to_convert.map do |value|
|
52
|
+
convert_object value
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def convert_time(time_to_convert)
|
57
|
+
send(coarsening_method_name, time_to_convert)
|
58
|
+
end
|
59
|
+
|
60
|
+
def coarsen_to_sec(time_to_convert)
|
61
|
+
Time.at(
|
62
|
+
time_to_convert.to_i
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
def coarsen_to_usec(time_to_convert)
|
67
|
+
Time.at(
|
68
|
+
time_to_convert.to_i, time_to_convert.usec, :usec
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
def coarsening_method_name
|
73
|
+
"coarsen_to_#{time_granularity}"
|
74
|
+
end
|
75
|
+
|
76
|
+
def check_valid_granularity_for_time_aware_comparison
|
77
|
+
return if VALID_TIME_GRANULARITY.include?(time_granularity.to_sym)
|
78
|
+
|
79
|
+
raise(
|
80
|
+
InvalidTimeGranularity,
|
81
|
+
[
|
82
|
+
"#{time_granularity.inspect} is not a valid time_granularity.",
|
83
|
+
"Valid values are: #{VALID_TIME_GRANULARITY.inspect}"
|
84
|
+
].join(' ')
|
85
|
+
)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/lib/hashes_equal/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashes_equal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shippingbo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ansi
|
@@ -194,16 +194,16 @@ dependencies:
|
|
194
194
|
name: rubocop
|
195
195
|
requirement: !ruby/object:Gem::Requirement
|
196
196
|
requirements:
|
197
|
-
- -
|
197
|
+
- - '='
|
198
198
|
- !ruby/object:Gem::Version
|
199
|
-
version:
|
199
|
+
version: 0.93.1
|
200
200
|
type: :development
|
201
201
|
prerelease: false
|
202
202
|
version_requirements: !ruby/object:Gem::Requirement
|
203
203
|
requirements:
|
204
|
-
- -
|
204
|
+
- - '='
|
205
205
|
- !ruby/object:Gem::Version
|
206
|
-
version:
|
206
|
+
version: 0.93.1
|
207
207
|
- !ruby/object:Gem::Dependency
|
208
208
|
name: rubocop-performance
|
209
209
|
requirement: !ruby/object:Gem::Requirement
|
@@ -259,6 +259,7 @@ files:
|
|
259
259
|
- lib/hashes_equal/generic_diff_displayer.rb
|
260
260
|
- lib/hashes_equal/hash_compare_helper.rb
|
261
261
|
- lib/hashes_equal/hash_diff_displayer.rb
|
262
|
+
- lib/hashes_equal/time_coarsener.rb
|
262
263
|
- lib/hashes_equal/version.rb
|
263
264
|
homepage: https://github.com/Facilecomm/hashes_equal
|
264
265
|
licenses:
|
@@ -279,7 +280,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
279
280
|
- !ruby/object:Gem::Version
|
280
281
|
version: '0'
|
281
282
|
requirements: []
|
282
|
-
rubygems_version: 3.0.
|
283
|
+
rubygems_version: 3.0.3
|
283
284
|
signing_key:
|
284
285
|
specification_version: 4
|
285
286
|
summary: MiniTest style assertion to compare hashes.
|