Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mock class method in RSpec expect syntax?

I have a confusion about how to mock a class method using new expect syntax. This works:

Facebook
  .should_receive(:profile)
  .with("token")
  .and_return({"name" => "Hello", "id" => "14314141", "email" => "[email protected]"})

and this doesn't:

facebook = double("Facebook")
allow(facebook).to receive(:profile).with("token").and_return({"name" => "Hello", "id" => "14314141", "email" => "[email protected]"})

Can someone tell me what is wrong here?

like image 334
aks Avatar asked Oct 17 '22 21:10

aks


1 Answers

Here's what you want to do (no need for double):

allow(Facebook)
  .to receive(:profile)
  .with("token")
  .and_return({"name" => "Hello", "id" => "14314141", "email" => "[email protected]"})
like image 148
Andrey Deineko Avatar answered Oct 21 '22 05:10

Andrey Deineko