Skip to content

Commit

Permalink
Merge pull request #19 from deecewan/fix/nilable-double-types
Browse files Browse the repository at this point in the history
support T.nilable(T.class_of(...)) doubles
  • Loading branch information
michaelwebb76 authored Oct 18, 2022
2 parents 74c0115 + 67a018a commit 8eec2ff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rspec/sorbet/doubles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def allow_doubles!
private

INLINE_DOUBLE_REGEX =
/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
/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


def handle_call_validation_error(signature, opts)
Expand Down
4 changes: 4 additions & 0 deletions spec/lib/rspec/sorbet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,15 @@ def rectangular_class?(klass); end
expect { T.let(class_double(Rectangle), Rectangle) }.to raise_error(TypeError)
expect { T.let(Rectangle, T.class_of(Rectangle)) }.not_to raise_error
expect { T.let(class_double(Rectangle), T.class_of(Rectangle)) }.to raise_error(TypeError)
expect { T.let(Rectangle, T.nilable(T.class_of(Rectangle))) }.not_to raise_error
expect { T.let(class_double(Rectangle), T.nilable(T.class_of(Rectangle))) }.to raise_error(TypeError)
subject
expect { T.let(Rectangle, Rectangle) }.to raise_error(TypeError)
expect { T.let(class_double(Rectangle), Rectangle) }.to raise_error(TypeError)
expect { T.let(Rectangle, T.class_of(Rectangle)) }.not_to raise_error
expect { T.let(class_double(Rectangle), T.class_of(Rectangle)) }.not_to raise_error
expect { T.let(Rectangle, T.nilable(T.class_of(Rectangle))) }.not_to raise_error
expect { T.let(class_double(Rectangle), T.nilable(T.class_of(Rectangle))) }.not_to raise_error
end

specify 'method signatures' do
Expand Down

0 comments on commit 8eec2ff

Please sign in to comment.