Sì, è possibile, ma la sintassi che si desidera utilizzare (usando gli spazi ovunque) ha l'implicazione che have(:name)
e eq('John')
sono tutti argomenti applicati al metodo should
. Quindi dovresti predefinire quelli, il che non può essere il tuo obiettivo. Detto questo, puoi usare RSSPEC MATCHERS CUSTIM Per raggiungere un obiettivo simile:
require 'rspec/expectations'
RSpec::Matchers.define :have do |meth, expected|
match do |actual|
actual.send(meth) == expected
end
end
Questo ti dà la seguente sintassi:
it { should have(:name, 'John') }
Inoltre, puoi usare its
its(:name){ should eq('John') }