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 Writing Test Helpers

Changing from <ul> to <table> causes rspec errors?

In the lecture this change was made and no rspec test was attempted. However, apparently 2 failures result from this:

Failure/Error: within("ul.todo_items") do
Failure/Error: expect(page.all("ul.todo_items li").size).to eq(2)
...
rspec ./spec/features/todo_items/create_spec.rb:6 # Adding todo items is successful with valid content
rspec ./spec/features/todo_items/index_spec.rb:18 # Viewing todo items displays item content when a todo list has items

What's the best way to fix them? Would the followings be good ok? [1] create_spec.rb within("table.todo_items") do [2] index_spec.rb expect(page.all("table.todo_items td").size).to eq(4) within "table.todo_items" do

4 Answers

At any point after the lesson of "Writing Test Helpers", anyone should see the "ul vs table" errors if you run "bin/rake". I think it's a defect of this course to run the extaustive test just in the begining and dimishingly doing so in the latter lessons.

The fixes temporarily work at that moment; however, later in the lecture, other tables are introduced and hence they lose uniqueness as the table so that the rspec eventually fails as below:

  1) Adding todo items is successful with valid content
     Failure/Error: within("table.todo_items") do
     Capybara::Ambiguous:
       Ambiguous match, found 2 elements matching css "table.todo_items"
     # ./spec/features/todo_items/create_spec.rb:13:in `block (2 levels) in <top (required)>'

  2) Viewing todo items displays item content when a todo list has items
     Failure/Error: within "table.todo_items" do
     Capybara::Ambiguous:
       Ambiguous match, found 2 elements matching css "table.todo_items"

There must be a better solution. Anyone?

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

When this happens, you can either give a unique class to that table in the view and in the test or search the whole page, not just the table.

The wrong answer to this question is "try and resolve it yourself, if it doesn't work post on the forums."

This is a change the instructor made to his own code and should have been addressed in the video series. If they didn't want to re-record the video to correct the error then they should have at a minimum added teacher's notes to each specific video this effected with the correct changes that should be made to the rspec and view files.

This is one change from a ul element to a table element causes several tests to fail. Isn't the whole point of TDD which is advocated in this and other rails paths to perform the tests and correct the errors? A change was made to the code without running the full respec tests (which would have shown the error). This flaw makes this series come across very unpolished and needs to be corrected with teacher notes.

Thank you, Maciej. I only understand your fix in theory, but I'm not knowledgable enough to implement your fix. I need the fix that is detailed for beginners.

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

OK, can you publish the code for the whole spec file and the view it concerns? I cna then show you suggested modifications that should work.