effective_test_bot 1.5.3 → 1.5.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5d2b6ddf1e130f21cdd75c9de378f53d634cc6653ebb7f3099cacd8107f3167
4
- data.tar.gz: 0ff7e7d9f70e8c79025d98dc545b445a8dce7cc3af7a2fcd6fbc5b9556e8c9e0
3
+ metadata.gz: 00e994d7cc48e7ad3f6594daf5f8e13678fcc85be4b178d8565f3d4666f5724e
4
+ data.tar.gz: 3b2ec36407c22b8b8639e6a585e2fea987033affdacb0ab61e551f183965b55b
5
5
  SHA512:
6
- metadata.gz: 979b5895d9261f028a5642e76aefa2d98a2394f21b213b6bd1343cc46b9505bae18f3f013c6675fe723e6b1df5794db8043eea9514ed1ab39a707e6bc29f7bd3
7
- data.tar.gz: 6031706d32bddbdf9daffd54a7a83f2dcb3bf78712745496dcb5a7b91ec3c81c9ffb162f8265f88828c88ad92e6b912ae55d95bb92cf314a5dc31bd24d674966
6
+ metadata.gz: 32c6e8f8e86c813d29dcc283a449eda202b61791ad4ae4cdb599a7db95ab4678f9d93f9d248507ec07265f6c1a45a42b62355d42a4549d765b1684f4ad2c52b5
7
+ data.tar.gz: 6d9ad23ef9fe2bf9dd41b7ef7ec1d9664735a38f0ff8187d65bb09a85aa66c455ac4f9e26c276b0fcbe00697ea04ae796c483628d96189614d1a0f5a16ebde53
@@ -10,6 +10,7 @@ module EffectiveTestBot
10
10
  include EffectiveTestBotFormHelper
11
11
  include EffectiveTestBotLoginHelper
12
12
  include EffectiveTestBotMinitestHelper
13
+ include EffectiveTestBotPerformance
13
14
  include EffectiveTestBotScreenshotsHelper
14
15
  include EffectiveTestBotTestHelper
15
16
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveTestBot
2
- VERSION = '1.5.3'.freeze
2
+ VERSION = '1.5.4'.freeze
3
3
  end
@@ -0,0 +1,62 @@
1
+ module EffectiveTestBotPerformance
2
+ def assert_performance(milliseconds: 250, print_results: false, &block)
3
+ result = performance_test(print_results: print_results, &block)
4
+
5
+ assert (result < milliseconds), "Expected performance to be less than #{milliseconds}ms, but it was #{result}ms"
6
+ end
7
+
8
+ def performance_test(warmups: 2, iterations: 10, print_results: true, &block)
9
+ raise('expected a block') unless block_given?
10
+ raise('please install the ruby-prof gem') unless defined?(RubyProf)
11
+
12
+ # Warmup
13
+ warmups.times { block.call() }
14
+
15
+ # Use ruby-prof to Profile
16
+ profile = RubyProf::Profile.new(track_allocations: true)
17
+
18
+ results = profile.profile do
19
+ iterations.times do
20
+ print '.'
21
+ block.call()
22
+ end
23
+ end
24
+
25
+ # Return a single number result
26
+ milliseconds = ((results.threads.sum { |thread| thread.total_time } * 1000.0) / iterations.to_f).round
27
+
28
+ # Print results
29
+ print_performance_test_results(results, milliseconds) if print_results
30
+
31
+ # Returns an integer number of milliseconds
32
+ milliseconds
33
+ end
34
+
35
+ private
36
+
37
+ def print_performance_test_results(results, milliseconds)
38
+ puts('')
39
+
40
+ path = Rails.application.root.join('tmp')
41
+
42
+ # Profile Graph
43
+ filename = path.join('profile-graph.html')
44
+ File.open(filename, 'w+') { |file| RubyProf::GraphHtmlPrinter.new(results).print(file) }
45
+ puts("Profile Graph: #{filename}")
46
+
47
+ # Profile Flat
48
+ filename = path.join('profile-flat.txt')
49
+ File.open(filename, 'w+') { |file| RubyProf::FlatPrinter.new(results).print(file) }
50
+ puts("Profile Flat: #{filename}")
51
+
52
+ # Profile Stack
53
+ filename = path.join('profile-stack.html')
54
+ File.open(filename, 'w+') { |file| RubyProf::CallStackPrinter.new(results).print(file) }
55
+ puts("Profile Stack: #{filename}")
56
+
57
+ # Total Performance
58
+ puts "Performance: #{milliseconds}ms"
59
+
60
+ puts('')
61
+ end
62
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_test_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-21 00:00:00.000000000 Z
11
+ date: 2023-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -161,6 +161,7 @@ files:
161
161
  - test/support/effective_test_bot_login_helper.rb
162
162
  - test/support/effective_test_bot_minitest_helper.rb
163
163
  - test/support/effective_test_bot_mocks.rb
164
+ - test/support/effective_test_bot_performance.rb
164
165
  - test/support/effective_test_bot_screenshots_helper.rb
165
166
  - test/support/effective_test_bot_test_helper.rb
166
167
  - test/test_bot/system/application_test.rb