rspec-sorbet 1.2.1 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 157ff389d41195f953b898165ddc8eb4d9ecf066e8e74cb97e5c666970b60088
4
- data.tar.gz: 107ec27a30a657e37ccdb359d8e1f7b4eae9242986fec6797dc7d2c5023efa7b
3
+ metadata.gz: 7c205b25d63802b44689b70f609d5e0a7c1fef16c9a69835cb111e99b66354cb
4
+ data.tar.gz: af324a74455c56c45a8034738275f915ee608e4a635fd00fa46d0388c179888a
5
5
  SHA512:
6
- metadata.gz: fadfb8ee20f9857891794468deb9785f325a53e3f9f2ae8a45e39c9846a2a2248300b0b69f026bc83b115eb184b6f649d9ab10ec599ac4389cf4857090183518
7
- data.tar.gz: 75c776e9609b55b6b4a579ab8815c28b0ea350d8b944fc8311665b248654d6996fc821d061dbfcfb58aa30153026f58bb9ee23ec5d94771de38c4dbec0aef339
6
+ metadata.gz: 90ea1853d6ef471805f179a0169680f014231f2d5e23827dbba1723229b62e5ada5173178efeb37d47345668474109aa1baf2034dc37dd6aa2b390e813f59792
7
+ data.tar.gz: '0464345935eb9a67b4fc2ade7503d22b77e33c5134137d445fb95a7f63c49847dc9e3b6c8f63603e819adc317be6c76725dea55768f841036749761f84470a2d'
data/CHANGELOG.md CHANGED
@@ -1,4 +1,9 @@
1
- UNRELEASED
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`'s in your tests you'll encounter errors such as the following:
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 `instance_double` to be used without breaking type checking:
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.allow_instance_doubles!
31
+ RSpec::Sorbet.allow_doubles!
32
32
  ```
@@ -2,5 +2,5 @@
2
2
 
3
3
  # THIS FILE IS AUTOGENERATED AND SHOULD NOT BE MANUALLY MODIFIED
4
4
 
5
- require 'rspec/sorbet/instance_doubles'
5
+ require 'rspec/sorbet/doubles'
6
6
  require 'rspec/sorbet/version'
@@ -4,8 +4,12 @@ require 'sorbet-runtime'
4
4
 
5
5
  module RSpec
6
6
  module Sorbet
7
- module InstanceDoubles
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
- INLINE_INSTANCE_DOUBLE_REGEX =
21
- /T.let: Expected type (T.any\()?(?<expected_classes>[a-zA-Z:: ,]*)(\))?, got type (.*) with value #<InstanceDouble\((?<doubled_module>[a-zA-Z:: ,]*)\)/.freeze
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 instance_double_message_with_ellipsis?(message) || typed_array_message?(message)
31
+ return if double_message_with_ellipsis?(message) || typed_array_message?(message)
28
32
 
29
- _, expected_types_string, doubled_module_string = (message.match(INLINE_INSTANCE_DOUBLE_REGEX) || [])[0..2]
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
- INSTANCE_VERIFYING_DOUBLE_OR_INSTANCE_DOUBLE =
48
- /(RSpec::Mocks::InstanceVerifyingDouble|InstanceDouble)/.freeze
51
+ VERIFYING_DOUBLE_OR_DOUBLE =
52
+ /(RSpec::Mocks::(Instance|Class|Object)VerifyingDouble|(Instance|Class|Object)Double)/.freeze
49
53
 
50
- def instance_double_message_with_ellipsis?(message)
51
- message.include?('...') && message.match?(INSTANCE_VERIFYING_DOUBLE_OR_INSTANCE_DOUBLE)
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?(INSTANCE_VERIFYING_DOUBLE_OR_INSTANCE_DOUBLE)
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module Sorbet
5
- VERSION = '1.2.1'
5
+ VERSION = '1.3.0'
6
6
  end
7
7
  end
data/lib/rspec/sorbet.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rspec/sorbet/instance_doubles'
3
+ require 'rspec/sorbet/doubles'
4
4
 
5
5
  module RSpec
6
6
  module Sorbet
7
- extend InstanceDoubles
7
+ extend Doubles
8
8
  end
9
9
  end
data/rspec-sorbet.gemspec CHANGED
@@ -1,7 +1,6 @@
1
1
  lib = File.expand_path('lib', __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
- require 'rspec/sorbet'
5
4
  require 'rspec/sorbet/version'
6
5
 
7
6
  Gem::Specification.new do |spec|
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.2.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-09-06 00:00:00.000000000 Z
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/instance_doubles.rb
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