sproutapp / pavlov

A BDD framework for your Elixir projects
MIT License
128 stars 7 forks source link

FunctionClauseError while calling to_receive #45

Open mspanc opened 9 years ago

mspanc commented 9 years ago

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.

inf0rmer commented 9 years ago

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!