RSpec Dispatch
RSpec Dispatch is a simple gem that replaces your default RSpec Formatter to send results from a test run to a web service of your choice. Useful to track RSpec suite results overtime through a custom web application (or endpoint).
Installation
Add this line to your application's Gemfile:
gem 'rspec_dispatch'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rspec_dispatch
Usage
Setup
To use this custom RSpec Formatter (or any custom formatter), you'll need to set it in your RSpec Config:
RSpec.configure do |config|
config.add_formatter(RspecDispatch::Formatter)
end
Configuration
A variety of configuration options are available for RSpec Dispatch, some optional.
Setup your RSpec Dispatch block (similar to your RSpec.config block):
RspecDispatch.configure do |config|
...
end
Within this config block, a required parameter is "service_url" which is the endpoint that RSpec Dispatch will POST the suite/test results to.
config.service_url = "http://examplehost.com"
Other parameters include:
"verbose" - true/false (boolean) which allows text to be output within the command line when running your test suite.
"custom_data" - (hash) this allows you to dynamically add any hash values to your results before they are sent to your specific web service. Examples might include the current date, a particular build, the environment or other server details, etc...
A full configuration block could look like:
RspecDispatch.configure do |config|
config.service_url = "http://examplehost.com/results"
config.verbose = false
config.custom_data = {author: "Kevin Wanek", date: Date.now}
end
POST Body
When the results from your test run are sent to your web service, that endpoint will recieve a body with the following structure:
{
"custom_data"=>{...},
"rspec_data"=>{
"duration"=>0.003571,
"example_count"=>4,
"success_count"=>2,
"failure_count"=>1,
"pending_count"=>1
},
"failures"=>[
{...}
],
"successes"=>[
{...},
],
"pending"=>[
{...}
]
}
The "failures", "successes", and "pending" values will be arrays filled with data about each example that was executed during your test run. Those will be structured as follows:
{
"description"=>"example test description",
"status"=>"failed",
"run_time"=>0.000421,
"file_path"=>"profile_spec.rb",
"line_number"=>"15"
}
TODO
- Needs the ability to add authentication parameters to POST request
- Clean up tests
- Clean up the Report module (specifically the text output and the #deliver method)
Contributing
- Fork it ( https://github.com/theef/rspec_dispatch/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request