DockTest Gem
Description
DockTest is an outside-in testing framework for ruby service api applications.
Features
Different from the popular Rack::Test, DockTest focuses on just on service applications and tests 100% from outside.
- 100% end-to-end as it is based on HTTP requests/responses. When testing in local mode, it also racks up the local rack server.
- same tests can run for all deployment environments - development, test, staging, and production.
- environment-specific
skippy
setting to automatically skip tests with requests that create side-effects in production environments. - focuses on service applications to strip out sessions, cookies, javascript, file uploads, and other browser-related features.
- provides custom assertions that are specific to api responses, including schema validation.
- same methods as Rack::Test for easy test reuse.
- support for OAuth requests
- support for displaying equivalent curl command using
OUTPUT_CURL
environment variable. - support for script_name localhost testing.
- support
verify_ssl
for specifying whether to enforce ssl verification in http connection. Optional, default is true.
Sample Application
- newark app: https://github.com/jackxxu/sample_dock_tested_app
- grape app: https://github.com/jackxxu/grape_dock_tested_app
- rails-api app: https://github.com/jackxxu/rails_api_dock_tested_app
Install
Add this line to your application's Gemfile:
group :test do
gem 'dock_test'
end
And then execute:
$ bundle
In your test helper file (often test/test_helper.rb
), include the following DockTest configuration:
DockTest.configure do |c|
case ENV['DOCK_ENV']
when 'production'
c.url = 'http://vast-reaches-9635.herokuapp.com/' # your production service url
c.skippy = true
else
c.url = 'http://localhost:9871' # your local service url with abitary unbound port number
c.skippy = false
end
end
Add include DockTest::Methods
to give your integration tests access to all the verb test methods and also assertions.
Now you can excute your test collectively or individually, such as:
$ bundle exec rake test
$ DOCK_ENV=production bundle exec rake test
Assumptions
- when testing local application, a
config.ru
exists that can be used torackup
the server.