cucumber_statistics 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ module CucumberStatistics
4
+ describe RendererHelper do
5
+
6
+ describe '#format' do
7
+ it 'formats milliseconds' do
8
+ assert_format(0.000123, '< 0.000s')
9
+ end
10
+ it 'formats seconds' do
11
+ assert_format(3.123456, '3.123s')
12
+ end
13
+ it 'formats minutes' do
14
+ assert_format(60, '1m 0.000s')
15
+ assert_format(60.12345, '1m 0.123s')
16
+ end
17
+ it 'formats hours' do
18
+ assert_format(3600, '1h 0m 0.000s')
19
+ assert_format(3600.12345, '1h 0m 0.123s')
20
+ end
21
+ end
22
+
23
+ def assert_format(duration, expectation)
24
+ expect(RendererHelper.new.format duration).to eq(expectation)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ module CucumberStatistics
4
+ describe Renderer do
5
+
6
+ subject(:step_statistics) { StepStatistics.new }
7
+ subject(:overall_statistics) { OverallStatistics.new }
8
+
9
+ before(:each) do
10
+ # clean up before start, leave after in case we want to inspect it.
11
+ Configuration.clean_tmp_dir
12
+
13
+ overall_statistics.start_time = Time.now - 35
14
+ overall_statistics.feature_count_inc
15
+ overall_statistics.scenario_count_inc
16
+
17
+ record 'my step 1', 0.000116
18
+ record 'my step 1', 9.213553
19
+ record 'my step 2', 0.000117
20
+ record 'my step 2', 14.204407
21
+ record 'my step 3', 0.000131
22
+ record 'my step 3', 3.48993
23
+ record 'my step 4', 4.21
24
+ record 'my step 4', 4.21
25
+
26
+ overall_statistics.end_time = Time.now
27
+ step_statistics.calculate
28
+ end
29
+
30
+
31
+ describe 'render_step_statistics' do
32
+ it 'should render content' do
33
+
34
+ File.exists?(Configuration.result_step_statistics).should be_false
35
+
36
+ absolute_file_name = Renderer.render_step_statistics step_statistics, overall_statistics
37
+ File.exists?(absolute_file_name).should be_true
38
+
39
+ #file = File.open(absolute_file_name, 'rb')
40
+ #file_contents = file.read
41
+ end
42
+ end
43
+
44
+ def record(step_name, duration)
45
+ # fake a source for convenience
46
+ step_statistics.record step_name, duration, '/Users/kross/alienfast/acme/features/account management/admin_cancel_account.feature:8'
47
+ overall_statistics.step_count_inc
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,199 @@
1
+ require 'spec_helper'
2
+
3
+ module CucumberStatistics
4
+ describe StepStatistics do
5
+
6
+ subject(:step_statistics) { StepStatistics.new }
7
+ subject(:overall_statistics) { OverallStatistics.new }
8
+
9
+ describe 'record' do
10
+ it 'should create a record' do
11
+ record "my step", 50
12
+
13
+ step_statistics.all.count.should == 1
14
+ step_statistics.all['my step'][:instances].count.should == 1
15
+ step_statistics.all['my step'][:instances].first.should == 50
16
+ end
17
+
18
+ it 'should support multiple instances of record' do
19
+ record "my step", 50
20
+ record "my step", 75
21
+
22
+ step_statistics.all.count.should == 1
23
+ step_statistics.all['my step'][:instances].count.should == 2
24
+ step_statistics.all['my step'][:instances].first.should == 50
25
+ step_statistics.all['my step'][:instances].last.should == 75
26
+ end
27
+ end
28
+
29
+ describe 'calculate' do
30
+ before(:each) do
31
+ record "my step", 25
32
+ record "my step", 50
33
+ record "my step", 75
34
+
35
+ step_statistics.calculate
36
+ end
37
+
38
+ it 'should calculate the total elapsed time' do
39
+ step_statistics.all["my step"][:total].should == 150
40
+ end
41
+
42
+ it 'should calculate the number of count' do
43
+ step_statistics.all["my step"][:count].should == 3
44
+ end
45
+
46
+ it 'should calculate the average time' do
47
+ step_statistics.all["my step"][:average].should == 50
48
+ end
49
+
50
+ it 'should calculate the fastest step' do
51
+ step_statistics.all["my step"][:fastest].should == 25
52
+ end
53
+
54
+ it 'should calculate the slowest step' do
55
+ step_statistics.all["my step"][:slowest].should == 75
56
+ end
57
+
58
+ it 'should calculate the variation' do
59
+ step_statistics.all["my step"][:variation].should == 50
60
+ end
61
+
62
+ it 'should calculate the standard deviation' do
63
+ step_statistics.all["my step"][:standard_deviation].should == 25
64
+ end
65
+
66
+ it 'should calculate the variance' do
67
+ step_statistics.all["my step"][:variance].should == 625
68
+ end
69
+ end
70
+
71
+ describe 'all' do
72
+ before(:each) do
73
+ record "my step 1", 24
74
+ record "my step 1", 50
75
+ record "my step 2", 75
76
+ end
77
+
78
+ it 'should return all records' do
79
+ step_statistics.all.count.should == 2
80
+ step_statistics.all.each_with_index do |step_name, data, index|
81
+ case index
82
+ when 1
83
+ step_name.should == "my_step 2"
84
+ when 2
85
+ step_name.should == "my_step 1"
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ describe 'set operations' do
92
+ before(:each) do
93
+ record "my step 1", 25
94
+ record "my step 1", 50
95
+ record "my step 2", 49
96
+ record "my step 2", 51
97
+ record "my step 3", 75
98
+ record "my step 3", 10
99
+
100
+ step_statistics.calculate
101
+ end
102
+
103
+ describe 'sort_by_property' do
104
+ it 'should sort all records by any property' do
105
+ step_statistics.sort_by_property(:total).first.first.should == "my step 1"
106
+ step_statistics.sort_by_property(:total).last.first.should == "my step 2"
107
+
108
+ step_statistics.sort_by_property(:fastest).first.first.should == "my step 3"
109
+ step_statistics.sort_by_property(:fastest).last.first.should == "my step 2"
110
+ end
111
+ end
112
+
113
+ describe 'highest_average' do
114
+ it 'should return the record with the highest average' do
115
+ step_statistics.highest_average.first.should == "my step 2"
116
+ end
117
+ end
118
+
119
+ describe 'highest_elapsed_time' do
120
+ it 'should return the record with the highest elapsed time' do
121
+ step_statistics.highest_total.first.should == "my step 2"
122
+ end
123
+ end
124
+
125
+ describe 'greatest_variation' do
126
+ it 'should return the record with the greatest variation between slow and fast' do
127
+ step_statistics.highest_variation.first.should == "my step 3"
128
+ end
129
+ end
130
+
131
+ describe 'step_part_of_total' do
132
+ it 'should return the total times of each step from largest to smallest' do
133
+ step_statistics.step_part_of_total.should == [100.0, 85.0, 75.0]
134
+ end
135
+ end
136
+
137
+ describe 'total_elapsed_time' do
138
+ it 'should return the count of all steps' do
139
+ step_statistics.total_elapsed_time.should == 260
140
+ end
141
+ end
142
+
143
+ describe 'average_times_plot_data' do
144
+ it 'should return all the averages sorted by average amount descending' do
145
+ record "my step 1", 25
146
+ record "my step 1", 50
147
+ record "my step 2", 49
148
+ record "my step 2", 51
149
+ record "my step 3", 75
150
+ record "my step 3", 10
151
+
152
+ step_statistics.calculate
153
+
154
+ step_statistics.average_times_plot_data.should == [50.0, 42.5, 37.5]
155
+ end
156
+ end
157
+
158
+ describe 'total_times_plot_data' do
159
+ it 'should return the total times of each step sorted by average amount descending' do
160
+ record "my step 1", 25
161
+ record "my step 1", 50
162
+ record "my step 3", 75
163
+ record "my step 3", 10
164
+
165
+ step_statistics.calculate
166
+
167
+ step_statistics.total_times_plot_data.should == [100.0, 170, 150.0]
168
+ end
169
+ end
170
+ end
171
+
172
+ describe 'sample_variance' do
173
+ it 'should calculate the variance' do
174
+ step_statistics.sample_variance([1,2,3,4,5,6]).should be_within(0.1).of(3.5)
175
+ step_statistics.sample_variance([2,4,4,4,5,5,7,9]).should be_within(0.1).of(4.57)
176
+ step_statistics.sample_variance([25,50,75]).should be_within(0.1).of(625)
177
+ end
178
+ end
179
+
180
+ describe 'standard_deviation' do
181
+ it 'should calculate the standard deviation' do
182
+ sample_variance = step_statistics.sample_variance([1,2,3,4,5,6])
183
+ step_statistics.standard_deviation(sample_variance).should be_within(0.1).of(1.87)
184
+
185
+ sample_variance = step_statistics.sample_variance([2,4,4,4,5,5,7,9])
186
+ step_statistics.standard_deviation(sample_variance).should be_within(0.1).of(2.13)
187
+
188
+ sample_variance = step_statistics.sample_variance([25,50,75])
189
+ step_statistics.standard_deviation(sample_variance).should be_within(0.1).of(25)
190
+ end
191
+ end
192
+
193
+ def record(step_name, duration)
194
+ # fake a source for convenience
195
+ step_statistics.record step_name, duration, '/Users/kross/alienfast/acme/features/account management/admin_cancel_account.feature:8'
196
+ #overall_statistics.step_count_inc
197
+ end
198
+ end
199
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ module CucumberStatistics
4
+ describe UnusedSteps do
5
+ subject do
6
+ UnusedSteps.new
7
+ end
8
+
9
+ describe 'record' do
10
+ it 'should create a record' do
11
+ subject.record "my_step", "some code somewhere"
12
+ subject.all['my_step'].should == "some code somewhere"
13
+ end
14
+ end
15
+
16
+ describe 'all' do
17
+ it 'should return all records sorted alphabetically' do
18
+ subject.record "my_step 3", "some code somewhere 3"
19
+ subject.record "my_step 2", "some code somewhere 2"
20
+ subject.record "my_step 1", "some code somewhere 1"
21
+
22
+ subject.all.count.should == 3
23
+ subject.all.each_with_index do |step_name, where, index|
24
+ case index
25
+ when 1
26
+ step_name.should == "my_step 1"
27
+ where.should == "some code somewhere 1"
28
+ when 2
29
+ step_name.should == "my_step 2"
30
+ where.should == "some code somewhere 1"
31
+ when 3
32
+ step_name.should == "my_step 3"
33
+ where.should == "some code somewhere 1"
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,11 @@
1
+ # Requires supporting ruby files with custom matchers and macros, etc,
2
+ # in spec/support/ and its subdirectories.
3
+ Dir["support/**/*.rb"].each {|f| require f}
4
+
5
+ require 'cucumber_statistics'
6
+
7
+ RSpec.configure do |config|
8
+ config.mock_with :rspec
9
+
10
+ config.color_enabled = true
11
+ end
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cucumber_statistics
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Ross
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 2.14.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: haml
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: tilt
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: cucumber
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
+ - !ruby/object:Gem::Dependency
98
+ name: virtus
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: ! ' Want to know what is slowing down your build?
112
+
113
+ '
114
+ email:
115
+ - kevin.ross@alienfast.com.com
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - .document
121
+ - .gitignore
122
+ - .rvmrc
123
+ - Gemfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - cucumber_statistics.gemspec
128
+ - lib/cucumber_statistics.rb
129
+ - lib/cucumber_statistics/autoload.rb
130
+ - lib/cucumber_statistics/configuration.rb
131
+ - lib/cucumber_statistics/formatter.rb
132
+ - lib/cucumber_statistics/overall_statistics.rb
133
+ - lib/cucumber_statistics/renderer.rb
134
+ - lib/cucumber_statistics/renderer_helper.rb
135
+ - lib/cucumber_statistics/step_statistics.rb
136
+ - lib/cucumber_statistics/unused_steps.rb
137
+ - lib/cucumber_statistics/version.rb
138
+ - lib/cucumber_statistics/view/step_statistics.html
139
+ - lib/cucumber_statistics/view/step_statistics.html.haml
140
+ - notes.txt
141
+ - spec/cucumber_statistics/configuration_spec.rb
142
+ - spec/cucumber_statistics/renderer_helper_spec.rb
143
+ - spec/cucumber_statistics/renderer_spec.rb
144
+ - spec/cucumber_statistics/step_statistics_spec.rb
145
+ - spec/cucumber_statistics/unused_steps_spec.rb
146
+ - spec/spec_helper.rb
147
+ homepage: http://github.com/alienfast/cucumber_statistics
148
+ licenses:
149
+ - MIT
150
+ metadata: {}
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ! '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 2.1.9
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: An cucumber formatter that will gather statistics and generate a single page
171
+ showing step time metrics.
172
+ test_files:
173
+ - spec/cucumber_statistics/configuration_spec.rb
174
+ - spec/cucumber_statistics/renderer_helper_spec.rb
175
+ - spec/cucumber_statistics/renderer_spec.rb
176
+ - spec/cucumber_statistics/step_statistics_spec.rb
177
+ - spec/cucumber_statistics/unused_steps_spec.rb
178
+ - spec/spec_helper.rb