2011-08-24 90 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