samedi 29 avril 2017

Rails Integration Testing: Is Capybara necessary for interacting with Javascript?

I'm new to testing in Rails and I'm trying to get into integration testing. I'm working with a Rails 4.2 project. I've written some simple tests in the default Minitest framework and I've quickly got to the point where I need to interact with the html by clicking a button and verifying that a modal appears.

From the research that I've done, it doesn't seem to be possible to to do anything like this with the syntax and driver that comes with Minitest. In order to do this I need to use Caypbara or something equivalent.

Firstly - Is that really the case? is there really no way to test Javascript with the default setup in Rails?

Assuming that is the case, I've pulled in Capybara to my project to utilize it's DSL and drivers for testing Javascript, but in doing so, it has rendered my initial tests useless. They no longer work as the Capybara DSL overwrites the assert_select method, forcing me to use Capybara syntax for writing tests - not something that I'm against, I'm just figuring this out.

So it seems like that if I ever want to test Javascript, then I need to use Capybara? and if I pull in Capybara then all my tests need to use Capybara snytax? If this is true, then it seems like I should just use Capybara from the get-go on all projects.

Aucun commentaire:

Enregistrer un commentaire