mercredi 21 janvier 2015

Need help setting up a method in a feature spec (RSpec)

My program code works as expected, but I need help setting up a method in a feature spec using RSpec (3.1.0) & FactoryGirl. The relevant part of my edit spec is as follows:



require 'rails_helper'

describe "Editing appointments" do

let!(:appointment) { FactoryGirl.create(:appointment) }

def update_appointment(options={})
options[:date] ||= "2018-01-02"
options[:starts_at] ||= "08:00:00"
options[:ends_at] ||= "10:00:00"
options[:member_id] ||= 1
options[:trainer_id] ||= 1

appointment = options[:appointment]

visit "/appointments"
within "#appointment_#{appointment.id}" do
click_link "Edit"
#save_and_open_page
end

select('2018', :from => 'appointment_date_1i')
select('December', :from => 'appointment_date_2i')
select('15', :from => 'appointment_date_3i')
select('10', :from => 'appointment_starts_at_4i')
select('00', :from => 'appointment_starts_at_5i')
select('12', :from => 'appointment_ends_at_4i')
select('00', :from => 'appointment_ends_at_5i')

click_button "Update Appointment"

end

it "updates an appointment successfully with corrected information" do

update_appointment appointment: appointment,

date: '2020-06-11',
starts_at: '08:00:00',
ends_at: '10:00:00'

appointment.reload

expect(page).to have_content ("Appointment was successfully updated.")
expect(appointment.date).to eq("2020-06-11")
expect(appointment.starts_at).to eq("08:00:00")
expect(appointment.ends_at).to eq("10:00:00")

end
end


When I run the spec, RSpec generates the following error message:



1) Editing appointments updates an appointment successfully with corrected information
Failure/Error: expect(appointment.date).to eq("2020-06-11")

expected: "2020-06-11"
got: Sat, 15 Dec 2018

(compared using ==)

Diff:
@@ -1,2 +1,2 @@
-"2020-06-11"
+Sat, 15 Dec 2018


Looks like the appointment is not being updated with new values. I assume this is caused by how I try to call the "update_appointment" method and/or assign new values. I don't know how best to fix the problem. I'd appreciate any help!


Aucun commentaire:

Enregistrer un commentaire