Why can't you drown right away! layout of objects?

I may be something completely obvious here, but why should I do this:

setup do
  @person = mock("person")
  @person.stub!(:name).and_return("david")
end

Instead

@person = mock("person").stub!(:name).and_return("david")

What is a false ("string") return that does not allow it to be truncated compared to allowing @person to be truncated? Is mock not an object return (maybe it just modifies some internal hash table from mock'ed out and then returns a separate object?

+3
source share
2 answers

Because the call and_returndoes not return a stub object. mockdoes.

-, , , . mock("person").stub!..., . , and_return .

+3

Peter, @person and_return, . Proc.

:

@person = mock("person").tap {|obj| obj.stub!(:name).and_return("david") }

, :

@person = mock("person", :name => "david")
+3

Source: https://habr.com/ru/post/1785070/


All Articles