RSpec Mock Object Example

前端 未结 5 1220
说谎
说谎 2021-01-30 13:13

I am new to mock objects, and I am trying to learn how to use them in RSpec. Can someone please post an example (a hello RSpec Mock object world type example), or a link (or any

5条回答
  •  你的背包
    2021-01-30 14:09

    mock is deprecated based on this github pull.

    Now instead we can use double - more here...

     before(:each) do
       @page = double("Page")
       end
    
      it "page should return hello world" do
        allow(@page).to receive(:say).and_return("hello world")
        answer = @page.say
        expect(answer).to eq("hello world")
      end
    

提交回复
热议问题