rspec-statsd 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.9.2
5
+ - jruby-18mode
6
+ - jruby-19mode
7
+ - rbx-18mode
8
+ - rbx-19mode
9
+ - 1.8.7
10
+ - ree
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec-statsd.gemspec
4
+ gemspec
@@ -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.
@@ -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
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ desc "run specs"
5
+ RSpec::Core::RakeTask.new
6
+
7
+ task :default => [:spec]
@@ -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,5 @@
1
+ module RSpec
2
+ module Statsd
3
+ VERSION = "0.0.1"
4
+ end
5
+ 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
@@ -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