你可以簡單地循環:
["[email protected]", "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 ["[email protected]", "Email"]
是什麼'last_email_sent.body'樣子? –
它是多串 – tomekfranek