rspec-statsd 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +7 -0
- data/lib/rspec-statsd.rb +16 -0
- data/lib/rspec-statsd/formatter.rb +25 -0
- data/lib/rspec-statsd/version.rb +5 -0
- data/rspec-statsd.gemspec +24 -0
- data/spec/formatter_spec.rb +46 -0
- data/spec/rspec-statsd_spec.rb +14 -0
- data/spec/spec_helper.rb +14 -0
- metadata +131 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Grzesiek Kolodziejczyk
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# RSpec::Statsd
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/grk/rspec-statsd.png)](http://travis-ci.org/grk/rspec-statsd)
|
4
|
+
|
5
|
+
|
6
|
+
RSpec::Statsd provides a way to measure rspec runs in statsd. It uses the
|
7
|
+
[http_statsd](https://github.com/grk/http_statsd/) gem to send the results
|
8
|
+
over HTTP to a http statsd proxy.
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
Add the gem to your Gemfile, and add the following lines to your spec_helper.rb:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
RSpec::Statsd.base_uri = "http://statsd.example.com"
|
16
|
+
RSpec::Statsd.username = "api1"
|
17
|
+
RSpec::Statsd.password = "pass1"
|
18
|
+
RSpec::Statsd.metric = "some-test"
|
19
|
+
|
20
|
+
RSpec.configure do |config|
|
21
|
+
config.add_formatter("progress")
|
22
|
+
config.add_formatter(RSpec::Statsd::Formatter)
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
The Formatter will send the following metrics to statsd when a suite is ran:
|
27
|
+
|
28
|
+
* `some-test.duration` - timing with the duration of the rspec run
|
29
|
+
* `some-test.count` - counter will be incremented
|
30
|
+
|
31
|
+
Additionally, when the suite has no errors:
|
32
|
+
|
33
|
+
* `some-test.success.duration` - timing with the duration of the rspec run
|
34
|
+
* `some-test.success.count` - counter will be incremented
|
35
|
+
|
36
|
+
And when the suite has errors:
|
37
|
+
|
38
|
+
* `some-test.failure.duration` - timing with the duration of the rspec run
|
39
|
+
* `some-test.failute.count` - counter will be incremented
|
data/Rakefile
ADDED
data/lib/rspec-statsd.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "rspec-statsd/version"
|
2
|
+
require "rspec-statsd/formatter"
|
3
|
+
require "http_statsd"
|
4
|
+
|
5
|
+
module RSpec
|
6
|
+
module Statsd
|
7
|
+
extend self
|
8
|
+
|
9
|
+
attr_accessor :base_uri, :username, :password, :metric
|
10
|
+
|
11
|
+
def client
|
12
|
+
@client ||= HttpStatsd::Client.new(:base_uri => base_uri,
|
13
|
+
:username => username, :password => password)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rspec/core/formatters/base_formatter'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Statsd
|
5
|
+
class Formatter < RSpec::Core::Formatters::BaseFormatter
|
6
|
+
def dump_summary(duration, example_count, failure_count, pending_count)
|
7
|
+
result = failure_count == 0 ? "success" : "failure"
|
8
|
+
|
9
|
+
client.gauge("#{metric}.duration", duration)
|
10
|
+
client.increment("#{metric}.count")
|
11
|
+
client.gauge("#{metric}.#{result}.duration", duration)
|
12
|
+
client.increment("#{metric}.#{result}.count")
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def client
|
17
|
+
RSpec::Statsd.client
|
18
|
+
end
|
19
|
+
|
20
|
+
def metric
|
21
|
+
RSpec::Statsd.metric
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rspec-statsd/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "rspec-statsd"
|
8
|
+
gem.version = RSpec::Statsd::VERSION
|
9
|
+
gem.authors = ["Grzesiek Kołodziejczyk"]
|
10
|
+
gem.email = ["gk@code-fu.pl"]
|
11
|
+
gem.summary = "Report status and duration of RSpec runs to statsd"
|
12
|
+
gem.homepage = "https://github.com/grk/rspec-statsd/"
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.add_runtime_dependency "rspec-core", "~> 2.0"
|
20
|
+
gem.add_runtime_dependency "http_statsd"
|
21
|
+
|
22
|
+
gem.add_development_dependency "rspec", "~> 2.11"
|
23
|
+
gem.add_development_dependency "rake"
|
24
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RSpec::Statsd::Formatter do
|
4
|
+
let(:formatter) { RSpec::Statsd::Formatter.new(nil) }
|
5
|
+
let(:client) { mock(HttpStatsd::Client).as_null_object }
|
6
|
+
|
7
|
+
before do
|
8
|
+
formatter.stub(:client => client)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "dump_summary" do
|
12
|
+
it "should measure duration" do
|
13
|
+
client.should_receive(:gauge).with("sample-test.duration", 12.3)
|
14
|
+
formatter.dump_summary(12.3, 10, 0, 0)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should count runs" do
|
18
|
+
client.should_receive(:increment).with("sample-test.count")
|
19
|
+
formatter.dump_summary(12.3, 10, 0, 0)
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when suite is successful" do
|
23
|
+
it "should measure successful duration" do
|
24
|
+
client.should_receive(:gauge).with("sample-test.success.duration", 12.3)
|
25
|
+
formatter.dump_summary(12.3, 10, 0, 0)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should count successful runs" do
|
29
|
+
client.should_receive(:increment).with("sample-test.success.count")
|
30
|
+
formatter.dump_summary(12.3, 10, 0, 0)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when suite has failures" do
|
35
|
+
it "should measure failed duration" do
|
36
|
+
client.should_receive(:gauge).with("sample-test.failure.duration", 12.3)
|
37
|
+
formatter.dump_summary(12.3, 9, 1, 0)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should count failed runs" do
|
41
|
+
client.should_receive(:increment).with("sample-test.failure.count")
|
42
|
+
formatter.dump_summary(12.3, 9, 1, 0)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RSpec::Statsd do
|
4
|
+
describe "client" do
|
5
|
+
it "should return a HttpStatsd::Client" do
|
6
|
+
client = mock
|
7
|
+
HttpStatsd::Client.should_receive(:new).with(:username => "api1",
|
8
|
+
:password => "pass1", :base_uri => "http://statsd.example.com").
|
9
|
+
and_return(client)
|
10
|
+
|
11
|
+
RSpec::Statsd.client.should eql(client)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require 'rspec-statsd'
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.color_enabled = true
|
8
|
+
config.before(:suite) do
|
9
|
+
RSpec::Statsd.base_uri = "http://statsd.example.com"
|
10
|
+
RSpec::Statsd.username = "api1"
|
11
|
+
RSpec::Statsd.password = "pass1"
|
12
|
+
RSpec::Statsd.metric = "sample-test"
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-statsd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Grzesiek Kołodziejczyk
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec-core
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: http_statsd
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.11'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.11'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description:
|
79
|
+
email:
|
80
|
+
- gk@code-fu.pl
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- .travis.yml
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- lib/rspec-statsd.rb
|
92
|
+
- lib/rspec-statsd/formatter.rb
|
93
|
+
- lib/rspec-statsd/version.rb
|
94
|
+
- rspec-statsd.gemspec
|
95
|
+
- spec/formatter_spec.rb
|
96
|
+
- spec/rspec-statsd_spec.rb
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
homepage: https://github.com/grk/rspec-statsd/
|
99
|
+
licenses: []
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
hash: 1491068059829848855
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
segments:
|
120
|
+
- 0
|
121
|
+
hash: 1491068059829848855
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 1.8.24
|
125
|
+
signing_key:
|
126
|
+
specification_version: 3
|
127
|
+
summary: Report status and duration of RSpec runs to statsd
|
128
|
+
test_files:
|
129
|
+
- spec/formatter_spec.rb
|
130
|
+
- spec/rspec-statsd_spec.rb
|
131
|
+
- spec/spec_helper.rb
|