rspice 0.27.1 → 0.29.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: 0ff9d0faf944ab29fdb19ad16b7118d666ff28eab278afe88bab135ffc365062
4
- data.tar.gz: 86348217f7cc96f97d35d967627449bf5f75f66d6e0c90021d4892ecb77a9725
3
+ metadata.gz: 2d81a88fc0c720d4eb3068fca5597ed2a6577b81033230c5e7ee668d81df87a6
4
+ data.tar.gz: 7aa5eaefe973d301c6f3d591bafced7a32ef466660cf24175d5138a12566e324
5
5
  SHA512:
6
- metadata.gz: 4a5f9f2b0583787e575acc3ea28e5045b3310fa04565fb725432768be8cb4b1d9443abebaae1b771f0e1d4c5d6218962fc9f9d7246dd4d81ef6c87a3e9f1b13a
7
- data.tar.gz: 1024d5a79ddeb3f2868b8ec8369e82339f4425bcfc4843f47e0bffec359fe1789bd09237aad4c97ce60c0874949783bc1d7a64edb523e9a1b5c5562adc75975a
6
+ metadata.gz: c019a7b1655e014935c5ed90088aac8b13d4122617f9cf25c33c3ac1efacb6e17f73b563faca4d9c9774f5217bcf7c8a79b98f9a45df933588a778d82e7dc99d
7
+ data.tar.gz: d8e34f805ef8474845f91bff69ad2c42deb7cda6d0c103f00590e0e952b6a6e8aef38cfbe4d6cfeb5512dab71a0475b2203d81c8c8bad834b8989aee0232515f
data/README.md CHANGED
@@ -68,13 +68,13 @@ require 'rspice'
68
68
 
69
69
  ## Development
70
70
 
71
- See Spicerack development instructions [here](https://github.com/Freshly/spicerack/blob/develop/README.md#development).
71
+ See Spicerack development instructions [here](https://github.com/RubyAfterAll/spicerack/blob/develop/README.md#development).
72
72
 
73
73
  To add a new example, context or matcher, add a new file to the appropriate directory in lib/rspice. Next, require the added file in its respective include file (such as `lib/rspice/custom_matchers.rb`).
74
74
 
75
75
  ## Contributing
76
76
 
77
- See Spicerack contribution instructions [here](https://github.com/Freshly/spicerack/blob/develop/README.md#contributing).
77
+ See Spicerack contribution instructions [here](https://github.com/RubyAfterAll/spicerack/blob/develop/README.md#contributing).
78
78
 
79
79
  ## License
80
80
 
@@ -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.1"
5
+ VERSION = "0.29.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.1
4
+ version: 0.29.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-09-04 00:00:00.000000000 Z
14
+ date: 2022-04-08 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rspec
@@ -85,15 +85,15 @@ files:
85
85
  - lib/rspice/shared_examples/an_inherited_property.rb
86
86
  - lib/rspice/shared_examples/an_instrumented_event.rb
87
87
  - lib/rspice/version.rb
88
- homepage: https://github.com/Freshly/spicerack/tree/main/rspice
88
+ homepage: https://github.com/RubyAfterAll/spicerack/tree/main/rspice
89
89
  licenses:
90
90
  - MIT
91
91
  metadata:
92
- homepage_uri: https://github.com/Freshly/spicerack/tree/main/rspice
93
- source_code_uri: https://github.com/Freshly/spicerack/tree/main/rspice
94
- changelog_uri: https://github.com/Freshly/spicerack/blob/main/rspice/CHANGELOG.md
95
- documentation_uri: https://www.rubydoc.info/gems/rspice/0.27.1
96
- post_install_message:
92
+ homepage_uri: https://github.com/RubyAfterAll/spicerack/tree/main/rspice
93
+ source_code_uri: https://github.com/RubyAfterAll/spicerack/tree/main/rspice
94
+ changelog_uri: https://github.com/RubyAfterAll/spicerack/blob/main/rspice/CHANGELOG.md
95
+ documentation_uri: https://www.rubydoc.info/gems/rspice/0.29.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.26
112
- signing_key:
111
+ rubygems_version: 3.3.8
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: []