Initialize Object and method receiver

Hello everyone, I just reviewed the weekly iteration, “Stubs, Mocks, Spies, and Fakes”. It is really good and I enjoy it. I have a few questions regarding the code in the video.

describe "#solution" do
  solution = double("solution")
  clone = double("clone", solution: solution)
  participation = Participation.new(clone: clone)

  result = participation.solution

  expect(clone).to have_received(:solution)
  expect(result).to eq(solution)
end

Firstly, what’s the differences between Participation.new(clone: clone) and Participation.new(clone) ? Are there any reasons we should use which one other than another?

In addition, since we are have clone = double("clone", solution: solution), shouldn’t the receiver of solution method be clone instead of participation ?

(like, result = clone.solution)

These are my questions regarding the video. Thank you!

Participation.new(clone: clone) is using a recent Ruby feature, keyword arguments. In this case since there’s only argument it’s not essential, but when you have several arguments it’s helpful.

I’m not sure I fully grasp your second question, but if we wrote result = clone.solution rather than result = participation.solution then the test would pass but it wouldn’t be verifying the real implementation at all, since participation is never used.

Hi Andy, thank you for your reply! I just checked out the video regarding keyword arguments and I have a better understanding of it.

I am sorry I did not make my question clear. What I wonder is that, since we make the solutioninstance variable on the object clone, why can we call solution on participation?