문제

I have many tests for my class. When I added check for file existence, in my class.

I needed to add this code in all my cases.

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

But I want declare a global mock for all my tests, can I make this with mocha and rspec?

도움이 되었습니까?

해결책

Would do this like follows:

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top