nanonano87-cucumber_statistics 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.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.gitignore +20 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE.txt +46 -0
  8. data/README.md +44 -0
  9. data/Rakefile +7 -0
  10. data/cucumber_statistics.gemspec +38 -0
  11. data/lib/cucumber_statistics.rb +8 -0
  12. data/lib/cucumber_statistics/autoload.rb +5 -0
  13. data/lib/cucumber_statistics/configuration.rb +56 -0
  14. data/lib/cucumber_statistics/feature_statistics.rb +28 -0
  15. data/lib/cucumber_statistics/formatter.rb +101 -0
  16. data/lib/cucumber_statistics/overall_statistics.rb +29 -0
  17. data/lib/cucumber_statistics/renderer.rb +30 -0
  18. data/lib/cucumber_statistics/renderer_helper.rb +102 -0
  19. data/lib/cucumber_statistics/scenario_statistics.rb +28 -0
  20. data/lib/cucumber_statistics/step_statistics.rb +91 -0
  21. data/lib/cucumber_statistics/unused_steps.rb +18 -0
  22. data/lib/cucumber_statistics/version.rb +3 -0
  23. data/lib/cucumber_statistics/view/combined_statistics.html +299 -0
  24. data/lib/cucumber_statistics/view/combined_statistics.html.haml +169 -0
  25. data/notes.txt +9 -0
  26. data/spec/cucumber_statistics/configuration_spec.rb +20 -0
  27. data/spec/cucumber_statistics/feature_statistics_spec.rb +78 -0
  28. data/spec/cucumber_statistics/renderer_helper_spec.rb +27 -0
  29. data/spec/cucumber_statistics/renderer_spec.rb +71 -0
  30. data/spec/cucumber_statistics/scenario_statistics_spec.rb +86 -0
  31. data/spec/cucumber_statistics/step_statistics_spec.rb +199 -0
  32. data/spec/cucumber_statistics/unused_steps_spec.rb +39 -0
  33. data/spec/spec_helper.rb +9 -0
  34. metadata +184 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ff217f63571bbeb7267ca82a312cfcc504943eb2
