Skip to content

Commit

Permalink
support T.nilable(T.class_of(...)) doubles
Browse files Browse the repository at this point in the history
closes #18
  • Loading branch information
deecewan committed Oct 17, 2022
1 parent 74c0115 commit 67a018a
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 67a018a

Please sign in to comment.