Are there any matchers in RSpec to check that a class is instantiated with an argument?
Something like it { is_expected.to respond_to(:initialize).with(1).argument }
Thanks!
Are there any matchers in RSpec to check that a class is instantiated with an argument?
Something like it { is_expected.to respond_to(:initialize).with(1).argument }
Thanks!
Dave Schweisguth
On
The respond_to matcher that you give as an example exists, with the exact syntax that you give.
However, you need to test the .new method, not the .initialize method, because .initialize is private.
class X
def initialize(an_arg)
end
end
describe X do
describe '.new'
it "takes one argument" do
expect(X).to respond_to(:new).with(1).argument
end
end
end
I'm not 100% sure if this is what you're asking? By default if the class requires arguments and you instantiate incorrectly it will throw an ArgumentError.
Alternatively you could use
attr_readeron your arguments and compareinstance_variables.