-
Notifications
You must be signed in to change notification settings - Fork 246
Chapter 6: Capybara initial test fails #92
Comments
Could you share a copy of your Gemfile.lock as it exists to this point, along with your Ruby version ( |
I'm on macOS 10.13.6 using Ruby 2.5.1p57 through RVM. Gemfile.lock:
And I used this branch: https://github.com/everydayrails/everydayrails-rspec-2017/tree/01-untested |
It's happening again with the subsequent test to check a task and see that it completed and then unchecking to see that it's back to be incomplete (pages 101-103).
I've done some subsequent research and it appears this is an issue with So in the code above, I changed the I guess that's where the scoping could come into play but given how weird |
I was planning to dig into this over the weekend, but at what point did you switch to 5.2? The app is built and tested on 5.1. I always recommend having a test suite in place before upgrading Rails versions. |
I finished the chapter and am curious about the output from adding additional tasks to this feature spec for completing/un-completing tasks: I made four tasks total:
And all are being output as expected:
But each task has the same
It's never a good idea to have duplicate
The test always fails because it can't find tasks using that ID structure. When I try to So we really have to have the same |
I've been using Rails 5.2 the entire time. |
For the purposes of this book, I think you'll have a better time with it if you stick to gem versions as defined in the sample code's Gemfile.lock, including Rails 5.1. My approach to learning TDD is to write. tests for code that's already been browser-tested. Once you're more comfortable writing tests, flip it around to a test-first approach that typically comes with TDD (see chapter 11). I can't guarantee that newer versions of Rails or any other dependencies will work with the sample app. Due to the process and time commitment involved with building up the sample app and tests chapter by chapter, I don't usually redo everything for every minor-level Rails release. But once a test suite is in place for an earlier version of Rails, it can help with the upgrade process for Rails or any other dependency. This is the approach I take with real-world, production apps.
You're right, this is an issue with the code that something in my version of the dependencies doesn't catch, but maybe something in Rails 5.2 is less permissive. (I first suspected a difference in Capybara versions, but that doesn't appear to be the case.) You could fix the application code with something like
But I would also be curious to see how things behave by basing the sample app on Rails 5.1. |
For the sake of completing the book, I've just moved forward by using the Rails-generated names of fields instead of trying to find them by their label text value. Such an odd discrepancy in Rails. The rest of the book has been great and extremely helpful. I stopped getting hung up on the Capybara stuff because I remembered I'll be doing the front end of any projects in React, so the Capybara functionality would be skipped in favor of React testing via Jest and Enzyme. For what it's worth, I've made a few changes to the test suites to account for the output differences between 5.2 and 5.1 (the original functions can be found on page 142 and 143):
And then the corresponding scenarios were changed to:
(I expanded on the book examples by adding 3 more tasks and updating their variable names accordingly). This works and hopefully it can be helpful for someone else in the future should they get stuck on this. Thanks for writing the book and finally making TDD make sense! |
For anyone googling: the way i solved this problem is by passing
|
I am completely baffled by this and the fact I cannot find any information about how to do this is downright infuriating.
Using the following scenario from pages 95-96:
I repeatedly get:
As you can see above, I moved a little further along in the chapter and added in the
save_and_open_page
code afterclick_link "New Project"
to see what is going on. And this is the HTML that's output on the page:So the label and field are there as expected. And I then looked at the project/_form.html.erb file to confirm that it does, in fact, associate the labels and fields:
Yet, there's no
for
attribute on either rendered HTML label associating the label with the field the label is getting its text value from. And I can find absolutely nothing explaining what magic is needed to make that happen. Rails docs show examples of fields setup the exact same way with the correspondingfor
attribute output on thelabel
yet not on this form. And when I move thesave_and_open_page
line up underclick_link "Sign in"
(since there's no issue getting that form filled in and moving on), I see this rendered HTML:which comes from this code found in views/devise/sessions/new.html.erb:
So somehow, basically identical code is outputting differently for no reason I can discern. And because of this, it's making the provided test scenario in the book impossible to follow because it doesn't behave as expected.
Given that on page 101 under the Testing JavaScript interactions header it says "So we’ve verified, with a passing spec, that our user interface for adding projects is working as planned." either something is totally different with how Rails works since the book was last updated, or something in the code or book or both necessary to make this work as presented in the book is missing.
I've found through Stack Overflow that changing:
to:
Works and I've confirmed it does and the tests pass since those are the actual
name
s of the fields, but that's not the point: I shouldn't have to do that because these labels should have a properfor
attribute on them, yet they do not and it's seemingly impossible to get that attribute on the Rails-generated label.This is the exact kind of stuff that has happened every single time I've attempted to learn TDD and is the exact reason I ultimately gave up on Rails four years ago after using it for 9 years. Simple stuff that shouldn't even be a thought doesn't work the way the book/guide/video I'm following says it should and instead of writing tests that are actually confirming functionality and providing peace of mind, I'm trying to figure out why something so painfully basic and completely unrelated to the test isn't happening and thus causing the test to fail.
The text was updated successfully, but these errors were encountered: