ruby - Test method that was called from other method -
i have module database method generate_from_database spins loops , calls method get_length. how can test if get_length called n times, using rspec or mocha?
module database class length < activerecord::base def get_length(i,j) ... end end def database.generate_from_database ... in 0...size j in 0...size length.new.get_length(i+1,j+1)) end end
this:
mock_length = mock("length") length.should_receive(:new).exactly(n).times.and_return(mock_length) mock_length.should_receive(:get_length).exactly(n).times
should work.
Comments
Post a Comment