rspice 0.27.1 → 0.27.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/lib/rspice/custom_matchers/have_error_on_attribute.rb +51 -4
- data/lib/rspice/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f449035f7409c9dc2a50a54d9eec58a77d0231671d068c3db3ae1669f9ec56b
|
4
|
+
data.tar.gz: 2d61af50c90b36c23cb801105b2abeb492885862de257e44f4111ba00dd590b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b58ecf6e2f3b438d6bafcb4a19dc184c7e3a18b7513b9c46600d05811f9c5d4b8394a16c8d1792697037a9c936527544a8a8951830da4ba00e41270f180d104b
|
7
|
+
data.tar.gz: 884204df4d59af10597420d6cc77f10107929b5e6c3e8a2a5a6cc373ada95373244630b938275272beb439eab9868c8bc73c5f322c3e573175bfcaafd6e7a79b
|
@@ -20,14 +20,24 @@
|
|
20
20
|
# end
|
21
21
|
|
22
22
|
RSpec::Matchers.define :have_error_on_attribute do |attribute|
|
23
|
+
attr_reader :record, :attribute
|
24
|
+
|
23
25
|
match do |record|
|
24
26
|
raise ArgumentError, "have_error_on_attribute matcher requires a detail_key" if @detail_key.blank?
|
25
27
|
|
26
|
-
@
|
28
|
+
@record = record
|
29
|
+
@attribute = attribute
|
30
|
+
|
31
|
+
error_present? && translation_present?
|
32
|
+
end
|
33
|
+
|
34
|
+
match_when_negated do |record|
|
35
|
+
raise ArgumentError, "have_error_on_attribute matcher requires a detail_key" if @detail_key.blank?
|
27
36
|
|
28
|
-
|
37
|
+
@record = record
|
38
|
+
@attribute = attribute
|
29
39
|
|
30
|
-
|
40
|
+
!error_present?
|
31
41
|
end
|
32
42
|
|
33
43
|
chain :with_detail_key do |detail_key|
|
@@ -39,10 +49,47 @@ RSpec::Matchers.define :have_error_on_attribute do |attribute|
|
|
39
49
|
end
|
40
50
|
|
41
51
|
failure_message do |record|
|
42
|
-
|
52
|
+
if translation_present?
|
53
|
+
"expected #{record} to have error on attribute #{attribute} with detail key #{@detail_key.inspect}, got #{@errors}"
|
54
|
+
else
|
55
|
+
missing_translation_failure_message
|
56
|
+
end
|
43
57
|
end
|
44
58
|
|
45
59
|
failure_message_when_negated do |record|
|
46
60
|
"expected #{record} not to have error on attribute #{attribute} with detail key #{@detail_key.inspect}"
|
47
61
|
end
|
62
|
+
|
63
|
+
def errors
|
64
|
+
@errors ||= (record.errors.details[attribute.to_sym] || []).pluck(:error).map(&:to_sym)
|
65
|
+
end
|
66
|
+
|
67
|
+
def error_present?
|
68
|
+
errors&.include?(@detail_key.to_sym)
|
69
|
+
end
|
70
|
+
|
71
|
+
def translation_present?
|
72
|
+
return @translation_present if defined?(@translation_present)
|
73
|
+
|
74
|
+
@translation_present ||= begin
|
75
|
+
record.errors[attribute.to_sym]
|
76
|
+
true
|
77
|
+
rescue *[ (I18n::MissingTranslationData if defined?(I18n::MissingTranslationData)) ] => exception # rubocop:disable Lint/RedundantSplatExpansion
|
78
|
+
@missing_translation_error = exception
|
79
|
+
false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def missing_translation_failure_message
|
84
|
+
message = <<~MESSAGE
|
85
|
+
expected error #{@detail_key.inspect} was present, but is missing a translation at key:
|
86
|
+
#{@missing_translation_error.key}
|
87
|
+
MESSAGE
|
88
|
+
|
89
|
+
if defined?(Rails) && Rails.application.present?
|
90
|
+
message << "\nIf this is ok, try setting config.i18n.raise_on_missing_translations = false in config/environments/test.rb"
|
91
|
+
end
|
92
|
+
|
93
|
+
message
|
94
|
+
end
|
48
95
|
end
|
data/lib/rspice/version.rb
CHANGED
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.27.
|
4
|
+
version: 0.27.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Garside
|
8
8
|
- Allen Rettberg
|
9
9
|
- Jordan Minneti
|
10
10
|
- Aleksei Kharkov
|
11
|
-
autorequire:
|
11
|
+
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2022-02-08 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rspec
|
@@ -92,8 +92,8 @@ metadata:
|
|
92
92
|
homepage_uri: https://github.com/Freshly/spicerack/tree/main/rspice
|
93
93
|
source_code_uri: https://github.com/Freshly/spicerack/tree/main/rspice
|
94
94
|
changelog_uri: https://github.com/Freshly/spicerack/blob/main/rspice/CHANGELOG.md
|
95
|
-
documentation_uri: https://www.rubydoc.info/gems/rspice/0.27.
|
96
|
-
post_install_message:
|
95
|
+
documentation_uri: https://www.rubydoc.info/gems/rspice/0.27.2
|
96
|
+
post_install_message:
|
97
97
|
rdoc_options: []
|
98
98
|
require_paths:
|
99
99
|
- lib
|
@@ -108,8 +108,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
|
-
rubygems_version: 3.2.
|
112
|
-
signing_key:
|
111
|
+
rubygems_version: 3.2.32
|
112
|
+
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: An `RSpec` utility gem of custom matchers, shared contexts and examples
|
115
115
|
test_files: []
|