sproutapp / pavlov

A BDD framework for your Elixir projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FunctionClauseError while calling to_receive

mspanc opened this issue · comments

Hello

I am trying to do the following

  describe ".start_link/0" do
     before(:each) do
       allow Supervisor |> to_receive(start_link: fn(options) -> {:ok, self()} end)
     end

     it "calls Supervisor.start_link" do
       This.start_link
       expect Supervisor |> to_have_received :start_link
     end 
  end

but I get the following error ** (FunctionClauseError) no function clause matching in Pavlov.Mocks.to_receive/2

I am using master.

Hi! You probably have to use parenthesis in your allow declaration, otherwise |> is trying to call to_receive on the Supervisor object directly, instead of the return of the allow function:

  describe ".start_link/0" do
     before(:each) do
       allow(Supervisor) |> to_receive(start_link: fn(options) -> {:ok, self()} end)
     end

     it "calls Supervisor.start_link" do
       This.start_link
       expect(Supervisor) |> to_have_received :start_link
     end 
  end

Can you try if this works? Thanks!