DEV Community

Augusts Bautra
Augusts Bautra

Posted on

Make your feature specs 69%™ more stable

These past couple of weeks we've been improving our existing feature spec suite to prepare it for switching over to --headless=new chrome option.
Several of the existing specs had to be updated with proper awaiting, for example

click_button "Update"

expect(record.reload.field).to eq("new value")
Enter fullscreen mode Exit fullscreen mode

oftentimes failed because the button click hadn't been fully processed yet, so

click_button "Update"

expect(page).to have_flash_message("Update successful")

expect(record.reload.field).to eq("new value")
Enter fullscreen mode Exit fullscreen mode

Another source of deeper fragility was the behavior of .set and fill_in - sometimes, especially if an input already had a value, the new value would either be appended or not inputted at all.

We significanly reduced the incidence of these fails by specifying a clear option like this:

config.before(:each, :js) do
  Capybara.default_set_options = { clear: :backspace }
end
Enter fullscreen mode Exit fullscreen mode

Top comments (0)