rspice 0.27.0 → 0.28.0
Sign up to get free protection for your applications and to get access to all the features.
- 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: c5c08de39871947d4f7d1e759bcec88514e37dbbf8d8dae8fd476cb999ddcf22
|
4
|
+
data.tar.gz: e6f1dac105ffd0a5bc7f0a4b3fd91691a851fd4e08e64bfec44905de6d04661e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23ef2bde1dfcd4188044c4c1ffbbaf5e0a87909f357f388e8182f288cb22f8e07f26c4ee7024453c2163838343e08a182aa64e8949de2c625c63b59319f5ca65
|
7
|
+
data.tar.gz: ab2e0176c6255a7b65ad484ba278d43cbfaef0353520d34aa3f87597fdb91e885a91c964109b6e8ee8977e24089b7805fa2389743fc85e48e2205d9eb10f745e
|
@@ -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.
|
4
|
+
version: 0.28.0
|
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-04-06 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.
|
96
|
-
post_install_message:
|
95
|
+
documentation_uri: https://www.rubydoc.info/gems/rspice/0.28.0
|
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.
|
112
|
-
signing_key:
|
111
|
+
rubygems_version: 3.3.9
|
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: []
|