rspec_dispatch 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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e8ed694a594802d2f2016b151d3cf02d9103857b
4
+ data.tar.gz: 15c97e6f514faf63afcea178a94040b2f750875e
5
+ SHA512:
6
+ metadata.gz: 50bd69bb1c595679aa02a7dc2e93ef40089262da1ddf7436196622e871d9aae52578148d8018f4622b528271ee757095cd4e60f483c1262f8823b6a05a258153
7
+ data.tar.gz: f965dae1cf4d644003007e9d4b9200d68a2d4ff91a3456fcaa7f6d329d327439bf2e5145abbadb4bf9c762cd402b4b79a120d2d33ec6ef06c430a022ed13b5ee
Binary file
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 theef
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,101 @@
1
+ # RSpec Dispatch
2
+
3
+ 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).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rspec_dispatch'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rspec_dispatch
18
+
19
+ ## Usage
20
+
21
+ #### Setup
22
+ To use this custom RSpec Formatter (or any custom formatter), you'll need to set it in your RSpec Config:
23
+ ```ruby
24
+ RSpec.configure do |config|
25
+ config.add_formatter(RspecDispatch::Formatter)
26
+ end
27
+ ```
28
+
29
+ #### Configuration
30
+ A variety of configuration options are available for RSpec Dispatch, some optional.
31
+ Setup your RSpec Dispatch block (similar to your RSpec.config block):
32
+ ```ruby
33
+ RspecDispatch.configure do |config|
34
+ ...
35
+ end
36
+ ```
37
+
38
+ Within this config block, a required parameter is "service_url" which is the endpoint that RSpec Dispatch will POST the suite/test results to.
39
+ ```ruby
40
+ config.service_url = "http://examplehost.com"
41
+ ```
42
+
43
+ Other parameters include:
44
+ "verbose" - true/false (boolean) which allows text to be output within the command line when running your test suite.
45
+ "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...
46
+
47
+ A full configuration block could look like:
48
+ ```ruby
49
+ RspecDispatch.configure do |config|
50
+ config.service_url = "http://examplehost.com/results"
51
+ config.verbose = false
52
+ config.custom_data = {author: "Kevin Wanek", date: Date.now}
53
+ end
54
+ ```
55
+
56
+ #### POST Body
57
+ When the results from your test run are sent to your web service, that endpoint will recieve a body with the following structure:
58
+ ```json
59
+ {
60
+ "custom_data"=>{...},
61
+ "rspec_data"=>{
62
+ "duration"=>0.003571,
63
+ "example_count"=>4,
64
+ "success_count"=>2,
65
+ "failure_count"=>1,
66
+ "pending_count"=>1
67
+ },
68
+ "failures"=>[
69
+ {...}
70
+ ],
71
+ "successes"=>[
72
+ {...},
73
+ ],
74
+ "pending"=>[
75
+ {...}
76
+ ]
77
+ }
78
+ ```
79
+ 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:
80
+ ```json
81
+ {
82
+ "description"=>"example test description",
83
+ "status"=>"failed",
84
+ "run_time"=>0.000421,
85
+ "file_path"=>"profile_spec.rb",
86
+ "line_number"=>"15"
87
+ }
88
+ ```
89
+
90
+ ## TODO
91
+ 1. Needs the ability to add authentication parameters to POST request
92
+ 2. Clean up tests
93
+ 3. Clean up the Report module (specifically the text output and the #deliver method)
94
+
95
+ ## Contributing
96
+
97
+ 1. Fork it ( https://github.com/theef/rspec_dispatch/fork )
98
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
99
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
100
+ 4. Push to the branch (`git push origin my-new-feature`)
101
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
Binary file
@@ -0,0 +1,26 @@
1
+ require "rspec_dispatch/version"
2
+ require "rspec_dispatch/configuration"
3
+ require "rspec_dispatch/monitor"
4
+ require "rspec_dispatch/formatter"
5
+ require "rspec_dispatch/report"
6
+
7
+ module RspecDispatch
8
+
9
+ begin
10
+ require 'pry'
11
+ rescue LoadError
12
+ end
13
+
14
+ class << self
15
+ attr_writer :configuration
16
+ end
17
+
18
+ def self.configuration
19
+ @configuration ||= RspecDispatch::Configuration.new
20
+ end
21
+
22
+ def self.configure
23
+ yield(configuration)
24
+ end
25
+
26
+ end
@@ -0,0 +1,13 @@
1
+ module RspecDispatch
2
+ class Configuration
3
+
4
+ attr_accessor :service_url, :custom_data, :verbose
5
+
6
+ def initialize
7
+ @service_url = 'http://localhost:3000/'
8
+ @custom_data = {}
9
+ @verbose = true
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,52 @@
1
+ require 'rspec/core'
2
+
3
+ require 'rspec_dispatch/monitor'
4
+ require 'rspec_dispatch/report'
5
+
6
+ module RspecDispatch
7
+ class Formatter < RSpec::Core::Formatters::ProgressFormatter
8
+
9
+ RSpec::Core::Formatters.register self, :start, :example_passed, :example_pending, :example_failed, :start_dump, :dump_summary
10
+
11
+ def start(example_count)
12
+ @monitor = RspecDispatch::Monitor.new
13
+ end
14
+
15
+ def example_passed(notification)
16
+ @monitor.track notification.example
17
+ super(notification)
18
+ end
19
+
20
+ def example_pending(notification)
21
+ @monitor.track notification.example
22
+ super(notification)
23
+ end
24
+
25
+ def example_failed(notification)
26
+ @monitor.track notification.example
27
+ super(notification)
28
+ end
29
+
30
+ def start_dump(notification)
31
+ super(notification)
32
+ output.puts
33
+ end
34
+
35
+ def dump_summary(examples)
36
+ rspec_data = {
37
+ duration: examples.duration,
38
+ example_count: examples.example_count,
39
+ success_count: examples.example_count.to_i - examples.failure_count.to_i - examples.pending_count.to_i,
40
+ failure_count: examples.failure_count,
41
+ pending_count: examples.pending_count
42
+ }
43
+
44
+ report = RspecDispatch::Report.new(rspec_data)
45
+ report.monitor_data = @monitor
46
+ report.deliver
47
+
48
+ super(examples)
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,33 @@
1
+ module RspecDispatch
2
+ class Monitor
3
+
4
+ attr_accessor :failures, :successes, :pending
5
+
6
+ def initialize
7
+ @failures = []
8
+ @successes = []
9
+ @pending = []
10
+ end
11
+
12
+ def track(example)
13
+ status = example.metadata[:execution_result].status
14
+
15
+ content = {
16
+ description: example.metadata[:full_description],
17
+ status: status,
18
+ run_time: example.metadata[:execution_result].run_time,
19
+ file_path: example.metadata[:file_path].gsub('./spec/', ''),
20
+ line_number: example.metadata[:location].split('.rb')[1].gsub(':', '')
21
+ }
22
+
23
+ if status == :failed
24
+ @failures << content
25
+ elsif status == :passed
26
+ @successes << content
27
+ elsif status == :pending
28
+ @pending << content
29
+ end
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,64 @@
1
+ require 'httparty'
2
+
3
+ module RspecDispatch
4
+ class Report
5
+
6
+ attr_accessor :rspec_data, :monitor_data
7
+
8
+ def initialize(rspec_data)
9
+ success_calculation = ((1 - (rspec_data[:failure_count].to_f/rspec_data[:example_count].to_f)) * 100).to_s[0..5]
10
+
11
+ if RspecDispatch.configuration.verbose == true
12
+
13
+ if rspec_data[:duration].to_f > 60
14
+ custom_duration = "#{(rspec_data[:duration].to_f / 60).to_s[0..5]} minutes."
15
+ else
16
+ custom_duration = "#{rspec_data[:duration]} seconds."
17
+ end
18
+
19
+ puts "\nRSpec Dispatch ----\n"
20
+ puts "Duration: #{custom_duration}\n"
21
+ puts "Example Count: #{rspec_data[:example_count]}\n"
22
+ puts "Success Rate: #{success_calculation}%"
23
+ end
24
+
25
+ self.rspec_data = rspec_data
26
+ end
27
+
28
+ def deliver
29
+ endpoint = RspecDispatch.configuration.service_url
30
+
31
+ payload = {
32
+ custom_data: RspecDispatch.configuration.custom_data,
33
+ rspec_data: self.rspec_data,
34
+ failures: self.monitor_data.failures,
35
+ successes: self.monitor_data.successes,
36
+ pending: self.monitor_data.pending
37
+ }
38
+
39
+ begin
40
+ response = HTTParty.post(endpoint,
41
+ body: payload.to_json,
42
+ headers: {'Content-Type' => 'application/json'})
43
+
44
+ body = response.body
45
+ if (200..206).include?(response.code.to_i)
46
+ if RspecDispatch.configuration.verbose == true
47
+ puts "\nResponse Status: #{response.code}\n"
48
+ if body.blank? || body == ''
49
+ body = "*no content*"
50
+ end
51
+ puts "Response Body: #{body}"
52
+ end
53
+
54
+ else
55
+ puts "\nResponse: ERROR (status #{response.code})\n"
56
+ end
57
+
58
+ rescue Errno::ECONNREFUSED
59
+ puts "RSpec Dispatch: ERROR - Could not connect to given endpoint. Ensure that you have properly configured your target service url in the configuration block. See Documentation at: https://github.com/theef/rspec_dispatch"
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,3 @@
1
+ module RspecDispatch
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec_dispatch/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "rspec_dispatch"
8
+ s.version = RspecDispatch::VERSION
9
+ s.authors = ["Kevin Wanek"]
10
+ s.email = ["kevin@gekkobyte.com"]
11
+ s.summary = "A custom RSpec formatter to post RSpec suite results to a web service."
12
+ s.description = "See summary..."
13
+ s.homepage = "https://github.com/theef/rspec_dispatch"
14
+ s.license = "MIT"
15
+
16
+ s.files = `git ls-files -z`.split("\x0")
17
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency 'bundler', '~> 1.6'
22
+ s.add_development_dependency 'rake'
23
+ s.add_development_dependency 'pry'
24
+
25
+ s.add_dependency 'rspec'
26
+ s.add_dependency 'rspec-support'
27
+ s.add_dependency 'httparty'
28
+ end
Binary file
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ module RspecDispatch
4
+ describe Configuration do
5
+
6
+ describe '#initialize' do
7
+ before(:all) do
8
+ @config = RspecDispatch::Configuration.new
9
+ end
10
+
11
+ it 'will set a default @service_url' do
12
+ expect(@config.service_url).to eq('http://localhost:3000/')
13
+ end
14
+
15
+ it 'will set default @custom_data as an empty hash' do
16
+ expect(@config.custom_data).to eq({})
17
+ end
18
+
19
+ it 'will set @verbose to true' do
20
+ expect(@config.verbose).to eq(true)
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ module RspecDispatch
4
+
5
+ describe '#configure' do
6
+ before do
7
+ RspecDispatch.configure do |config|
8
+ config.service_url = 'http://example.com'
9
+ config.custom_data = {example: 'test'}
10
+ config.verbose = false
11
+ end
12
+ end
13
+
14
+ it 'will have the values saved from config block' do
15
+ expect(RspecDispatch.configuration.service_url).to eq('http://example.com')
16
+ expect(RspecDispatch.configuration.custom_data).to eq({example: 'test'})
17
+ expect(RspecDispatch.configuration.verbose).to eq(false)
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,9 @@
1
+ require 'rspec_dispatch'
2
+
3
+ RSpec.configure do |config|
4
+ config.filter_run :focus
5
+ config.run_all_when_everything_filtered = true
6
+
7
+ config.warnings = true
8
+ config.order = :random
9
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec_dispatch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Wanek
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-support
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: httparty
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: See summary...
98
+ email:
99
+ - kevin@gekkobyte.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .DS_Store
105
+ - .gitignore
106
+ - .rspec
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - lib/.DS_Store
112
+ - lib/rspec_dispatch.rb
113
+ - lib/rspec_dispatch/configuration.rb
114
+ - lib/rspec_dispatch/formatter.rb
115
+ - lib/rspec_dispatch/monitor.rb
116
+ - lib/rspec_dispatch/report.rb
117
+ - lib/rspec_dispatch/version.rb
118
+ - rspec_dispatch.gemspec
119
+ - spec/.DS_Store
120
+ - spec/rspec_dispatch/configuration_spec.rb
121
+ - spec/rspec_dispatch_spec.rb
122
+ - spec/spec_helper.rb
123
+ homepage: https://github.com/theef/rspec_dispatch
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.3.0
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: A custom RSpec formatter to post RSpec suite results to a web service.
147
+ test_files:
148
+ - spec/.DS_Store
149
+ - spec/rspec_dispatch/configuration_spec.rb
150
+ - spec/rspec_dispatch_spec.rb
151
+ - spec/spec_helper.rb