need some guidance with a test
This is part of a rails project. The following method is part of the Ams class (a rails model). I'm a bit unsure of the rspec/bdd way of testing this method.
def persist_as_domains
@current_domains.each do |d|
dom = Domain.new
dom.domain = d
dom.source_id = 1
dom.at = Time.now
dom.save
end
end
The following is what came out when I tried to write my test. Notice that the only thing I'm testing here is that each method is called a certain number of times. This doesn't test that the proper values are passed to the Domain model which is something I'd like to test, but I don't know how to do that since the methods are called in a loop with a different value each time. Am I even approaching this the right way?
context "persisting as Domain" do
setup do
@ams = Ams.new
@ams.get
@ams.process
puts Domain.class
Domain.should_receive(:new).exactly(10).times
Domain.should_receive(:domain).exactly(10).times
Domain.should_receive(:source_id).exactly(10).times
Domain.should_receive(:at).exactly(10).times
Domain.should_receive(:save).exactly(10).times
puts Domain.class
end
specify "should create new domain and save" do
@ams.persist_as_domains
end
end