shard-spectator/spec/issues/github_issue_32_spec.cr
Michael Miller 2e5f822e1d
Remove new from reserved keywords
This effectively allows stubs to be placed on the `new` method for types.
A strange issue arose when the keyword was allowed.
The compiler failed to resolve the Stub type from the Double initializer.
The error trace goes through null_double_spec.cr.
Running just that spec file confirms the issue is there, but running other individual files doesn't produce the error.
As a workaround, I've put the full path of Stub in the initializer.
2022-07-12 22:30:04 -06:00

34 lines
718 B
Crystal

require "../spec_helper"
Spectator.describe "GitHub Issue #32" do
module TestFoo
class TestClass
def initialize
end
# the method we are testing
def self.test
new().test
end
# the method we want to ensure gets called
def test
end
end
end
let(test_class) { TestFoo::TestClass }
let(test_instance) { test_class.new }
describe "something else" do
inject_mock TestFoo::TestClass
it "must test when new is called" do
expect(test_class).to receive(:new).with(no_args).and_return(test_instance)
expect(test_instance).to receive(:test)
expect(test_class.new).to be(test_instance)
test_class.test
end
end
end