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 Cleaning Up Our View

Tomasz Jaśkiewicz
Tomasz Jaśkiewicz
5,399 Points

What's wrong with "5.minutes.ago" in complete_spec.rb?

Hey guys. I encountered some strange errors.

I have this context block in complete_spec.rb:

    context "with completed items" do
        let!(:completed_todo_item) { todo_list.todo_items.create(content: "Honey", completed_at: Time.now) }

        it "shows completed items as complete" do
            visit_todo_list(todo_list)
            within dom_id_for(completed_todo_item) do
                expect(page).to have_content(completed_todo_item.completed_at)
            end
        end

        it "does not give the option to mark complete" do
            visit_todo_list(todo_list)
            within dom_id_for(completed_todo_item) do
                expect(page).to_not have_content("Mark Complete")
            end
        end         
    end

I had to change this line:

let!(:completed_todo_item) { todo_list.todo_items.create(content: "Honey", completed_at: "5.minutes.ago") }

to:

let!(:completed_todo_item) { todo_list.todo_items.create(content: "Honey", completed_at: Time.now) }

Because it turned out that first let! produces such error during test:

 1) Editing todo items with completed items does not give the option to mark complete
     Failure/Error: expect(page).to_not have_content("Mark Complete")
       expected not to find text "Mark Complete" in "Honey Mark Complete Edit Delete"
     # ./spec/features/todo_items/complete_spec.rb:30:in `block (4 levels) in <top (required)>'
     # ./spec/features/todo_items/complete_spec.rb:29:in `block (3 levels) in <top (required)>'

"Honey Mark Complete Edit Delete" - it seems like completed_todo_item.completed_at is empty. On the other hand when I use Time.now it works perfectly.

Could someone explain it to me? Because I have no idea what's going on.

1 Answer

I think the problem is the "" at 5.minutes.ago, ...that turns it into a string while you probably want to get a value that signifies time. Try omitting the quotation marks from it and see if it helps.