It really depends on the objects. If that were PORO code I would pass in
mocks for epoch and vendor. I would set my expectations of command methods
on epoch and vendor accordingly as tests that the proper things are done. I
would also check the public state of the returned object to ensure it was
what I expected.

Now I’m guessing by the naming this is ActiveRecord related. In that case,
if epoch and vendor are other AR objects, I would likely let this method
hit the database. I would then set my expectations on the public API of the
returned object (as above), I would also check the state in the database,
and the state of the collaborators if applicable.

Now, when using this method, in say a controller spec, I would allow myself
to stub it out (since it is *your* API): allow(ThatObjectClass).to
receive(:create_from_vendor).and_return(this_mock_or_built_model).
​

On Thu, May 28, 2015 at 11:43 AM, Marlin Pierce <[email protected]>
wrote:

> I saw the official discouragement of using expect_any_instance_of
> and allow_any_instance_of on the page:
>
>
> https://relishapp.com/rspec/rspec-mocks/docs/working-with-legacy-code/any-instance
>
> So, what should I do when I have a method which calls new to get a new
> object of a class,
> and then calls a method on that new object?  I want to stub the method
> call,
> because it does some complicated things which external resources,
> and I want to have an expectation that the method is called.
>
>   def self.create_from_vendor(epoch, vendor)
>     new(vendor).create(epoch)
>   end
>
> Is there a way I need to rewrite my code to test this better?
> Is this a smell?
>
>  --
> You received this message because you are subscribed to the Google Groups
> "rspec" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rspec/60034cee-8d5d-4053-ba10-1816a6c4ef03%40googlegroups.com
> <https://groups.google.com/d/msgid/rspec/60034cee-8d5d-4053-ba10-1816a6c4ef03%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/CAKCESdi%3D7a4kPC5HqGjy4_UzGHw6pitr6jSw-zZn_OhQChFdCQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to