我想为 Rspec 2 声明自定义匹配器
我正在使用rspec 2.13
和rails 3.2.13
。
我试图写这样的东西:
RSpec::Matchers.define :be_present do |expected|
match do
expected !be_empty
end
end
但是当我在规范中使用它时,它不起作用失败:
1) NewsletterMailer.send_newsletter_to_groups from
Failure/Error: its(:from) { should be_present }
ArgumentError:
wrong number of arguments (1 for 0)
规格代码:
describe NewsletterMailer do
describe '.send_newsletter_to_emails' do
let(:user) { create(:admin) }
let(:user2) { create(:user) }
subject { NewsletterMailer.send_newsletter_to_emails(newsletter.id, "#{user.email}, #{user2.email}") }
its(:to) { should == [user.email, user2.email] }
its(:from) { should be_present }
its(:subject) { should be }
end
编辑:
我想要这样的逻辑反转:
its(:from) { should_not be_nil }