Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Deleting Todo Lists

Error when running destroy test

require 'spec_helper'

describe "Destroy medication reminder" do
    medication_reminders = MedicationReminder.create(medication: "My Medication Name")

    it "Destroys the medication reminder if successful" do
        visit "/medication_reminders"

        within "#medication_reminder_#{medication_reminders.id}" do
            click_link "Destroy"
        end
        expect(page).to_not have_content(medication_reminder.medication)
        expect(MedicationReminder.count).to eq (0)
    end
end

My scaffold was created with the name 'medication_reminders'. Can't quite figure out why the test is failing. It appears to be failing at the 'to_not have_content' portion of the code.

3 Answers

Max Alexander
Max Alexander
7,258 Points

Just going to throw an answer out there, if it's not helping just ignore me!

Currently you have typed in medication_reminder, but everywhere else you have it as medication_reminders

expect(page).to_not have_content(medication_reminder.medication)

It could be a simple spelling mistake? The following example has fixed the spelling error.

expect(page).to_not have_content(medication_reminders.medication)

That was it! Big thanks!

That was it! Big thanks!

That was it! Big thanks!

Max Alexander
Max Alexander
7,258 Points

No problem Jeremy! Glad to help :)

I'm pretty new at this, but I wonder: do you need a line of code that includes a reload in order to check if the content is gone?

Maciej Czuchnowski
Maciej Czuchnowski
36,437 Points

Try removing the space after eq in this line:

expect(MedicationReminder.count).to eq (0)

so it should look like this:

expect(MedicationReminder.count).to eq(0)
Maciej Czuchnowski
Maciej Czuchnowski
36,437 Points

By the way, if this doesn't help, please paste your error here. It will help a lot in pinpointing the cause :)