rspec-sorbet 1.8.3 → 1.9.0
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/.github/workflows/ci.yml +4 -2
- data/CHANGELOG.md +4 -0
- data/README.md +13 -0
- data/lib/rspec/sorbet/doubles.rb +11 -2
- data/lib/rspec/sorbet/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88e13e13b30f81692eee4f6e0733cb8382c177df738040fd973b800976940459
|
4
|
+
data.tar.gz: 9e655229ec0b953a8bd0839d9f28f2be66d9553d5c6854fbe83dcdd323586f7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 754248f96d753ca1069284780ff3cabb11700f3f224ab28a3336df5261ed9935371948cd4e40cb992177796a21c7fcb95d0a49d3474db6f33a1a0612f3c3f121
|
7
|
+
data.tar.gz: ad16625d96aa2acd2c3d4fba8b7b8f5bb11988ae6a0fb2075b78b7dd53db7106abba8b3a91a063adb8d4201e412735e39ed4b93db01c7c591bd6aa7cc5e32d26
|
data/.github/workflows/ci.yml
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
---
|
2
2
|
name: Continuous Integration
|
3
|
+
env:
|
4
|
+
SLACK_CHANNEL_ID: C0317P7C9C2
|
3
5
|
on:
|
4
6
|
push:
|
5
7
|
branches-ignore:
|
@@ -38,9 +40,9 @@ jobs:
|
|
38
40
|
|| github.ref == 'refs/heads/stable')
|
39
41
|
uses: pullreminders/slack-action@a5a262c896a1cc80dcbae59ba95513e2dfb21439
|
40
42
|
env:
|
41
|
-
SLACK_BOT_TOKEN: "${{ secrets.
|
43
|
+
SLACK_BOT_TOKEN: "${{ secrets.BELLROY_SLACK_TOKEN }}"
|
42
44
|
with:
|
43
|
-
args: '{\"channel\":\"
|
45
|
+
args: '{\"channel\":\"${{ env.SLACK_CHANNEL_ID }}\",\"text\":\"* ${{ github.repository }} BUILD
|
44
46
|
FAILURE*\", \"attachments\": [{ \"fallback\": \"Failure summary\", \"color\":
|
45
47
|
\"#ff0000\", \"fields\": [{\"title\": \"Branch\", \"value\":\"${{ steps.extract_branch.outputs.branch
|
46
48
|
}}\"}, {\"title\": \"Who broke it\", \"value\":\"${{ github.actor }}\"},
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -34,3 +34,16 @@ RSpec::Sorbet.allow_doubles!
|
|
34
34
|
### `eq` matcher usage with `T::Struct`'s
|
35
35
|
|
36
36
|
Using the [`eq` matcher](https://www.rubydoc.info/github/rspec/rspec-expectations/RSpec%2FMatchers:eq) to compare [`T::Struct`'s](https://sorbet.org/docs/tstruct) might not behave as you'd expect whereby two separate instances of the same struct class with identical attributes are not `==` out of the box. The standalone [sorbet-struct-comparable](https://github.com/tricycle/sorbet-struct-comparable) gem may be of interest if you are looking for a simple attribute based comparison that will help make the `eq` matcher behave as you expect.
|
37
|
+
|
38
|
+
### Specifying a custom validation handler
|
39
|
+
|
40
|
+
You can customise the handler of Sorbet validation errors if you so desire.
|
41
|
+
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
def handler(signature, opts)
|
45
|
+
raise MyCustomException, "The options were #{opts}"
|
46
|
+
end
|
47
|
+
|
48
|
+
T::Configuration.call_validation_error_handler = handler
|
49
|
+
```
|
data/lib/rspec/sorbet/doubles.rb
CHANGED
@@ -11,6 +11,8 @@ module RSpec
|
|
11
11
|
inline_type_error_handler(error)
|
12
12
|
end
|
13
13
|
|
14
|
+
@existing_handler = T::Configuration.instance_variable_get(:@call_validation_error_handler)
|
15
|
+
|
14
16
|
T::Configuration.call_validation_error_handler = proc do |signature, opts|
|
15
17
|
call_validation_error_handler(signature, opts)
|
16
18
|
end
|
@@ -23,6 +25,13 @@ module RSpec
|
|
23
25
|
INLINE_DOUBLE_REGEX =
|
24
26
|
/T.(?:let|cast): Expected type (?:T.(?<t_method>any|nilable|class_of)\()?(?<expected_types>[a-zA-Z0-9:: ,]*)(\))?, got (?:type .* with value )?#<(?<double_type>Instance|Class|Object)?Double([\(]|[ ])(?<doubled_type>[a-zA-Z0-9:: ,]*)(\))?/.freeze
|
25
27
|
|
28
|
+
|
29
|
+
def handle_call_validation_error(signature, opts)
|
30
|
+
raise TypeError, opts[:pretty_message] unless @existing_handler
|
31
|
+
|
32
|
+
@existing_handler.call(signature, opts)
|
33
|
+
end
|
34
|
+
|
26
35
|
def inline_type_error_handler(error)
|
27
36
|
case error
|
28
37
|
when TypeError
|
@@ -75,7 +84,7 @@ module RSpec
|
|
75
84
|
message.match?(TYPED_ARRAY_MESSAGE)
|
76
85
|
end
|
77
86
|
|
78
|
-
def call_validation_error_handler(
|
87
|
+
def call_validation_error_handler(signature, opts)
|
79
88
|
should_raise = true
|
80
89
|
|
81
90
|
message = opts.fetch(:pretty_message, opts.fetch(:message, ''))
|
@@ -108,7 +117,7 @@ module RSpec
|
|
108
117
|
end
|
109
118
|
end
|
110
119
|
|
111
|
-
|
120
|
+
handle_call_validation_error(signature, opts) if should_raise
|
112
121
|
end
|
113
122
|
end
|
114
123
|
end
|
data/lib/rspec/sorbet/version.rb
CHANGED