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

rspec failures after completing Odot

The rspecs that we are using in the Odot (todo lists) are failing now that I've completed this section. The failures are:

rspec ./spec/views/todo_lists/index.html.erb_spec.rb:17 # todo_lists/index renders a list of todo_lists rspec ./spec/features/todo_items/create_spec.rb:6 # Adding todo items is sucessful with valid content rspec ./spec/features/todo_items/index_spec.rb:18 # Viewing todo items displays item content when a todo list has items rspec ./spec/features/todo_items/index_spec.rb:6 # Viewing todo items displays the title of the todo list

While the app works, I'd like to clean this up to allow for all the specs to pass. I've included my git link for review. Please assist.

Git for Odot: https://github.com/mnickey/odot.git

4 Answers

Thanks Brandon, this was helpful but I think to solve one of them I may have hacked it. in the views/todo_items.html.erb I had:

<td><%= todo_item.content %></td>
<td>
<%= link_to "Edit", edit_todo_list_todo_item_path(todo_item) %>
<%= link_to "Delete", todo_list_todo_item_path(todo_item), method: :delete, data: { confirm: "Are you sure?" } %>
</td>

I added the class 'item' to the top <td> to read

...
<td class='item'><%= todo_item.content %></td>
...

After that I changed the spec to look for that class with

...
  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("td.item") do
      expect(page).to have_content("Milk")
    end
  end
...

While this passes the rspec test and doesn't bring any further issues in my code, I'm wondering if this is the most efficient way of passing this spec. Any suggestions/advice/comments?

Brandon Barrette
Brandon Barrette
20,485 Points

You have to look at the tests that are failing and see what's making them fail. I had this same issue and it was because we changed the CSS and HTML and our tests were looking for specific text inside an <h1> tag and stuff like that.

If you have specific questions, I'm willing to help, but you have to paste your code and tell us what you've tried to do to make them pass. That's the only way you'll learn to code. You'll spend hours trying, and fail often, but then you start to learn things that no video tutorial could ever teach you.

Brandon Barrette
Brandon Barrette
20,485 Points

You should not need this line:

within("td.item") do 
    expect(page).to have_content("Milk") 
end

Because capybara will look over the whole page to find the word "Milk". It would help if you could paste your whole test here, using the Markdown formatting so we can read it. (See below the input box to learn how to enter code)

Hey, glad this was on here; I ran into the same issue.

The video uses rspec 2.99, but I currently have v3.0.3, (which is now relevant for everyone in the future as of 8/12/14).

To get around this, check out this

    https://github.com/rspec/rspec-activemodel-mocks

Install the

    gem 'rspec-activemodel-mocks'

And

    require 'rspec/active_model/mocks'
faranaway
faranaway
Courses Plus Student 13,885 Points

Thanks!

I was having the same issue with the spec view pages. I knew it had to do something with the current version of rspec since I was using the most current gem.

Curiously, how get to the current provided solution.