Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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,441 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,441 Points

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