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 Adding Validations to Todo Items

Micah Goldston
Micah Goldston
5,014 Points

Issue with running rspec for spec/features/todo_items/create_spec.rb

While running the tests related to this video, I'm getting an 'ActionView: MissingTemplate:...' error. Please see below for full prompt screen messaging:

~/treehouse/odot$ bin/rspec spec/features/todo_items/create_spec.rb .

Finished in 0.22113 seconds 1 example, 0 failures

Randomized with seed 21850

~/treehouse/odot$ bin/rspec spec/features/todo_items/create_spec.rb F.

Failures:

1) Adding todo items displays an error with no content Failure/Error: expect(page).to have_content("There was a problem adding that todo list item.") expected to find text "There was a problem adding that todo list item." in "Added todo list itme." # ./spec/features/todo_items/create_spec.rb:31:in block (3 levels) in <top (required)>' # ./spec/features/todo_items/create_spec.rb:30:inblock (2 levels) in <top (required)>'

Finished in 0.2532 seconds 2 examples, 1 failure

Failed examples:

rspec ./spec/features/todo_items/create_spec.rb:25 # Adding todo items displays an error with no content

Randomized with seed 13299

**Here I make the changes perscribed by Jason in the video****

~/treehouse/odot$ bin/rspec spec/features/todo_items/create_spec.rb .F

Failures:

1) Adding todo items displays an error with no content Failure/Error: click_button "Save" ActionView::MissingTemplate: Missing template todo_items/create, application/create with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in: * "/home/micahgoldston/treehouse/odot/app/views" # ./spec/features/todo_items/create_spec.rb:29:in `block (2 levels) in <top (required)>'

Finished in 0.25323 seconds 2 examples, 1 failure

Failed examples:

rspec ./spec/features/todo_items/create_spec.rb:25 # Adding todo items displays an error with no content

Randomized with seed 31925

Any help would be appreciated.

2 Answers

Nick Fuller
Nick Fuller
9,027 Points

What is happening is you're using an http GET route to your create action in your controller. Rails then thinks you want to render some HTML, so it looks for the matching create.html.erb file in the views/todos directory. But since it didn't find the file, it throws the MissingTemplate error.

You most likely want to call the new action (new_todo_path).

It would be more helpful to see the contents of your todo_items/create_spec.rb file

Micah Goldston
Micah Goldston
5,014 Points

Hey Nick,

Thanks a lot for the response, and my apologies for the delayed response. I tried adding the 'new' action in the todo_items controller create method but not go. Where exactly would I call this new action you speak of. As you requested, here's the contents of my todo_items/create_spec.rb file:

require 'spec_helper'

describe "Adding todo items" do let!(:todo_list) { TodoList.create(title: "Grocery List", description: "Groceries" ) }

it "is successful with valid content" do
    visit_todo_list(todo_list)
    click_link "New Todo Item"
    fill_in "Content", with: "Milk"
    click_button "Save"
    expect(page).to have_content("Added todo list item.")
    within("ul.todo_items") do
        expect(page).to have_content("Milk")
    end
end

it "displays an error with no content" do
    visit_todo_list(todo_list)
    click_link "New Todo Item"
    fill_in "Content", with: ""
    click_button "Save"
    within("div.flash") do
    expect(page).to have_content("There was a problem adding that todo list item.")
    end
    expect(page).to have_content("Content can't be blank")
end

it "displays an error with content less than 2 characters long" do
    visit_todo_list(todo_list)
    click_link "New Todo Item"
    fill_in "Content", with: "1"
    click_button "Save"
    within("div.flash") do
    expect(page).to have_content("There was a problem adding that todo list item.")
    end
    expect(page).to have_content("Content is too short")
end

end