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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbbd9a3ce788080d8ecbab76e17c0162f8d02d4d686e0176eea1801fa6150fa5
4
- data.tar.gz: db566e480d92c0ced0d861af2d542dac68121e0e3188c331cb4b4e44a8501fbf
3
+ metadata.gz: c5c08de39871947d4f7d1e759bcec88514e37dbbf8d8dae8fd476cb999ddcf22
4
+ data.tar.gz: e6f1dac105ffd0a5bc7f0a4b3fd91691a851fd4e08e64bfec44905de6d04661e
5
5
  SHA512:
6
- metadata.gz: f200a635b69c84515de6ec9eb64f6d01ff01d6f891fa83e75f9b118a82ad965fc02849ff2d2ecf1168958ae75b6394c38f6f49e13ef95cdf39d1545c99c57d7c
7
- data.tar.gz: 6bd229e1547001fbc5580a8d3af5db5ef989795be20275182ee0dd852aff31d3144df52809df0a064ee7fdd98ba1e69ae84272f2885043eecf17e0145b72a7c7
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
- @errors = (record.errors.details[attribute.to_sym] || []).pluck(:error).map(&:to_sym)
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
- expect(@errors).to include(@detail_key.to_sym)
37
+ @record = record
38
+ @attribute = attribute
29
39
 
30
- expect { record.errors[attribute.to_sym] }.to_not raise_error
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
- "expected #{record} to have error on attribute #{attribute} with detail key #{@detail_key.inspect}, got #{@errors}"
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Rspice
4
4
  # This constant is managed by spicerack
5
- VERSION = "0.27.0"
5
+ VERSION = "0.28.0"
6
6
  end
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.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: 2021-08-24 00:00:00.000000000 Z
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.27.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.2.25
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: []