rails_helper.rb
bundle exec rspec spec/features/hello_world_spec.rb
js: true
on line 3!expect(page).to have_content("hello world!")
therefore may take up to 2000ms to become truthy without breaking the spec. Following the documentation of Capybara, you can adjust the default wait time or set it individually on specific expectations. This built-in wait mechanism is especially useful when working with features requiring client-server communication, like page transitions, form or action submissions!matestack_form
used for creating new User
ActiveRecord Model instances:expect(page).to have_content("succeeded!")
after click "submit me"
the spec would fail. The User.count
would be executed too early! You somehow need to use Capybara's built-in wait mechanisim in order to identify a successful asynchronous form submission. Otherwise the spec would just click the submit button and immediately expect a database state change. Unlike Capybara, plain Rspec expectations do not wait a certain amount of time before failing! Gems like https://github.com/laserlemon/rspec-wait are trying to address this issue. In our experience, you're better of using Capybara's built-in wait mechanism like shown in the example, though.sleep
after a visit
in your spec, you can request the same page, your spec would visit in you local browser and review what's going on there by manually executing the steps your spec would perform while reviewing the DOM and browser debugging tools:localhost:33123/xyz
for example.