rspec-sorbet 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +4 -4
- data/lib/rspec/sorbet/all.rb +1 -1
- data/lib/rspec/sorbet/{instance_doubles.rb → doubles.rb} +14 -10
- data/lib/rspec/sorbet/version.rb +1 -1
- data/lib/rspec/sorbet.rb +2 -2
- data/rspec-sorbet.gemspec +0 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c205b25d63802b44689b70f609d5e0a7c1fef16c9a69835cb111e99b66354cb
|
4
|
+
data.tar.gz: af324a74455c56c45a8034738275f915ee608e4a635fd00fa46d0388c179888a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90ea1853d6ef471805f179a0169680f014231f2d5e23827dbba1723229b62e5ada5173178efeb37d47345668474109aa1baf2034dc37dd6aa2b390e813f59792
|
7
|
+
data.tar.gz: '0464345935eb9a67b4fc2ade7503d22b77e33c5134137d445fb95a7f63c49847dc9e3b6c8f63603e819adc317be6c76725dea55768f841036749761f84470a2d'
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
|
1
|
+
1.3.0
|
2
|
+
|
3
|
+
* Added ability to allow any kind of double (Class, Instance, Object).
|
4
|
+
* `RSpec::Sorbet.allow_instance_doubles!` has been renamed to `RSpec::Sorbet.allow_doubles!`, an alias remains for backwards compatibility for the time being.
|
5
|
+
|
6
|
+
1.2.1
|
2
7
|
|
3
8
|
* Fix call check when opts contains :message instead of :pretty_message.
|
4
9
|
|
data/README.md
CHANGED
@@ -15,9 +15,9 @@ In your `spec_helper.rb` you need to first add a `require`:
|
|
15
15
|
require 'rspec/sorbet'
|
16
16
|
```
|
17
17
|
|
18
|
-
### Allowing Instance Doubles
|
18
|
+
### Allowing Instance/Class/Object Doubles
|
19
19
|
|
20
|
-
Out of the box if you're using `instance_double`
|
20
|
+
Out of the box if you're using `instance_double`, `class_double` or `object_double` in your tests you'll encounter errors such as the following:
|
21
21
|
|
22
22
|
```
|
23
23
|
TypeError:
|
@@ -25,8 +25,8 @@ Out of the box if you're using `instance_double`'s in your tests you'll encounte
|
|
25
25
|
Caller: /Users/samuelgiles/Documents/Projects/Clients/Bellroy/bellroy/spec/lib/checkout/use_cases/my_use_case.rb:9
|
26
26
|
```
|
27
27
|
|
28
|
-
Drop the following into your `spec_helper.rb` to allow
|
28
|
+
Drop the following into your `spec_helper.rb` to allow doubles to be used without breaking type checking:
|
29
29
|
|
30
30
|
```ruby
|
31
|
-
RSpec::Sorbet.
|
31
|
+
RSpec::Sorbet.allow_doubles!
|
32
32
|
```
|
data/lib/rspec/sorbet/all.rb
CHANGED
@@ -4,8 +4,12 @@ require 'sorbet-runtime'
|
|
4
4
|
|
5
5
|
module RSpec
|
6
6
|
module Sorbet
|
7
|
-
module
|
7
|
+
module Doubles
|
8
8
|
def allow_instance_doubles!
|
9
|
+
allow_doubles!
|
10
|
+
end
|
11
|
+
|
12
|
+
def allow_doubles!
|
9
13
|
T::Configuration.inline_type_error_handler = proc do |error|
|
10
14
|
inline_type_error_handler(error)
|
11
15
|
end
|
@@ -17,16 +21,16 @@ module RSpec
|
|
17
21
|
|
18
22
|
private
|
19
23
|
|
20
|
-
|
21
|
-
/T.let: Expected type (T.any\()?(?<expected_classes>[a-zA-Z:: ,]*)(\))?, got type (.*) with value #<
|
24
|
+
INLINE_DOUBLE_REGEX =
|
25
|
+
/T.let: Expected type (T.any\()?(?<expected_classes>[a-zA-Z:: ,]*)(\))?, got type (.*) with value #<(Instance|Class|Object)Double\((?<doubled_module>[a-zA-Z:: ,]*)\)/.freeze
|
22
26
|
|
23
27
|
def inline_type_error_handler(error)
|
24
28
|
case error
|
25
29
|
when TypeError
|
26
30
|
message = error.message
|
27
|
-
return if
|
31
|
+
return if double_message_with_ellipsis?(message) || typed_array_message?(message)
|
28
32
|
|
29
|
-
_, expected_types_string, doubled_module_string = (message.match(
|
33
|
+
_, expected_types_string, doubled_module_string = (message.match(INLINE_DOUBLE_REGEX) || [])[0..2]
|
30
34
|
raise error unless expected_types_string && doubled_module_string
|
31
35
|
|
32
36
|
expected_types = expected_types_string.split(',').map do |expected_type_string|
|
@@ -44,11 +48,11 @@ module RSpec
|
|
44
48
|
end
|
45
49
|
end
|
46
50
|
|
47
|
-
|
48
|
-
/(RSpec::Mocks::
|
51
|
+
VERIFYING_DOUBLE_OR_DOUBLE =
|
52
|
+
/(RSpec::Mocks::(Instance|Class|Object)VerifyingDouble|(Instance|Class|Object)Double)/.freeze
|
49
53
|
|
50
|
-
def
|
51
|
-
message.include?('...') && message.match?(
|
54
|
+
def double_message_with_ellipsis?(message)
|
55
|
+
message.include?('...') && message.match?(VERIFYING_DOUBLE_OR_DOUBLE)
|
52
56
|
end
|
53
57
|
|
54
58
|
TYPED_ARRAY_MESSAGE = /got T::Array/.freeze
|
@@ -61,7 +65,7 @@ module RSpec
|
|
61
65
|
should_raise = true
|
62
66
|
|
63
67
|
message = opts.fetch(:pretty_message, opts.fetch(:message, ''))
|
64
|
-
if message.match?(
|
68
|
+
if message.match?(VERIFYING_DOUBLE_OR_DOUBLE)
|
65
69
|
typing = opts[:type]
|
66
70
|
value = opts[:value].is_a?(Array) ? opts[:value].first : opts[:value]
|
67
71
|
target = value.instance_variable_get(:@doubled_module).target
|
data/lib/rspec/sorbet/version.rb
CHANGED
data/lib/rspec/sorbet.rb
CHANGED
data/rspec-sorbet.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-sorbet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Giles
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sorbet
|
@@ -117,7 +117,7 @@ files:
|
|
117
117
|
- lib/rspec/all.rb
|
118
118
|
- lib/rspec/sorbet.rb
|
119
119
|
- lib/rspec/sorbet/all.rb
|
120
|
-
- lib/rspec/sorbet/
|
120
|
+
- lib/rspec/sorbet/doubles.rb
|
121
121
|
- lib/rspec/sorbet/version.rb
|
122
122
|
- rspec-sorbet.gemspec
|
123
123
|
homepage: https://github.com/tricycle/rspec-sorbet
|