我有以下测试:RSpec的消息的期望没有得到满足,但方法被称为
describe "Exporter#get_method" do
before(:each) do
exporter.should_receive(:get_method).at_least(:once).and_call_original
end
it "should get the next terminal value" do
exporter.send(:get_method).should == :split
end
it "should call descend if the current value is a hash" do
exporter.should_receive(:descend).once
2.times { exporter.send(:get_method) }
end
it "should call ascend if at the end of an array and there is a prologue" do
exporter.should_receive(:ascend).once
3.times { exporter.send(:get_method) }
end
end
我可以用一对夫妇binding.pry的验证调用升降被调用。但RSpec没有看到它。我哪里错了。我想确保正在测试的方法在正确的情况下调用其他方法。有没有另一种方法来做到这一点?
没有骰子。在具体的块中,我得到了与call_original相同的失败。这是一种私人方法。不过,我想通过测试,以便我知道未来是否会破坏测试。要么通过改变其作出决定的条件,要么通过修改方法而不意识到我也修改了行为。 – LeakyBucket
文件中是否还有其他存根(可能位于顶部)?这个陷阱会让你经常... – Gabe
不是,只有两个let语句:let(:exporter){Export :: Exporter.new'data',[:split,{:to_s => [:split] }]} let(:formats){{:xls => Export :: Formatters :: XLSFormatter,:csv => Export :: Formatters :: CSVFormatter}} – LeakyBucket