我有以下规格:
describe EmailImport do
describe "#format_x_priority" do
specify { EmailImport.format_x_priority('5 (Lowest)').should eq(:low) }
it "should raise an error when wrong argument is passed" do
expect { EmailImport.format_x_priority('5 (Lowest)').to raise_error }
end
end
end
这应该不会过去吧?两次都是相同的代码,一次应该导致:low
,一次应该导致错误。但有趣的是,两者都通过了!我究竟做错了什么?
只是为了完整起见,这是我的EmailImport.format_x_priority
方法:
def self.format_x_priority(priority)
# 1 Highest; 2 High; 3 oder "" normal; 4 low; 5 lowest
case priority
when "1 (Highest)"
Priority::HIGH
when "2 (High)"
Priority::HIGH
when "3 (Middle)"
Priority::MEDIUM
when "4 (Low)"
Priority::LOW
when "5 (Lowest)"
Priority::LOW
when ''
Priority::MEDIUM
else
raise "Invalid value '#{priority}' for argument 'priority'!"
end
end