我有一个实现此功能的对象
def link paths.each do |old,new| fileUtils.ln_s old,new endend
基于路径(这是对新旧文件进行哈希配对)完成了几个链接.我的测试看起来像这样:
context "linking files to new ones" do it "links a sample to the propper file" do @comb.link expect(fileUtils).to have_received(:ln_s).with("/example/path/files/old.root","example/path/nornmfiles/new.root") endend
因为我想测试至少在它们被调用时必须使用has_received方法,因为一旦使用不同的参数调用ln_s方法,接收的方法就会失败.问题是测试失败,因为这是一个测试,我真的要创建链接,因为文件不存在因此它不能引发异常,因为文件不存在.
如何在不实际调用方法的情况下测试它?
一旦进行不同的呼叫,该呼叫也会失败
it "links a sample with a region subpath to the propper file" do expect(fileUtils).to receive(:ln_s).with("/example/path/files/pathsuff/old.root","/example/path/normfiles/pathsuff/new.root").at_least(:once) @comb.link end
它给出了这个错误:
RSpec::Mocks::MockExpectationError: fileUtils received :ln_s with unexpected arguments expected: ("/example/path/files/pathsuff/old.root","/example/path/normfiles/pathsuff/new.root") got: ("/example/path/files/old.root","/example/path/normfiles/new.root")
这是可以调用的可能发生的其他调用的其他调用
解决方法context "linking files to new ones" do it "links a sample to the propper file" do allow(fileUtils).to receive(:ln_s) @comb.link expect(fileUtils).to have_received(:ln_s).with( "/example/path/files/old.root","example/path/nornmfiles/new.root",).at_least(:once) endend总结
以上是内存溢出为你收集整理的ruby – Rspec检查是否在没有调用方法的情况下调用了方法全部内容,希望文章能够帮你解决ruby – Rspec检查是否在没有调用方法的情况下调用了方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)