Skip to content

CRUD Capybara Testing

Tung Nguyen edited this page Jan 21, 2018 · 4 revisions

CRUD: Capybara Testing

To spare from mundane work, some of the CRUD can be tested with selenium. Here's the code in a gist.

Usage

Run:

jets new store
cd store
bundle
jets generate scaffold Post title:string
jets db:create db:migrate
mkdir -p spec/features
curl -o spec/features/posts_spec.rb https://gist.githubusercontent.com/tongueroo/aab399b6d497c0aa57ba603626a213ca/raw/c727ad5d52220a1ab0fa0259247124a86326e275/posts_spec.rb
bundle exec rspec

That will test all CRUD except DELETE. Delete must be tested manually still.

Remote Testing

You can use the same spec to test a remote host that is on API Gateway by setting APP_HOST. Example:

APP_HOST=https://8s1wzivnz4.execute-api.us-east-1.amazonaws.com/dev bundle exec rspec

Install

Make sure you have an updated Firefox installation. The capybara test uses the selenium driver and requires Firefox.

Testing Speed

Capybara testing is pretty slow because it opens up a full browser. It is notably slower when using a remote host by setting APP_HOST=xxx. Measured speeds:

  • APP_HOST not set: 5 seconds
  • APP_HOST set: 32 seconds