spec_marker 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/.rspec +2 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +86 -0
- data/Rakefile +5 -0
- data/lib/spec_marker.rb +102 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/spec_marker_spec.rb +76 -0
- data/spec_marker.gemspec +21 -0
- metadata +92 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Shota Fukumori
|
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,86 @@
|
|
1
|
+
# SpecMarker - RSpec formatter that useful for profiling
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
gem 'spec_marker'
|
8
|
+
|
9
|
+
And then execute:
|
10
|
+
|
11
|
+
$ bundle
|
12
|
+
|
13
|
+
Or install it yourself as:
|
14
|
+
|
15
|
+
$ gem install spec_marker
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
### Basic
|
20
|
+
|
21
|
+
```
|
22
|
+
# to STDOUT
|
23
|
+
$ rspec --format SpecMarker ...
|
24
|
+
|
25
|
+
# to a File
|
26
|
+
$ rspec --format SpecMarker --out spec_marker.log ...
|
27
|
+
$ cat spec_marker.log
|
28
|
+
```
|
29
|
+
|
30
|
+
### Log File
|
31
|
+
|
32
|
+
Log file is like this:
|
33
|
+
|
34
|
+
```
|
35
|
+
[suite:start][1355121779.69578] {"tag":"suite","at":1355121779.6957781,"meta":{},"kind":"start"}
|
36
|
+
[example_group:start][1355121779.69596] {"tag":"example_group","at":1355121779.695959,"meta":{"description":"foo"},"kind":"start"}
|
37
|
+
[example:start][1355121779.69616] {"tag":"example","at":1355121779.6961558,"meta":{"location":"./a_spec.rb:2","description":"hello"},"kind":"start"}
|
38
|
+
[example:end][1355121781.69764 (2.00148)] {"tag":"example","at":1355121781.6976361,"meta":{"location":"./a_spec.rb:2","description":"hello","result":"passed"},"kind":"end","elapsed":2.0014803409576416}
|
39
|
+
...
|
40
|
+
```
|
41
|
+
|
42
|
+
Each line is:
|
43
|
+
|
44
|
+
```
|
45
|
+
[TAG][TIMESTAMP (ELAPSED TIME)] JSON
|
46
|
+
```
|
47
|
+
|
48
|
+
### Marking
|
49
|
+
|
50
|
+
``` ruby
|
51
|
+
describe "foo" do
|
52
|
+
it "hello" do
|
53
|
+
sleep 2
|
54
|
+
end
|
55
|
+
|
56
|
+
context "bar" do
|
57
|
+
it "hello" do
|
58
|
+
# Use SpecMarker.mark to mark the time on the log.
|
59
|
+
SpecMarker.mark :foo
|
60
|
+
#=> [foo][1355121541.62746] {"tag":"foo","at":1355121541.627462,"meta":{},"kind":null}
|
61
|
+
|
62
|
+
# You can pass additional data to record in JSON.
|
63
|
+
SpecMarker.mark :foo, meta: :data
|
64
|
+
#=> [foo][1355121541.62750] {"tag":"foo","at":1355121541.627502,"meta":{"meta":"data"},"kind":null}
|
65
|
+
end
|
66
|
+
|
67
|
+
it "hello" do
|
68
|
+
# You can record an elapsed time of any parts.
|
69
|
+
SpecMarker.mark :bar, :start
|
70
|
+
#=> [bar:start][1355121781.69903] {"tag":"bar","at":1355121781.699029,"meta":{},"kind":"start"}
|
71
|
+
sleep 1
|
72
|
+
|
73
|
+
# Then call with :end to record elapsed time.
|
74
|
+
SpecMarker.mark :bar, :end
|
75
|
+
#=> [bar:end][1355121782.70022 (1.00119)] {"tag":"bar","at":1355121782.700217,"meta":{},"kind":"end","elapsed":1.001188039779663}
|
76
|
+
sleep 1
|
77
|
+
end
|
78
|
+
|
79
|
+
it "hello" do
|
80
|
+
# You can also pass the metadata.
|
81
|
+
SpecMarker.mark :bar, {meta: :data}, :start
|
82
|
+
SpecMarker.mark :bar, {meta: :data}, :end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
```
|
data/Rakefile
ADDED
data/lib/spec_marker.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rspec/core/formatters/base_formatter'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
class SpecMarker < RSpec::Core::Formatters::BaseFormatter
|
6
|
+
VERSION = "0.0.1"
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def mark(*args)
|
10
|
+
@listeners.each do |listener|
|
11
|
+
listener.mark *args
|
12
|
+
end
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def _join(formatter)
|
17
|
+
@listeners ||= []
|
18
|
+
@listeners << formatter unless @listeners.include?(formatter)
|
19
|
+
end
|
20
|
+
|
21
|
+
def _leave(formatter)
|
22
|
+
(@listeners ||= []).delete formatter
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(*args)
|
27
|
+
super
|
28
|
+
@marks = []
|
29
|
+
end
|
30
|
+
|
31
|
+
def start(example_count)
|
32
|
+
super
|
33
|
+
self.class._join(self)
|
34
|
+
mark :suite, :start
|
35
|
+
end
|
36
|
+
|
37
|
+
def stop
|
38
|
+
super
|
39
|
+
self.class._leave(self)
|
40
|
+
mark :suite, :end
|
41
|
+
end
|
42
|
+
|
43
|
+
def mark(tag, meta_or_kind={}, kind=nil, meta_for_search=nil)
|
44
|
+
if meta_or_kind.is_a?(Hash)
|
45
|
+
meta = meta_or_kind
|
46
|
+
elsif kind.nil? && meta_or_kind.is_a?(Symbol)
|
47
|
+
meta = {}
|
48
|
+
kind = meta_or_kind
|
49
|
+
end
|
50
|
+
|
51
|
+
m = {:tag => tag, :at => Time.now.to_f, :meta => meta, :kind => kind}
|
52
|
+
if kind == :end
|
53
|
+
start = @marks.reverse_each.find { |mark| mark[:kind] == :start && mark[:tag] == tag && mark[:meta] == (meta_for_search || meta)}
|
54
|
+
if start
|
55
|
+
m[:elapsed] = m[:at] - start[:at]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
@marks << m
|
60
|
+
output.puts "[#{tag}#{kind && ":#{kind}"}][#{"%.5f" % m[:at]}#{m[:elapsed] && (" (%.5f)" % m[:elapsed])}] #{m.to_json}"
|
61
|
+
end
|
62
|
+
|
63
|
+
def example_group_started(group)
|
64
|
+
super
|
65
|
+
mark :example_group, example_group_meta(group), :start
|
66
|
+
end
|
67
|
+
|
68
|
+
def example_started(example)
|
69
|
+
super
|
70
|
+
mark :example, example_meta(example), :start
|
71
|
+
end
|
72
|
+
|
73
|
+
def example_passed(example)
|
74
|
+
super
|
75
|
+
mark :example, example_meta(example, :passed), :end, example_meta(example)
|
76
|
+
end
|
77
|
+
|
78
|
+
def example_pending(example)
|
79
|
+
super
|
80
|
+
mark :example, example_meta(example, :pending), :end, example_meta(example)
|
81
|
+
end
|
82
|
+
|
83
|
+
def example_failed(example)
|
84
|
+
super
|
85
|
+
mark :example, example_meta(example, :failed), :end, example_meta(example)
|
86
|
+
end
|
87
|
+
|
88
|
+
def example_group_finished(group)
|
89
|
+
super
|
90
|
+
mark :example_group, example_group_meta(group), :end
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def example_group_meta(group)
|
96
|
+
{:description => group.description}
|
97
|
+
end
|
98
|
+
|
99
|
+
def example_meta(example, result = nil)
|
100
|
+
{:location => example.location, :description => example.description}.merge(result ? {:result => result} : {})
|
101
|
+
end
|
102
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'spec_marker'
|
3
|
+
require 'stringio'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
describe SpecMarker do
|
7
|
+
let(:output) { StringIO.new }
|
8
|
+
let(:formatter) do
|
9
|
+
SpecMarker.new(output).tap do |formatter|
|
10
|
+
formatter.start(2)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:time) { Time.now }
|
15
|
+
|
16
|
+
before do
|
17
|
+
Time.stub(now: time)
|
18
|
+
end
|
19
|
+
|
20
|
+
subject { output.string.split(/\n/) }
|
21
|
+
|
22
|
+
describe "marking" do
|
23
|
+
let(:example_group1) { RSpec::Core::ExampleGroup.describe }
|
24
|
+
let(:example1_1) { RSpec::Core::ExampleGroup.example }
|
25
|
+
let(:example1_2) { RSpec::Core::ExampleGroup.example }
|
26
|
+
|
27
|
+
let(:example_group2) { RSpec::Core::ExampleGroup.describe }
|
28
|
+
let(:example2_1) { RSpec::Core::ExampleGroup.example }
|
29
|
+
|
30
|
+
before do
|
31
|
+
formatter.example_group_started(example_group1)
|
32
|
+
formatter.example_started(example1_1)
|
33
|
+
Time.stub(now: Time.now + 10)
|
34
|
+
formatter.example_passed(example1_1)
|
35
|
+
formatter.example_started(example1_2)
|
36
|
+
formatter.example_failed(example1_1)
|
37
|
+
formatter.example_group_finished(example_group1)
|
38
|
+
formatter.example_group_started(example_group2)
|
39
|
+
formatter.example_started(example2_1)
|
40
|
+
formatter.example_pending(example2_1)
|
41
|
+
formatter.example_group_finished(example_group2)
|
42
|
+
end
|
43
|
+
|
44
|
+
it { should have(10).lines }
|
45
|
+
|
46
|
+
it "records JSON per line" do
|
47
|
+
expect {
|
48
|
+
subject.each { |line| JSON.parse(line) }
|
49
|
+
}.to_not raise_error
|
50
|
+
end
|
51
|
+
|
52
|
+
it "records timestamp" do
|
53
|
+
json = JSON.parse(subject[0])
|
54
|
+
json['at'].should == time.to_f
|
55
|
+
json['elapsed'].should == 10
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "data" do
|
60
|
+
before do
|
61
|
+
formatter.example_group_started(example_group)
|
62
|
+
formatter.example_started(example)
|
63
|
+
SpecMarker.mark(:foo, {meta: :data})
|
64
|
+
SpecMarker.mark(:bar, {meta: :meta}, :start)
|
65
|
+
SpecMarker.mark(:bar, {meta: :meta}, :end)
|
66
|
+
SpecMarker.mark(:bar, {meta: :foo}, :start)
|
67
|
+
SpecMarker.mark(:bar, {meta: :foo}, :end)
|
68
|
+
SpecMarker.mark(:bar) do
|
69
|
+
end
|
70
|
+
formatter.example_passed(example)
|
71
|
+
formatter.example_group_finished(example_group)
|
72
|
+
end
|
73
|
+
|
74
|
+
it { should have(11).lines }
|
75
|
+
end
|
76
|
+
end
|
data/spec_marker.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
#require 'spec_marker'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "spec_marker"
|
8
|
+
gem.version = "0.0.1"
|
9
|
+
gem.authors = ["Shota Fukumori (sora_h)"]
|
10
|
+
gem.email = ["sorah@tubusu.net"]
|
11
|
+
gem.description = %q{Mark the timestamp of RSpec example starts/ends, and log other stuff for profiling}
|
12
|
+
gem.summary = %q{Mark the timestamp of RSpec example starts/ends, and log other stuff for profiling.}
|
13
|
+
gem.homepage = "https://github.com/sorah/spec_marker"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.add_dependency 'rspec'
|
20
|
+
gem.add_dependency 'json'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spec_marker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Shota Fukumori (sora_h)
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '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: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: json
|
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
|
+
description: Mark the timestamp of RSpec example starts/ends, and log other stuff
|
47
|
+
for profiling
|
48
|
+
email:
|
49
|
+
- sorah@tubusu.net
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- .rspec
|
56
|
+
- .travis.yml
|
57
|
+
- Gemfile
|
58
|
+
- LICENSE.txt
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- lib/spec_marker.rb
|
62
|
+
- spec/spec_helper.rb
|
63
|
+
- spec/spec_marker_spec.rb
|
64
|
+
- spec_marker.gemspec
|
65
|
+
homepage: https://github.com/sorah/spec_marker
|
66
|
+
licenses: []
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.8.24
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Mark the timestamp of RSpec example starts/ends, and log other stuff for
|
89
|
+
profiling.
|
90
|
+
test_files:
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
- spec/spec_marker_spec.rb
|