chartspec 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
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/.project CHANGED
@@ -1,17 +1,17 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <projectDescription>
3
- <name>chartspec</name>
4
- <comment></comment>
5
- <projects>
6
- </projects>
7
- <buildSpec>
8
- <buildCommand>
9
- <name>com.aptana.ide.core.unifiedBuilder</name>
10
- <arguments>
11
- </arguments>
12
- </buildCommand>
13
- </buildSpec>
14
- <natures>
15
- <nature>com.aptana.ruby.core.rubynature</nature>
16
- </natures>
17
- </projectDescription>
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>chartspec</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>com.aptana.ide.core.unifiedBuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ </buildSpec>
14
+ <natures>
15
+ <nature>com.aptana.ruby.core.rubynature</nature>
16
+ </natures>
17
+ </projectDescription>
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,7 +1,7 @@
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"]
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
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/db.rb CHANGED
@@ -1,29 +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
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
29
  end
@@ -1,140 +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
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) if example.metadata[:chart]
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
140
  end
@@ -1,28 +1,28 @@
1
- require 'erb'
2
-
3
- module Chartspec
4
- class Printer
5
- include ERB::Util
6
-
7
- def initialize(output)
8
- @output = output
9
- end
10
-
11
- def print_html_start
12
- chartspec_header = ERB.new File.new(File.expand_path("../../../templates/chartspec_header.html.erb", __FILE__)).read
13
- @output.puts chartspec_header.result(binding)
14
- end
15
-
16
- def flush
17
- @output.flush
18
- end
19
-
20
- def print_html_end
21
- chartspec_footer = ERB.new File.new(File.expand_path("../../../templates/chartspec_footer.html.erb", __FILE__)).read
22
- @output.puts chartspec_footer.result(binding)
23
- end
24
-
25
- private
26
-
27
- end
1
+ require 'erb'
2
+
3
+ module Chartspec
4
+ class Printer
5
+ include ERB::Util
6
+
7
+ def initialize(output)
8
+ @output = output
9
+ end
10
+
11
+ def print_html_start
12
+ chartspec_header = ERB.new File.new(File.expand_path("../../../templates/chartspec_header.html.erb", __FILE__)).read
13
+ @output.puts chartspec_header.result(binding)
14
+ end
15
+
16
+ def flush
17
+ @output.flush
18
+ end
19
+
20
+ def print_html_end
21
+ chartspec_footer = ERB.new File.new(File.expand_path("../../../templates/chartspec_footer.html.erb", __FILE__)).read
22
+ @output.puts chartspec_footer.result(binding)
23
+ end
24
+
25
+ private
26
+
27
+ end
28
28
  end
@@ -1,3 +1,3 @@
1
- module Chartspec
2
- VERSION = "0.0.4"
3
- end
1
+ module Chartspec
2
+ VERSION = "0.0.5"
3
+ end