2011-08-24 91 views
0

我对我的班级有很多测试。 当我添加检查文件的存在,在我的班级。全球模拟摩卡

我需要在我的所有情况下添加此代码。

File.any_instance. 
    expects(:exist?). 
    with('test_file'). 
    returns(true). 
    once() 

但我要声明我所有的测试全球模拟,我可以让这个与摩卡和RSpec?

回答

0

会做到这一点像如下:

describe Thing do 

    # If this is really done once... 

    before :all do 
    File.any_instance.expects(:exist?).with('test_file').returns(true).once 
    end 

    # If this is done once per example... 

    before :each do 
    File.any_instance.expects(:exist?).with('test_file').returns(true).once 
    end 

    # ... 

end