4
+ data.tar.gz: d2530015b07ae9016ad3c0b070024af1e2fbd473
5
+ SHA512:
6
+ metadata.gz: 081123713f8d4c3352ccdcadf27fa585db47a877eb5394009058d5a36e6bf2657d77caae411335e008829c5a556e5c8eac4fb913e29f1b0901454539690aa791
7
+ data.tar.gz: df4916a633c39072684d2af8fd5d390f78ab49518bb9be4a88d110ad4fdf1d2039e771665e7ae6f2d933b1e9ad6c585a6c05618761be541554ffa45866b17e72
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ target
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+
20
+ .idea
@@ -0,0 +1 @@
1
+ cucumber_statistics
@@ -0,0 +1 @@
1
+ ruby-2.3.1
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,46 @@
1
+ Copyright (c) 2014 AlienFast, LLC
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.
23
+
24
+ -----------------------------------------------------------------------------------------------------------------------
25
+ Some code originally authored by Ryan Boucher https://github.com/distributedlife/cucumber_timing_presenter
26
+
27
+ Copyright (c) 2012 Ryan Boucher
28
+
29
+ Permission is hereby granted, free of charge, to any person obtaining
30
+ a copy of this software and associated documentation files (the
31
+ "Software"), to deal in the Software without restriction, including
32
+ without limitation the rights to use, copy, modify, merge, publish,
33
+ distribute, sublicense, and/or sell copies of the Software, and to
34
+ permit persons to whom the Software is furnished to do so, subject to
35
+ the following conditions:
36
+
37
+ The above copyright notice and this permission notice shall be
38
+ included in all copies or substantial portions of the Software.
39
+
40
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
41
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
42
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
43
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
44
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
45
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
46
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ # Cucumber Statistics
2
+
3
+ Tracks cucumber timing and displays results in a single html page with outliers highlighted in a table sortable by various metrics.
4
+
5
+ ## Installation
6
+
7
+ 1. Add `gem 'cucumber_statistics'` to your `Gemfile`
8
+
9
+ 2. Or `gem install 'cucumber_statistics`
10
+
11
+ ## Configuration
12
+
13
+ 1. For always-on automatic loading (recommended), add `require 'cucumber_statistics/autoload'` to `features/support/env.rb` or other support file.
14
+
15
+ 2. Or, add it to your `cucumber.yml` by adding `--format CucumberStatistics::Formatter` i.e.
16
+
17
+ `std_opts = "-r features/support/ -r features/step_definitions --quiet --format CucumberStatistics::Formatter --format progress --format junit -o test-reports --strict --tags ~@wip --tags ~@todo"`
18
+
19
+ 3. Or, use it via command line with the `--format CucumberStatistics::Formatter` option.
20
+
21
+ ## Results
22
+
23
+ Look in the `./target/cucumber_statistics` for the generated html document.
24
+
25
+ ## Why?
26
+
27
+ It should be fast and easy to find long running steps. This generates a bootstrap styled page with a sortable table, where the outliers are clearly identified. It should be fast and easy to diagnose problems.
28
+
29
+ ## Contributing
30
+
31
+ Please contribute!
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
38
+
39
+ ## Credits
40
+ Credit to Ryan Boucher [cucumber_timing_presenter](https://github.com/distributedlife/cucumber_timing_presenter) for the original code used to gather statistics.
41
+
42
+ ## Copyright
43
+
44
+ Copyright (c) 2014 AlienFast. See [LICENSE.txt](https://github.com/alienfast/cucumber_statistics/blob/master/LICENSE.txt) for further details.
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ # add rspec task
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new('spec')
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cucumber_statistics/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'nanonano87-cucumber_statistics'
8
+ spec.version = CucumberStatistics::VERSION
9
+ spec.authors = ['Weimun Ding']
10
+ spec.email = ['ding.wm7@gmail.com']
11
+ spec.summary = <<-TEXT
12
+ An cucumber formatter that will gather statistics and generate a single page showing step time metrics.
13
+ TEXT
14
+ spec.description = <<-TEXT
15
+ Want to know what is slowing down your build?
16
+ TEXT
17
+
18
+
19
+ spec.homepage = 'https://github.com/nanonano87/cucumber_statistics'
20
+ spec.license = 'MIT'
21
+
22
+ spec.files = `git ls-files`.split($/).reject { |f| f =~ /^samples\// }
23
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
24
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
25
+ spec.require_paths = ['lib']
26
+
27
+ # development
28
+ #spec.add_development_dependency 'cucumber'
29
+ spec.add_development_dependency 'bundler', '~> 1.3'
30
+ spec.add_development_dependency 'rake'
31
+ spec.add_development_dependency 'rspec', '>= 2.14.1'
32
+
33
+ # runtime
34
+ spec.add_runtime_dependency 'haml'
35
+ spec.add_runtime_dependency 'tilt'
36
+ spec.add_runtime_dependency 'cucumber', '>= 2.1.0'
37
+ spec.add_runtime_dependency 'virtus'
38
+ end
@@ -0,0 +1,8 @@
1
+ require 'cucumber_statistics/configuration'
2
+ require 'cucumber_statistics/step_statistics'
3
+ require 'cucumber_statistics/scenario_statistics'
4
+ require 'cucumber_statistics/feature_statistics'
5
+ require 'cucumber_statistics/overall_statistics'
6
+ require 'cucumber_statistics/unused_steps'
7
+ require 'cucumber_statistics/formatter'
8
+ require 'cucumber_statistics/renderer'
@@ -0,0 +1,5 @@
1
+ require 'cucumber_statistics'
2
+
3
+ AfterConfiguration do |configuration|
4
+ configuration.formats << ['CucumberStatistics::Formatter', nil]
5
+ end
@@ -0,0 +1,56 @@
1
+ require 'fileutils'
2
+
3
+ module CucumberStatistics
4
+ class Configuration
5
+
6
+ class << self
7
+
8
+ $tmp_path = 'target/cucumber_statistics'
9
+
10
+ def clean_tmp_dir
11
+ FileUtils.rm_r tmp_dir
12
+ end
13
+
14
+ def tmp_dir
15
+ dir = resolve_path_from_root $tmp_path
16
+ FileUtils.mkdir_p dir unless File.exists? dir
17
+
18
+ dir
19
+ end
20
+
21
+ def tmp_file(filename)
22
+ "#{tmp_dir}/#{filename}"
23
+ end
24
+
25
+ def result_combined_statistics
26
+ tmp_file('combined_statistics.html')
27
+ end
28
+
29
+ def resolve_path_from_root(relative_path)
30
+ if defined?(Rails)
31
+ Rails.root.join(relative_path)
32
+ elsif defined?(Rake.original_dir)
33
+ File.expand_path(relative_path, Rake.original_dir)
34
+ else
35
+ File.expand_path(relative_path, Dir.pwd)
36
+ end
37
+ end
38
+ #
39
+ #def all_usage_results
40
+ # File.expand_path('templates/all_usage_results.html', File.dirname(__FILE__))
41
+ #end
42
+ #
43
+ #def unused_steps
44
+ # File.expand_path('templates/unused_steps.html', File.dirname(__FILE__))
45
+ #end
46
+ #
47
+ #def step_times_of_whole
48
+ # File.expand_path('templates/step_times_of_whole.html', File.dirname(__FILE__))
49
+ #end
50
+ #
51
+ #def step_average_and_total
52
+ # File.expand_path('templates/step_average_and_total.html', File.dirname(__FILE__))
53
+ #end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,28 @@
1
+ module CucumberStatistics
2
+ class FeatureStatistics
3
+ def initialize
4
+ @all = Hash.new
5
+ end
6
+
7
+ def record feature_name, duration, file
8
+ short_file = file[file.index('features').to_i..-1]
9
+
10
+ feature_result = @all[short_file]
11
+ feature_result ||= Hash.new
12
+ feature_result[:duration] = duration
13
+ feature_result[:feature_name] = feature_name
14
+
15
+ @all[short_file] ||= feature_result
16
+ end
17
+
18
+ def all
19
+ @all
20
+ end
21
+
22
+ def sort_by_property property
23
+ result = @all.sort {|a,b| a.last[property.to_sym] <=> b.last[property.to_sym]}
24
+ result
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,101 @@
1
+ module CucumberStatistics
2
+ class Formatter
3
+ def initialize(step_mother, io, options)
4
+ @step_mother = step_mother
5
+ @io = io
6
+ @options = options
7
+
8
+ @overall_statistics = OverallStatistics.new
9
+ @step_statistics = StepStatistics.new
10
+ @scenario_statistics = ScenarioStatistics.new
11
+ @feature_statistics = FeatureStatistics.new
12
+ @unused_steps = UnusedSteps.new
13
+ end
14
+
15
+ #----------------------------------------------------
16
+ # Step callbacks
17
+ #----------------------------------------------------
18
+ def before_test_step(step)
19
+ @step_start_time = Time.now
20
+ end
21
+
22
+ def before_step_result(*args)
23
+ @step_duration = Time.now - @step_start_time
24
+ end
25
+
26
+ def after_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background, file_colon_line)
27
+ step_definition = step_match.step_definition
28
+ unless step_definition.nil? # nil if it's from a scenario outline
29
+ @step_statistics.record step_definition.regexp_source, @step_duration, file_colon_line
30
+ end
31
+ end
32
+
33
+
34
+ #----------------------------------------------------
35
+ # Feature Element callbacks
36
+ #----------------------------------------------------
37
+ def before_feature_element(feature_element)
38
+ @scenario_name = ''
39
+ @scenario_file_colon_line = ''
40
+ @scenario_start_time = Time.now
41
+ end
42
+
43
+ def after_feature_element(feature_element)
44
+ @scenario_duration = Time.now - @scenario_start_time
45
+ @scenario_statistics.record @scenario_name, @scenario_duration, @scenario_file_colon_line
46
+ end
47
+
48
+ #----------------------------------------------------
49
+ # Feature callbacks
50
+ #----------------------------------------------------
51
+ def before_feature(feature)
52
+ @feature_name = ''
53
+ @feature_file = ''
54
+ @feature_start_time = Time.now
55
+ end
56
+
57
+ #----------------------------------------------------
58
+ # Overall callbacks
59
+ #----------------------------------------------------
60
+ #def before_feature(feature)
61
+ #end
62
+ def scenario_name(keyword, name, file_colon_line, source_indent)
63
+ @overall_statistics.scenario_count_inc
64
+ @scenario_name = name
65
+ @scenario_file_colon_line = file_colon_line
66
+ end
67
+
68
+ def feature_name(keyword, name)
69
+ @overall_statistics.feature_count_inc
70
+ @feature_name = name
71
+ end
72
+
73
+ def after_step(step)
74
+ @overall_statistics.step_count_inc
75
+ end
76
+
77
+ def after_feature(feature)
78
+ @feature_file = feature.location.to_s
79
+ @feature_duration = Time.now - @feature_start_time
80
+ @feature_statistics.record @feature_name, @feature_duration, @feature_file
81
+ end
82
+
83
+ def before_features(features)
84
+ @overall_statistics.start_time = Time.now
85
+ end
86
+
87
+ def after_features(features)
88
+
89
+ @overall_statistics.end_time = Time.now
90
+
91
+ # gather unused steps
92
+ @step_mother.unmatched_step_definitions.each do |step_definition|
93
+ @unused_steps.record step_definition.regexp_source, step_definition.location.to_s
94
+ end
95
+
96
+ @step_statistics.calculate
97
+
98
+ Renderer.render_combined_statistics @step_statistics, @scenario_statistics, @feature_statistics, @overall_statistics
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,29 @@
1
+ require 'virtus'
2
+
3
+ module CucumberStatistics
4
+ class OverallStatistics
5
+ include Virtus.model
6
+
7
+ attribute :start_time, Time
8
+ attribute :end_time, Time
9
+ attribute :feature_count, Integer, default: 0
10
+ attribute :scenario_count, Integer, default: 0
11
+ attribute :step_count, Integer, default: 0
12
+
13
+ def duration
14
+ end_time - start_time
15
+ end
16
+
17
+ def feature_count_inc
18
+ self.feature_count += 1
19
+ end
20
+
21
+ def scenario_count_inc
22
+ self.scenario_count += 1
23
+ end
24
+
25
+ def step_count_inc
26
+ self.step_count += 1
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,30 @@
1
+ require 'haml'
2
+ require 'tilt/haml'
3
+ require 'cucumber_statistics/renderer_helper'
4
+
5
+ module CucumberStatistics
6
+ class Renderer
7
+
8
+ class << self
9
+
10
+ $renderer_helper ||=
11
+
12
+ def render_combined_statistics(step_statistics, scenario_statistics, feature_statistics, overall_statistics)
13
+ template = Tilt::HamlTemplate.new(File.expand_path('../view/combined_statistics.html.haml', __FILE__))
14
+ rendered_content = template.render(RendererHelper.new,
15
+ step_statistics: step_statistics,
16
+ scenario_statistics: scenario_statistics,
17
+ feature_statistics: feature_statistics,
18
+ overall_statistics: overall_statistics)
19
+
20
+ absolute_file_name = Configuration.result_combined_statistics
21
+ File.open(absolute_file_name, 'w') do |f|
22
+ f.write rendered_content
23
+ end
24
+
25
+ absolute_file_name
26
+ end
27
+
28
+ end
29
+ end
30
+ end