【发布时间】:2023-03-09 05:40:01
【问题描述】:
我需要测试一段代码执行两条sql语句,我是这么说的
ActiveRecord::Base.connection.should_receive(:execute).with("s1")
ActiveRecord::Base.connection.should_receive(:execute).with("s2")
但是,该代码还执行了许多我不关心的其他语句,这会使测试出错。如何告诉 Rspec 确保 s1 和 s2 在已执行语句列表中?
【问题讨论】:
-
"which trips up the test"-- 你的意思是这会让预期不起作用,还是说它会让实际代码不起作用? -
预期不起作用 - 在
s1和s2之前和之后执行的一些查询会触发预期错误。
标签: unit-testing activerecord rspec rspec2