Skip to content
This repository was archived by the owner on Mar 13, 2024. It is now read-only.

Commit 3acbaed

Browse files
author
Udalov Igor
committed
[UCMS-11261] Update spec format
1 parent a2ecdab commit 3acbaed

File tree

9 files changed

+102
-114
lines changed

9 files changed

+102
-114
lines changed

README.md

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,6 @@ Gem with utilities used by Unity team
55
# Documentation
66

77
- ### Utils:
8-
- **CiFormatter** - Custom rspec formatter: collapses pending tests and adds some time analytics.
9-
10-
```
11-
rspec --formatter CiFormatter
12-
...bash
13-
Rubric publishing using Muppet::PublishJob
14-
updating rubric
15-
enqueues Muppet::PublishJob | Duration: 0.03981s
16-
...
17-
Groups:
18-
7.20884s ./spec/services/topics_views_count/update_spec.rb (right after midnight)
19-
5.45071s ./spec/commands/ugc/approve_topic_spec.rb (approve logic)
20-
...
21-
Single examples:
22-
5.45071s ./spec/commands/ugc/approve_topic_spec.rb (approve logic / creates a topic)
23-
4.91609s ./spec/commands/topic/update/reviews_of_published_spec.rb (has correct state value / is expected to be need approval)
24-
```
25-
268
- **Retrier** - Restarting passed block.
279
```ruby
2810
Unity::Utils::Retrier.call { 5 / 0 }
@@ -106,6 +88,56 @@ Gem with utilities used by Unity team
10688
end
10789
```
10890

91+
- ### Rake tasks:
92+
- **unity:rspec** - rspec with custom report format: collapses pending tests and adds some analytics.
93+
94+
```bash
95+
bundle exec rake unity:rspec
96+
bundle exec rake unity:rspec\['spec/queries'\]
97+
bundle exec rake unity:rspec\['spec/{jobs\,services}/'\]
98+
bundle exec rake unity:rspec\['spec/ --exclude-pattern "spec/{models\,requests}/**/*_spec.rb"'\]
99+
...
100+
[TEST PROF INFO] TagProf report for type
101+
102+
type time total %total %time avg
103+
104+
query 00:27.908 134 15.14 37.51 00:00.208
105+
service 00:15.849 167 18.87 21.31 00:00.094
106+
...
107+
108+
Top 10 slowest examples (10.23 seconds, 13.7% of total time):
109+
Api::V2::RssGeneratorJob generate for topic1 double generating does not duplicate data
110+
1.32 seconds ./spec/jobs/api/v2/rss_generator_job_spec.rb:39
111+
Exports::V2::BaseQuery behaves like queries/exports/v2/postponed when site is postponed is expected to contain
112+
1.2 seconds ./spec/support/shared_examples/queries/exports/v2/postponed_example.rb:28
113+
...
114+
115+
Top 10 slowest example groups:
116+
Exports::V2::Indexnow::TopicsQuery
117+
0.89632 seconds average (5.38 seconds / 6 examples) ./spec/queries/exports/v2/indexnow/topics_query_spec.rb:5
118+
Exports::V2::RssAggregation
119+
0.70154 seconds average (5.61 seconds / 8 examples) ./spec/services/exports/rss_aggregation_spec.rb:5
120+
...
121+
122+
Finished in 1 minute 14.71 seconds (files took 7.29 seconds to load)
123+
885 examples, 0 failures, 31 pending
124+
125+
Randomized with seed 6856
126+
127+
[TEST PROF INFO] Factories usage
128+
129+
Total: 1624
130+
Total top-level: 1298
131+
Total time: 00:54.568 (out of 01:16.029)
132+
Total uniq factories: 12
133+
134+
total top-level total time time per call top-level time name
135+
136+
521 521 8.9882s 0.0173s 8.9882s v2_topic
137+
394 394 17.5059s 0.0444s 17.5059s v2_push_topic
138+
...
139+
```
140+
109141
## Installation
110142

111143
Add this line to your application's Gemfile:

lib/unity-utils.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# frozen_string_literal: true
22

33
require_relative 'unity/utils'
4+
require_relative 'unity/railtie' if defined?(Rails::Railtie)

lib/unity/railtie.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
require_relative 'spec/support/ci_formatter'
4+
require_relative 'spec/support/tag_prof'
5+
6+
module Unity
7+
class Railtie < Rails::Railtie
8+
railtie_name :unity_utils
9+
10+
rake_tasks do
11+
namespace :unity do
12+
desc 'Run tests'
13+
task :rspec, %i[options] => :environment do |_t, args|
14+
system("FPROF=1 TAG_PROF=type bundle exec rspec #{args.options} --require test-prof --format CiFormatter --profile")
15+
end
16+
end
17+
18+
task unity_utils: ['unity:rspec']
19+
end
20+
end
21+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
require 'rspec/core'
4+
5+
RSpec::Support.require_rspec_core 'formatters/progress_formatter'
6+
7+
class CiFormatter < RSpec::Core::Formatters::ProgressFormatter
8+
RSpec::Core::Formatters.register self
9+
10+
def example_pending(_); end
11+
12+
def dump_pending(_); end
13+
end

lib/unity/spec/support/tag_prof.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
require 'rspec/core'
4+
5+
# https://test-prof.evilmartians.io/profilers/tag_prof?id=pro-tip-more-types
6+
RSpec.configure do |config|
7+
config.define_derived_metadata(file_path: %r{/spec/}) do |metadata|
8+
# do not overwrite type if it's already set
9+
next if metadata.key?(:type)
10+
11+
match = metadata[:location].match(%r{/spec/([^/]+)/})
12+
metadata[:type] = match[1].singularize.to_sym
13+
end
14+
end

lib/unity/utils.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
require_relative 'modules/loggable'
88

99
# Utils
10-
require_relative 'utils/ci_formatter'
1110
require_relative 'utils/faraday_with_retries'
1211
require_relative 'utils/retrier'
1312
require_relative 'utils/thread_pool'

lib/unity/utils/ci_formatter.rb

Lines changed: 0 additions & 93 deletions
This file was deleted.

lib/unity/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Unity
4-
VERSION = '0.3.0'
4+
VERSION = '0.4.0'
55
end

unity-utils.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
2121

2222
spec.add_dependency 'activesupport', '>= 4.2'
2323
spec.add_dependency 'faraday', '>= 1.0', '< 1.4'
24-
spec.add_dependency 'rspec-core', '>= 3.9'
24+
spec.add_dependency 'rspec-rails', '>= 5.0'
2525
spec.add_dependency 'ruby-progressbar', '>= 1.11.0'
26+
spec.add_dependency 'test-prof', '~> 1.0'
2627
end

0 commit comments

Comments
 (0)