【发布时间】:2014-06-30 13:25:37
【问题描述】:
我想测试一下;
1) 类在其初始化方法中调用特定方法
2) 该方法返回一个特定的值。
我的代码:
it 'should call message method with a message' do
expect_any_instance_of(MyExample).to receive(:message).with("A Message")
MyExample.new("A Message")
end
it 'should call message method with a message and return message_var in reverse' do
expect_any_instance_of(MyExample).to receive(:message).with("A Message").and_return("this should fail")
MyExample.new("A Message")
end
class MyExample
def initialize(m)
message(m)
end
def message(m)
return m.reverse
end
end
问题是第二个测试总是通过,无论传递给 .and_return()
任何帮助将不胜感激,谢谢! 完整代码清单:http://pastebin.com/pkNuZfC4
【问题讨论】:
标签: ruby rspec initialization return