I know there is a balance to be struck between writing dry code and damp code but I have the feeling that this is a bit too repeative. Is there a terse yet self explainatory way to rewrite these tests?
class TripTest < ActiveSupport::TestCase
def setup
@trip = trips(:one)
@invoice = invoices(:one)
end
test 'trip can save' do
trip = Trip.new
trip.departure_date = "2040-03-24"
trip.depart_airport = "DHW"
trip.arrive_airport = "ABC"
trip.invoice_id = 123534
assert trip.save, "Error message: #{trip.errors.full_messages}"
end
test "one invoice can have multiple trips" do
trip = Trip.new
trip.departure_date = "2040-03-24"
trip.depart_airport = "DHW"
trip.arrive_airport = "ABC"
trip.invoice_id = 123534
@invoice.trips.push(trip)
@invoice.save
trip = Trip.new
trip.departure_date = "2040-03-24"
trip.depart_airport = "ICN"
trip.arrive_airport = "XYZ"
trip.invoice_id = 123534
@invoice.trips.push(trip)
@invoice.save
assert @invoice.trips.size > 1
end