RSpec Delivery
RSpec Delivery is a gem designed to post to a web-service the results of your rspec test. (still in development)
Installation
Add this line to your application's Gemfile:
gem 'rspec_delivery'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rspec_delivery
Usage
Setting the Formatter
Once you have the RSpec Delivery gem installed, you need to specify 'RspecDelivery' as the formatter to be used when running your rspec tests.
in a Rakefile:
RSpec::Core::RakeTask.new do |t|
t.rspec_opts = "-r post_rspec/formatter -f RspecDelivery::Formatter"
end
or within your .rspec file:
--format RspecDelivery::Formatter
--color
or from the command line:
rspec -r rspec_delivery/formatter --format RspecDelivery::Formatter --color
or from within your spec_helper.rb
require 'rspec_delivery/formatter'
RSpec.configure do |config|
config.add_formatter(RspecDelivery::Formatter)
config.color_enabled = true
end
Setting the POST endpoint
You also need to add a config var within the Rspec.config block to specify an endpoint to post to:
RSpec.configure do |config|
config.add_setting :rspec_delivery_endpoint
config.rspec_delivery_endpoint = 'http://localhost:3000/...'
end
Response / Summary
Once your rspec suite finishes running, it will send a POST to your specified endpoint with a body that looks like:
{
"rspec_data"=>{
"duration"=>184.146366,
"example_count"=>9,
"failure_count"=>4,
"pending_count"=>0
},
"errors"=>[
{
"description"=>"Example description #1...",
"status"=>"failed",
"run_time"=>15.583829,
"file_path"=>"./spec/models/example_1.rb",
"line_number"=>"10"
}, {
"description"=>"Example description #2",
"status"=>"failed",
"run_time"=>22.671084,
"file_path"=>"./spec/controllers/example_2.rb",
"line_number"=>"38"
},
....
],
"successes"=>[
{
"description"=>"Example description #3",
"status"=>"passed",
"run_time"=>22.481478,
"file_path"=>"./app/specs/models/example_3.rb",
"line_number"=>"5"
},
....
],
"pending"=>nil
}
After the POST is sent, a message will be displayed within your terminal that contains the rspec suite summary (total time spent running tests, number of tests, number of failed tests, number of pending tests, and success rate) and two additional line items including the server response status and the server response body.
TODO
- error handling
- still needs some stabilization / refactoring
- would like to setup a config block to set things like endpoint, config vars, etc...
- would like to setup the ability to send an email instead of http POST
- setup other HTTP methods (such as 'GET')
- ability to customize POST body
Contributing
- Fork it
- 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 new Pull Request