你可以简单地循环:
["test@test.pl", "Email"].each { |str| last_email_sent.body.should include str }
或者,如果您喜欢匹配器语法,请编写自己的匹配器:
RSpec::Matchers.define :include_all do |include_items|
match do |given|
@errors = include_items.reject { |item| given.include?(item) }
@errors.empty?
end
failure_message_for_should do |given|
"did not include \"#{@errors.join('\", \"')}\""
end
failure_message_for_should_not do |given|
"everything was included"
end
description do |given|
"includes all of #{include_items.join(', ')}"
end
end
像这样调用它:
last_email_sent.body.should include_all ["test@test.pl", "Email"]