rspec-sorbet 1.8.3 → 1.9.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: 2d40a0e2d4b22ec8c7a7809fea36e467492bd7c649ac7de5ac3e09130ac7e180
4
- data.tar.gz: a39fe8993182ca260861e2d583e68ce9fb332e9557d376210583f33be7042208
3
+ metadata.gz: 88e13e13b30f81692eee4f6e0733cb8382c177df738040fd973b800976940459
4
+ data.tar.gz: 9e655229ec0b953a8bd0839d9f28f2be66d9553d5c6854fbe83dcdd323586f7d
5
5
  SHA512:
6
- metadata.gz: daa20d80ec931a565cdec2dbcd25a72c781a319b0760d5896e0470ad35cd789eb90a8d543aebb01e282fa11f512882c1ccff03832ec7865d18d1627974857a45
7
- data.tar.gz: bb6bc7ea8e5f088f73eea5c72498ba4839c3aecc6dc83fb727135d15abdf24cb9ce3454de689fd7f31662e8fc65d0868ad2157c671ff55f23c7aeb5b434583b6
6
+ metadata.gz: 754248f96d753ca1069284780ff3cabb11700f3f224ab28a3336df5261ed9935371948cd4e40cb992177796a21c7fcb95d0a49d3474db6f33a1a0612f3c3f121
7
+ data.tar.gz: ad16625d96aa2acd2c3d4fba8b7b8f5bb11988ae6a0fb2075b78b7dd53db7106abba8b3a91a063adb8d4201e412735e39ed4b93db01c7c591bd6aa7cc5e32d26
@@ -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.SLACK_BOT_TOKEN }}"
43
+ SLACK_BOT_TOKEN: "${{ secrets.BELLROY_SLACK_TOKEN }}"
42
44
  with:
43
- args: '{\"channel\":\"C33574SJJ\",\"text\":\"* ${{ github.repository }} BUILD
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
@@ -1,3 +1,7 @@
1
+ 1.9.0
2
+
3
+ * Allow specification of a custom validation handler (thanks [@bmalinconico](https://github.com/bmalinconico))
4
+
1
5
  1.8.3
2
6
 
3
7
  * Make sorbet a development dependency
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
+ ```
@@ -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(_signature, opts)
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
- raise TypeError, opts[:pretty_message] if should_raise
120
+ handle_call_validation_error(signature, opts) if should_raise
112
121
  end
113
122
  end
114
123
  end
@@ -3,6 +3,6 @@
3
3
 
4
4
  module RSpec
5
5
  module Sorbet
6
- VERSION = '1.8.3'
6
+ VERSION = '1.9.0'
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-sorbet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.3
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Giles