我有用户输入的代码:
class Z
def self.input()
val = $stdin.gets.chomp
if val == "123"
p "Ok"
else
p "none"
end
end
end
我想测试不同的数据:
describe "Z" do
it "should receive none"
Object.stub!(:gets){"das"}
Z.input
Object.should_receive(:p).with("none")
end
end
但我得到一个错误:
Failure/Error: Object.should_receive(:p).with("none")
(<Object (class)>).p("none")
expected: 1 time
received: 0 times
如何测试输出?谢谢。