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