I'm not sure if I quite get what you are saying.

The example code is a re-write from trying to avoid calling any_instance. 
 Maybe this will be clearer with the original code below.

def create_accounts(epoch, start_time)
  vendors = Vendor.new_vendors(start_time)
  vendors.each do |vendor|
    ProspectAccount.new(vendor).create(epoch)
  end
end

What I was trying to test was that in create_accounts, if 
Vendor.new_vendors returns a collection of some vendor objects, the 
create_accounts will call the ProspectAccount#create method.

To avoid using any_instance, I rewrote the call inside the loop to 
ProspectAccount.create_from_vendor(epoch, vendor), but that only moves the 
problem to the create_from_vendor method.  It does help that when testing 
the create_from_vendor method, I will only be dealing with one vendor, 
instead of looping through a collection of vendors.

The create method actually does some complicated stuff.  It writes data to 
a Redis database, and then makes a web service call to a queuing system. 
 What create actually should do is tested in other tests.

What I need to test is that create_accounts calls the ProspectAccount#create 
method.

I don't think your response helps me test that create is called, while 
stubbing out the already tested and complicated implementation of the 
create method.


I am gleaming from your response is that you would test that what happens 
in create would be tested in the create_accounts test, rather than testing 
that ProspectAccount#create is called.  That seems to me that you would 
test the functionality of the ProspectAccount#create method in the 
create_accounts test.  Then do you test the functionality of the 
create_accounts method in the test of the method which calls 
create_accounts?


BTW, The create is not the ActiveRecord create.  Also we are not using 
Rails, just ruby.  We don't have a view.  The closest we come to a 
controller object/class is the class that the create_accounts method is in. 
 Say for the sake of argument, that that class is named BatchController.




>

-- 
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 rspec+unsubscr...@googlegroups.com.
To post to this group, send email to rspec@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/87099f16-88f8-423f-a009-41f5598bb7a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to