Let's say I have a class definition like so:
class Foo
def init(val)
@val = val
end
def self.bar
:bar
end
def val
@val
end
end
with a spec like:
describe Foo
it { should respond_to(:val) }
it { should respond_to(:bar) }
end
The second it
assertion fails. It isn't clear to me from RSpec's documentation that respond_to
should fail on class methods.
Nowadays it is suggested we use expect, like this:
describe Foo do
it 'should respond to :bar' do
expect(Foo).to respond_to(:bar)
end
end
See: http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
OLD ANSWER:
Actually you can make this approach by providing a subject:
describe Foo do
subject { Foo }
it { should respond_to :bar } # :bar being a class method
end
As described in here: http://betterspecs.org/#subject
Your example should be written like this:
it 'should respond to ::bar' do
Foo.should respond_to(:bar)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With