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 trialRachelle Wood
15,362 PointsI just don't get this
Hi all,
I have a mystery to solve. I have been banging my head over this for the past hour. I can't get the create_spec.rb to work with the code shown in the video. I am using rspec 2.99.
When I ran the first two tests, I kept getting failures. Rspec told me that it did not recognize the methods. After some trial and error, I realized that it was the expect(page).to have_content("stuff") statements in the code that were causing the problem. I had to replace them with page.has_content?("stuff") instead. Then it worked fine.
The last test passed with expect(TodoList.count).to eq(0).
It looks like Rspec 2.99 supports expect.to blah blah, so what gives? I would like this to work with something that ressembles the code that the instructor gave in the video since it seems like the page.has_content? method is going to become deprecated at some point?
4 Answers
Seth Reece
32,867 PointsAhh, you need a capital L on List in your test. you are expecting the page to have content "New Todo list" but your test is finding "New Todo List".
Seth Reece
32,867 PointsHi Rachelle,
expect(page).to have_content 'stuff'
is the current capybara syntax in the docs.
expect(page).to have_content('stuff')
should still work though.
page.has_content?('stuff')
is syntax for the gem cucumber. Are you are using
assert page.has_content?('stuff')
If not you might be getting a false pass. What are the no method errors you are getting? You might have an undefined method, or a method that is not being set properly and returning nil.
Rachelle Wood
15,362 PointsHi. Thanks for your answer. I looked in my Gemfile but I don't see the cucumber gem in it. I also did not add assert to my statements.
I tried expect(page).to have_content 'stuff' as well and got the same error. I even tried it with "" instead of single quotes.
I tried it again by just changing the first test to have what was originally in the instructor's code and the error message changed (2 examples, 1 failure):
Failures:
1) Creating todo lists redirects to the todo list index page on success
Failure/Error: expect(page).to have_content 'New Todo list'
expected to find text "New Todo list" in "New Todo List Title Description Back"
# ./spec/features/todo_lists/create_spec.rb:7:in `block (2 levels) in <top (required)>'
Rachelle Wood
15,362 PointsOh wow! That is what it was! Thank you for suggesting that. Oddly, on the webpage it was "New Todo list" not "New Todo List", which is why I had it like that in the code. This works now!