Yes, it is possible, but the syntax you want to use (using spaces everywhere) has the implicatiion that have(:name)
and eq('John')
are all arguments applied to the method should
. So you would have to predefine those, which cannot be your goal. That said, you can use rspec custom matchers to achieve a similar goal:
require 'rspec/expectations'
RSpec::Matchers.define :have do |meth, expected|
match do |actual|
actual.send(meth) == expected
end
end
This gives you the following syntax:
it { should have(:name, 'John') }
Also, you can use its
its(:name){ should eq('John') }