chartspec 0.0.3 → 0.0.4

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f37f2bb306208ac827db30a92d6b825b9a8b6416
4
+ data.tar.gz: 40ca5a5b98eedf8185e01c0d95cb6f3c5874ca21
5
+ SHA512:
6
+ metadata.gz: a122b8de4f237d604586909c81cfd417016758c019e61e6f5419c6632eaccf1cc9b8094f1fc5fe90dade62b1fcdba3b70bc5ddc8bbd2c466e997e55062b85fc7
7
+ data.tar.gz: ef405c8dfb1f8e58234b5e94fe342b99e253ab5958040fbdc84157f0bdb088cd79fabc1069168e89db61b7b26a94249cfbac06805700e49c7b3fcd17c1c117bb
data/.gitignore CHANGED
@@ -1,16 +1,16 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- *.bundle
11
- *.so
12
- *.o
13
- *.a
14
- mkmf.log
15
- .project
16
- pkg
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .project
16
+ pkg
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in chartspec.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in chartspec.gemspec
4
+ gemspec
data/LICENSE.txt CHANGED
@@ -1,22 +1,22 @@
1
- Copyright (c) 2014 AlexVangelov
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.
1
+ Copyright (c) 2014 AlexVangelov
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 CHANGED
@@ -1,31 +1,31 @@
1
- # Chartspec
2
-
3
- Generates HTML files with case execution time charts for recurrent RSpec tests
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'chartspec'
11
- ```
12
-
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
18
-
19
- $ gem install chartspec
20
-
21
- ## Usage
22
-
23
- TODO: Write usage instructions here
24
-
25
- ## Contributing
26
-
27
- 1. Fork it ( https://github.com/[my-github-username]/chartspec/fork )
28
- 2. Create your feature branch (`git checkout -b my-new-feature`)
29
- 3. Commit your changes (`git commit -am 'Add some feature'`)
30
- 4. Push to the branch (`git push origin my-new-feature`)
31
- 5. Create a new Pull Request
1
+ # Chartspec
2
+
3
+ Generates HTML files with case execution time charts for recurrent RSpec tests
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'chartspec'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install chartspec
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/chartspec/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
- require "bundler/gem_tasks"
2
-
1
+ require "bundler/gem_tasks"
2
+
data/bin/chartspec CHANGED
@@ -1,5 +1,7 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'chartspec'
4
-
5
- Chartspec::run ARGV
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rspec'
4
+ require 'chartspec'
5
+
6
+ #RSpec::Core::Runner::run ARGV + ["--format", "Chartspec::Formatter", "--out", ENV["CHARTSPEC_HTML"] || "tmp/chartspec.html"]
7
+ RSpec::Core::Runner::run ARGV + ["--format", "Chartspec::Formatter"]
data/chartspec.gemspec CHANGED
@@ -1,28 +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 'chartspec/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "chartspec"
8
- spec.version = Chartspec::VERSION
9
- spec.authors = ["AlexVangelov"]
10
- spec.email = ["email@data.bg"]
11
- spec.summary = %q{RSpec with execution time history charts}
12
- spec.description = %q{Generates HTML files with case execution time charts for recurrent RSpec tests}
13
- spec.homepage = ""
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_dependency 'rspec'
22
- spec.add_dependency 'sqlite3'
23
-
24
- spec.add_development_dependency "bundler", "~> 1.6"
25
- spec.add_development_dependency "rake", "~> 10.0"
26
-
27
- spec.executables << 'chartspec'
28
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'chartspec/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "chartspec"
8
+ spec.version = Chartspec::VERSION
9
+ spec.authors = ["AlexVangelov"]
10
+ spec.email = ["email@data.bg"]
11
+ spec.summary = %q{RSpec with execution time history charts}
12
+ spec.description = %q{Generates HTML files with case execution time charts for recurrent RSpec tests}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'rspec'
22
+ spec.add_dependency 'sqlite3'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+
27
+ spec.executables << 'chartspec'
28
+ end
data/lib/chartspec.rb CHANGED
@@ -1,141 +1,4 @@
1
- require "chartspec/version"
2
- require "rspec"
3
- require "rspec/core/formatters/progress_formatter"
4
- require "rspec/core/formatters/console_codes"
5
- require 'sqlite3'
6
- require 'erb'
7
-
8
- module Chartspec
9
- def self.run argv
10
- config = RSpec.configuration
11
- formatter = Formatter.new config.output_stream
12
- reporter = RSpec::Core::Reporter.new(config)
13
- config.instance_variable_set :@reporter, reporter
14
- loader = config.send :formatter_loader
15
- notifications = loader.send :notifications_for, Formatter
16
- reporter.register_listener formatter, *notifications
17
- RSpec::Core::Runner::run [argv]
18
- end
19
-
20
- class Formatter < RSpec::Core::Formatters::ProgressFormatter
21
- RSpec::Core::Formatters.register self, :start, :stop, :example_group_started, :start_dump, :example_started, :example_passed, :example_failed, :example_pending, :dump_profile
22
-
23
- def initialize(output)
24
- super(output)
25
- @db = SQLite3::Database.new( ENV["CHARTSPEC_DB"] || "tmp/chartspec.sqlite3" )
26
- @title = ENV["CHARTSPEC_TITLE"]
27
- @name = ENV["CHARTSPEC_NAME"]
28
- @db.execute( "CREATE TABLE IF NOT EXISTS specs(id INTEGER PRIMARY KEY, file TEXT, name TEXT, duration NUMERIC, measured_at DATETIME);" )
29
- end
30
-
31
- def start(notification)
32
- super
33
- @failed_examples = []
34
- @example_group_number = 0
35
- @example_number = 0
36
- @header_red = false
37
- @output_hash = {}
38
- end
39
-
40
- def stop(notification)
41
- @output_hash[:examples] = notification.examples.map do |example|
42
- format_example(example).tap do |hash|
43
- e = example.exception
44
- if e
45
- hash[:exception] = {
46
- :class => e.class.name,
47
- :message => e.message,
48
- :backtrace => e.backtrace,
49
- }
50
- else
51
- @db.execute("INSERT INTO specs(file, name, duration, measured_at) VALUES (?, ?, ?, ?)", [
52
- example.metadata[:file_path], example.full_description, example.execution_result.run_time, Time.now.to_i
53
- ]) if example.metadata[:chart]
54
- end
55
- end
56
- end
57
- end
58
-
59
- def dump_summary(summary)
60
- output.puts summary.fully_formatted
61
- @output_hash[:summary] = {
62
- :duration => summary.duration,
63
- :example_count => summary.example_count,
64
- :failure_count => summary.failure_count,
65
- :pending_count => summary.pending_count
66
- }
67
- @output_hash[:summary_line] = summary.totals_line
68
-
69
- specs_history = [].tap do |cd|
70
- @db.execute( "select file, name, duration, measured_at from specs where measured_at > ?", (Time.now - ((ENV['CHARTSPEC_HISTORY_HOURS'] || 2)*3600)).to_i).each do |row|
71
- cd << {
72
- file: row[0],
73
- name: row[1],
74
- duration: row[2],
75
- measured_at: row[3]
76
- }
77
- end
78
- end
79
-
80
- @chart_data = {}.tap do |spec_summary|
81
- specs_history.group_by{ |x| x[:name] }.each do |name, specs|
82
- measures = []
83
- specs.each do |spec|
84
- measures << [Time.at(spec[:measured_at]), spec[:duration], spec[:name]]
85
- end
86
- spec_summary[name] = measures
87
- end
88
- end
89
-
90
- @chartspec_root = File.expand_path("../../", __FILE__)
91
- template = ERB.new File.new(File.expand_path("../../templates/chartspec.html.erb", __FILE__)).read, nil, "%"
92
- template.result(binding)
93
-
94
- File.open(ENV["CHARTSPEC_HTML"] || "tmp/chartspec.html", "w") do |file|
95
- file.puts template.result(binding)
96
- end
97
- end
98
-
99
- def example_group_started(notification)
100
- super
101
- @example_group_red = false
102
- @example_group_number += 1
103
- end
104
-
105
- def start_dump(_notification)
106
- end
107
-
108
- def example_started(_notification)
109
- @example_number += 1
110
- end
111
-
112
- def example_passed(passed)
113
- super
114
- end
115
-
116
- def example_failed(failure)
117
- super
118
- @failed_examples << failure.example
119
- unless @header_red
120
- @header_red = true
121
- end
122
- end
123
-
124
- def example_pending(pending)
125
- super
126
- end
127
-
128
- private
129
- def format_example(example)
130
- {
131
- :description => example.description,
132
- :full_description => example.full_description,
133
- :status => example.execution_result.status.to_s,
134
- :file_path => example.metadata[:file_path],
135
- :line_number => example.metadata[:line_number],
136
- :run_time => example.execution_result.run_time
137
- }
138
- end
139
-
140
- end
141
- end
1
+ require "chartspec/version"
2
+ require "chartspec/formatter"
3
+
4
+
@@ -0,0 +1,29 @@
1
+ require 'sqlite3'
2
+
3
+ module Chartspec
4
+ class Db
5
+ def initialize db = nil
6
+ @db_file = db || "tmp/chartspec.sqlite3"
7
+ db_dirname = File.dirname(@db_file)
8
+ unless File.directory?(db_dirname)
9
+ FileUtils.mkdir_p(db_dirname)
10
+ end
11
+ @db = SQLite3::Database.new @db_file
12
+ @db.execute( "CREATE TABLE IF NOT EXISTS specs(id INTEGER PRIMARY KEY, file TEXT, name TEXT, duration NUMERIC, measured_at DATETIME);" )
13
+ end
14
+
15
+ def add(file, name, duration, measured_at = Time.now.to_i)
16
+ @db.execute("INSERT INTO specs(file, name, duration, measured_at) VALUES (?, ?, ?, ?)", [
17
+ file, name, duration, measured_at
18
+ ])
19
+ end
20
+
21
+ def all
22
+ @db.execute( "select file, name, duration, measured_at from specs where measured_at > ?", (Time.now - ((ENV['CHARTSPEC_HISTORY_HOURS'] || 2)*3600)).to_i)
23
+ end
24
+
25
+ def file_name
26
+ @db_file
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,140 @@
1
+ require "rspec"
2
+ require "rspec/core/formatters/progress_formatter"
3
+ require "chartspec/printer"
4
+ require "chartspec/db"
5
+ require 'json'
6
+
7
+ module Chartspec
8
+ class Formatter < RSpec::Core::Formatters::ProgressFormatter
9
+ RSpec::Core::Formatters.register self, :start, :stop, :example_group_started, :start_dump, :example_started, :example_passed, :example_failed, :example_pending, :dump_profile
10
+
11
+ def initialize(output)
12
+ super output
13
+ @failed_examples = []
14
+ @current_file = {}
15
+ @example_group_number = 0
16
+ @example_number = 0
17
+ @header_red = false
18
+ @db = Db.new ENV["CHARTSPEC_DB"]
19
+ #@printer = Printer.new output
20
+ end
21
+
22
+ def start(notification)
23
+ super
24
+ @output_hash = {}
25
+ #@printer.print_html_start
26
+ #@printer.flush
27
+ end
28
+
29
+ def stop(notification)
30
+ @output_hash[:examples] = notification.examples.map do |example|
31
+ format_example(example).tap do |hash|
32
+ e = example.exception
33
+ if e
34
+ hash[:exception] = {
35
+ :class => e.class.name,
36
+ :message => e.message,
37
+ :backtrace => e.backtrace,
38
+ }
39
+ else
40
+ @db.add example.metadata[:file_path], example.full_description, example.execution_result.run_time
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ def dump_summary(summary)
47
+ output.puts summary.fully_formatted
48
+ @output_hash[:summary] = {
49
+ :duration => summary.duration,
50
+ :example_count => summary.example_count,
51
+ :failure_count => summary.failure_count,
52
+ :pending_count => summary.pending_count
53
+ }
54
+ @output_hash[:summary_line] = summary.totals_line
55
+
56
+ specs_history = [].tap do |cd|
57
+ @db.all.each do |row|
58
+ cd << {
59
+ file: row[0],
60
+ name: row[1],
61
+ duration: row[2],
62
+ measured_at: row[3]
63
+ }
64
+ end
65
+ end
66
+
67
+ @chart_data = {}.tap do |spec_summary|
68
+ specs_history.group_by{ |x| x[:name] }.each do |name, specs|
69
+ measures = []
70
+ specs.each do |spec|
71
+ measures << [Time.at(spec[:measured_at]), spec[:duration], spec[:name]]
72
+ end
73
+ spec_summary[name] = measures
74
+ end
75
+ end
76
+
77
+ @chartspec_root = File.expand_path("../../../", __FILE__)
78
+ template = ERB.new File.new(File.expand_path("../../../templates/chartspec.html.erb", __FILE__)).read, nil, "%"
79
+ template.result(binding)
80
+
81
+ @chart_file = ENV["CHARTSPEC_HTML"] || "tmp/chartspec.html"
82
+ chart_dirname = File.dirname(@chart_file)
83
+ unless File.directory?(chart_dirname)
84
+ FileUtils.mkdir_p(chart_dirname)
85
+ end
86
+ File.open(@chart_file, "w") do |file|
87
+ file.puts template.result(binding)
88
+ end
89
+ puts "* Chartspec output: #{@chart_file}\n"
90
+ puts "* Chartspec tmp_db: #{@db.file_name}\n"
91
+ end
92
+
93
+ def example_group_started(notification)
94
+ super
95
+ @example_group_red = false
96
+ @example_group_number += 1
97
+ end
98
+
99
+ def start_dump(notification)
100
+
101
+ end
102
+
103
+ def example_started(notification)
104
+ @example_number += 1
105
+ end
106
+
107
+ def example_passed(passed)
108
+ super
109
+ end
110
+
111
+ def example_failed(failure)
112
+ super
113
+ @failed_examples << failure.example
114
+ unless @header_red
115
+ @header_red = true
116
+ end
117
+ end
118
+
119
+ def example_pending(pending)
120
+ super
121
+ end
122
+
123
+ private
124
+ def example_group_number
125
+ @example_group_number
126
+ end
127
+
128
+ def format_example(example)
129
+ {
130
+ :description => example.description,
131
+ :full_description => example.full_description,
132
+ :status => example.execution_result.status.to_s,
133
+ :file_path => example.metadata[:file_path],
134
+ :line_number => example.metadata[:line_number],
135
+ :run_time => example.execution_result.run_time
136
+ }
137
+ end
138
+
139
+ end
140
+ end