test-prof 0.1.0.beta1 → 0.1.0.pre5
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.
- checksums.yaml +4 -4
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.rubocop.yml +69 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +2 -6
- data/Rakefile +8 -0
- data/bin/setup +8 -0
- data/circle.yml +11 -0
- data/guides/any_fixture.md +1 -1
- data/guides/stack_prof.md +1 -1
- data/lib/test_prof/factory_doctor.rb +9 -11
- data/lib/test_prof/ruby_prof.rb +5 -2
- data/lib/test_prof/stack_prof.rb +5 -2
- data/lib/test_prof/version.rb +1 -1
- data/lib/test_prof.rb +1 -19
- data/spec/integrations/any_fixture_spec.rb +11 -0
- data/spec/integrations/before_all_spec.rb +11 -0
- data/spec/integrations/event_prof_spec.rb +100 -0
- data/spec/integrations/factory_doctor_spec.rb +20 -0
- data/spec/integrations/fixtures/rspec/any_fixture_fixture.rb +37 -0
- data/spec/integrations/fixtures/rspec/before_all_fixture.rb +32 -0
- data/spec/integrations/fixtures/rspec/event_prof_factory_create_fixture.rb +23 -0
- data/spec/integrations/fixtures/rspec/event_prof_fixture.rb +51 -0
- data/spec/integrations/fixtures/rspec/event_prof_sidekiq_fixture.rb +53 -0
- data/spec/integrations/fixtures/rspec/factory_doctor_fixture.rb +33 -0
- data/spec/integrations/fixtures/rspec/rspec_stamp_fixture_tmpl.rb +33 -0
- data/spec/integrations/rspec_stamp_spec.rb +53 -0
- data/spec/spec_helper.rb +38 -0
- data/spec/support/ar_models.rb +43 -0
- data/spec/support/instrumenter_stub.rb +19 -0
- data/spec/support/integration_helpers.rb +13 -0
- data/spec/support/transactional_context.rb +11 -0
- data/spec/test_prof/any_fixture_spec.rb +66 -0
- data/spec/test_prof/event_prof_spec.rb +138 -0
- data/spec/test_prof/ext/float_duration_spec.rb +12 -0
- data/spec/test_prof/factory_doctor_spec.rb +84 -0
- data/spec/test_prof/rspec_stamp/parser_spec.rb +58 -0
- data/spec/test_prof/rspec_stamp_spec.rb +281 -0
- data/spec/test_prof/ruby_prof_spec.rb +109 -0
- data/spec/test_prof/stack_prof_spec.rb +73 -0
- data/spec/test_prof_spec.rb +23 -0
- data/test-prof.gemspec +35 -0
- metadata +38 -21
- data/CHANGELOG.md +0 -7
- data/assets/flamegraph.demo.html +0 -173
- data/assets/flamegraph.template.html +0 -196
- data/assets/src/d3-tip.js +0 -352
- data/assets/src/d3-tip.min.js +0 -1
- data/assets/src/d3.flameGraph.css +0 -92
- data/assets/src/d3.flameGraph.js +0 -459
- data/assets/src/d3.flameGraph.min.css +0 -1
- data/assets/src/d3.flameGraph.min.js +0 -1
- data/assets/src/d3.v4.min.js +0 -8
- data/guides/factory_prof.md +0 -85
- data/guides/rubocop.md +0 -48
- data/lib/test_prof/cops/rspec/aggregate_failures.rb +0 -140
- data/lib/test_prof/factory_prof/factory_girl_patch.rb +0 -12
- data/lib/test_prof/factory_prof/printers/flamegraph.rb +0 -71
- data/lib/test_prof/factory_prof/printers/simple.rb +0 -28
- data/lib/test_prof/factory_prof.rb +0 -140
- data/lib/test_prof/rubocop.rb +0 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c9b58b9e9898a5b72c42700bfc0751c31639aefc
|
|
4
|
+
data.tar.gz: 4bf4799f92e06e8e9b3c000fe08659171cd2293d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 50f89b1bce0e4c45bb00aacaff4cfb6f1e1f8f2875cc0fc38f2317244c662b24f8b56788bb1980221b5ca6987753b3b190a3b9e671de958f5a581a1616ca0fe7
|
|
7
|
+
data.tar.gz: ed479e4104b92b159a7872fc7dbb85e6b69308c954dade0ca2cb7d044bc60ef11f483e905cb569ceaa0b686a7b07bbc49de841f3424f3b4535f01acc9f985167
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
Include:
|
|
3
|
+
- 'lib/**/*.rb'
|
|
4
|
+
- 'lib/**/*.rake'
|
|
5
|
+
- 'spec/**/*.rb'
|
|
6
|
+
Exclude:
|
|
7
|
+
- 'bin/**/*'
|
|
8
|
+
- 'spec/dummy/**/*'
|
|
9
|
+
- 'tmp/**/*'
|
|
10
|
+
- 'Rakefile'
|
|
11
|
+
- 'Gemfile'
|
|
12
|
+
- '*.gemspec'
|
|
13
|
+
DisplayCopNames: true
|
|
14
|
+
StyleGuideCopsOnly: false
|
|
15
|
+
TargetRubyVersion: 2.3
|
|
16
|
+
|
|
17
|
+
Rails:
|
|
18
|
+
Enabled: false
|
|
19
|
+
|
|
20
|
+
Style/AccessorMethodName:
|
|
21
|
+
Enabled: false
|
|
22
|
+
|
|
23
|
+
Style/TrivialAccessors:
|
|
24
|
+
Enabled: false
|
|
25
|
+
|
|
26
|
+
Style/Documentation:
|
|
27
|
+
Exclude:
|
|
28
|
+
- 'spec/**/*.rb'
|
|
29
|
+
|
|
30
|
+
Style/StringLiterals:
|
|
31
|
+
Enabled: false
|
|
32
|
+
|
|
33
|
+
Style/RegexpLiteral:
|
|
34
|
+
Enabled: false
|
|
35
|
+
|
|
36
|
+
Style/SpaceInsideStringInterpolation:
|
|
37
|
+
EnforcedStyle: no_space
|
|
38
|
+
|
|
39
|
+
Style/ClassAndModuleChildren:
|
|
40
|
+
Enabled: false
|
|
41
|
+
|
|
42
|
+
Style/BlockDelimiters:
|
|
43
|
+
Exclude:
|
|
44
|
+
- 'spec/**/*.rb'
|
|
45
|
+
|
|
46
|
+
Lint/AmbiguousRegexpLiteral:
|
|
47
|
+
Enabled: false
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
Metrics/MethodLength:
|
|
51
|
+
Enabled: false
|
|
52
|
+
|
|
53
|
+
Metrics/AbcSize:
|
|
54
|
+
Enabled: false
|
|
55
|
+
|
|
56
|
+
Metrics/LineLength:
|
|
57
|
+
Max: 100
|
|
58
|
+
Exclude:
|
|
59
|
+
- 'spec/**/*.rb'
|
|
60
|
+
|
|
61
|
+
Metrics/BlockLength:
|
|
62
|
+
Exclude:
|
|
63
|
+
- 'spec/**/*.rb'
|
|
64
|
+
|
|
65
|
+
Rails/Date:
|
|
66
|
+
Enabled: false
|
|
67
|
+
|
|
68
|
+
Rails/TimeZone:
|
|
69
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
CHANGED
|
@@ -55,9 +55,7 @@ Checkout our guides for each specific tool:
|
|
|
55
55
|
|
|
56
56
|
- [Factory Doctor](https://github.com/palkan/test-prof/tree/master/guides/factory_doctor.md)
|
|
57
57
|
|
|
58
|
-
-
|
|
59
|
-
|
|
60
|
-
- [Rubocop Cops](https://github.com/palkan/test-prof/tree/master/guides/rubocop.md)
|
|
58
|
+
- Factory Profiler
|
|
61
59
|
|
|
62
60
|
## Tips and Tricks (or _Recipes_)
|
|
63
61
|
|
|
@@ -92,12 +90,10 @@ Or TODO list:
|
|
|
92
90
|
|
|
93
91
|
- Better Minitest integration (PRs welcome!)
|
|
94
92
|
|
|
95
|
-
- Other data generation library support (e.g [Fabricator](http://fabricationgem.org/))
|
|
93
|
+
- Other data generation library support (e.g [Fabricator](http://fabricationgem.org/))
|
|
96
94
|
|
|
97
95
|
- Improve FactoryDoctor
|
|
98
96
|
|
|
99
|
-
- Add more Rubocop cops (e.g. `CreateListLimit`)
|
|
100
|
-
|
|
101
97
|
## License
|
|
102
98
|
|
|
103
99
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/setup
ADDED
data/circle.yml
ADDED
data/guides/any_fixture.md
CHANGED
|
@@ -18,7 +18,7 @@ RSpec.shared_context "account", account: true do
|
|
|
18
18
|
@account = TestProf::AnyFixture.register(:account) do
|
|
19
19
|
# Do anything here, AnyFixture keeps track of affected DB tables
|
|
20
20
|
# For example, you can use factories here
|
|
21
|
-
|
|
21
|
+
create(:account)
|
|
22
22
|
|
|
23
23
|
# or with Fabrication
|
|
24
24
|
Fabricate(:account)
|
data/guides/stack_prof.md
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
require "test_prof/factory_doctor/factory_girl_patch"
|
|
4
4
|
|
|
5
5
|
module TestProf
|
|
6
|
-
# FactoryDoctor is a tool that helps you identify
|
|
7
|
-
# tests that perform unnecessary database queries.
|
|
6
|
+
# FactoryDoctor is a tool that helps you identify such _bad_ tests,
|
|
7
|
+
# i.e. tests that perform unnecessary database queries.
|
|
8
8
|
module FactoryDoctor
|
|
9
9
|
class Result # :nodoc:
|
|
10
10
|
attr_reader :count, :time, :queries_count
|
|
@@ -81,16 +81,14 @@ module TestProf
|
|
|
81
81
|
def within_factory(strategy)
|
|
82
82
|
return yield if ignore? || !running? || (strategy != :create)
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
@depth -= 1
|
|
84
|
+
ts = Time.now if @depth.zero?
|
|
85
|
+
@depth += 1
|
|
86
|
+
@count += 1
|
|
87
|
+
yield
|
|
88
|
+
ensure
|
|
89
|
+
@depth -= 1
|
|
91
90
|
|
|
92
|
-
|
|
93
|
-
end
|
|
91
|
+
@time += (Time.now - ts) if @depth.zero?
|
|
94
92
|
end
|
|
95
93
|
|
|
96
94
|
private
|
data/lib/test_prof/ruby_prof.rb
CHANGED
|
@@ -110,8 +110,11 @@ module TestProf
|
|
|
110
110
|
private
|
|
111
111
|
|
|
112
112
|
def build_path(name, printer)
|
|
113
|
-
TestProf.
|
|
114
|
-
|
|
113
|
+
TestProf.with_timestamps(
|
|
114
|
+
File.join(
|
|
115
|
+
TestProf.config.output_dir,
|
|
116
|
+
"ruby-prof-report-#{printer}-#{config.mode}-#{name}.html"
|
|
117
|
+
)
|
|
115
118
|
)
|
|
116
119
|
end
|
|
117
120
|
|
data/lib/test_prof/stack_prof.rb
CHANGED
|
@@ -88,8 +88,11 @@ module TestProf
|
|
|
88
88
|
private
|
|
89
89
|
|
|
90
90
|
def build_path(name)
|
|
91
|
-
TestProf.
|
|
92
|
-
|
|
91
|
+
TestProf.with_timestamps(
|
|
92
|
+
File.join(
|
|
93
|
+
TestProf.config.output_dir,
|
|
94
|
+
"stack-prof-report-#{config.mode}-#{name}.dump"
|
|
95
|
+
)
|
|
93
96
|
)
|
|
94
97
|
end
|
|
95
98
|
|
data/lib/test_prof/version.rb
CHANGED
data/lib/test_prof.rb
CHANGED
|
@@ -52,27 +52,10 @@ module TestProf
|
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
-
# Return absolute path to asset
|
|
56
|
-
def asset_path(filename)
|
|
57
|
-
::File.expand_path(filename, ::File.join(::File.dirname(__FILE__), "..", "assets"))
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# Return a path to store artefact
|
|
61
|
-
def artefact_path(filename)
|
|
62
|
-
with_timestamps(
|
|
63
|
-
::File.join(
|
|
64
|
-
config.output_dir,
|
|
65
|
-
filename
|
|
66
|
-
)
|
|
67
|
-
)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
private
|
|
71
|
-
|
|
72
55
|
def with_timestamps(path)
|
|
73
56
|
return path unless config.timestamps?
|
|
74
57
|
timestamps = "-#{Time.now.to_i}"
|
|
75
|
-
"#{path.sub(/\.\w+$/, '')}#{timestamps}#{
|
|
58
|
+
"#{path.sub(/\.\w+$/, '')}#{timestamps}#{File.extname(path)}"
|
|
76
59
|
end
|
|
77
60
|
end
|
|
78
61
|
|
|
@@ -104,5 +87,4 @@ require "test_prof/ruby_prof"
|
|
|
104
87
|
require "test_prof/stack_prof"
|
|
105
88
|
require "test_prof/event_prof"
|
|
106
89
|
require "test_prof/factory_doctor"
|
|
107
|
-
require "test_prof/factory_prof"
|
|
108
90
|
require "test_prof/rspec_stamp"
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe "EventProf" do
|
|
6
|
+
specify "RSpec integration", :aggregate_failures do
|
|
7
|
+
output = run_rspec('event_prof', env: { 'EVENT_PROF' => 'test.event' })
|
|
8
|
+
|
|
9
|
+
expect(output).to include("EventProf results for test.event")
|
|
10
|
+
expect(output).to match(/Total time: 25:56\.\d{3}/)
|
|
11
|
+
expect(output).to include("Total events: 8")
|
|
12
|
+
|
|
13
|
+
expect(output).to include("Top 5 slowest suites (by time):")
|
|
14
|
+
expect(output).to include("Top 5 slowest tests (by time):")
|
|
15
|
+
|
|
16
|
+
expect(output).to include(
|
|
17
|
+
"Another something (./event_prof_fixture.rb:42) – 16:40.000 (1 / 2)\n"\
|
|
18
|
+
"Something (./event_prof_fixture.rb:21) – 09:16.100 (7 / 3)"
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
expect(output).to include(
|
|
22
|
+
"do very long (./event_prof_fixture.rb:47) – 16:40.000 (1)\n"\
|
|
23
|
+
"invokes twice (./event_prof_fixture.rb:27) – 06:20.000 (2)\n"\
|
|
24
|
+
"invokes many times (./event_prof_fixture.rb:33) – 02:16.000 (4)\n"\
|
|
25
|
+
"invokes once (./event_prof_fixture.rb:22) – 00:40.100 (1)"
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
specify "RSpec integration with rank by count", :aggregate_failures do
|
|
30
|
+
output = run_rspec(
|
|
31
|
+
'event_prof',
|
|
32
|
+
env: { 'EVENT_PROF' => 'test.event', 'EVENT_PROF_RANK' => 'count' }
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
expect(output).to include("EventProf results for test.event")
|
|
36
|
+
expect(output).to match(/Total time: 25:56\.\d{3}/)
|
|
37
|
+
expect(output).to include("Total events: 8")
|
|
38
|
+
|
|
39
|
+
expect(output).to include("Top 5 slowest suites (by count):")
|
|
40
|
+
expect(output).to include("Top 5 slowest tests (by count):")
|
|
41
|
+
|
|
42
|
+
expect(output).to include(
|
|
43
|
+
"Something (./event_prof_fixture.rb:21) – 09:16.100 (7 / 3)\n"\
|
|
44
|
+
"Another something (./event_prof_fixture.rb:42) – 16:40.000 (1 / 2)"
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
expect(output).to include(
|
|
48
|
+
"invokes many times (./event_prof_fixture.rb:33) – 02:16.000 (4)\n"\
|
|
49
|
+
"invokes twice (./event_prof_fixture.rb:27) – 06:20.000 (2)\n"\
|
|
50
|
+
"invokes once (./event_prof_fixture.rb:22) – 00:40.100 (1)\n"\
|
|
51
|
+
"do very long (./event_prof_fixture.rb:47) – 16:40.000 (1)"
|
|
52
|
+
)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context "CustomEvents" do
|
|
56
|
+
it "works with factory.create" do
|
|
57
|
+
output = run_rspec(
|
|
58
|
+
'event_prof_factory_create',
|
|
59
|
+
env: { 'EVENT_PROF' => 'factory.create' }
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
expect(output).to include("EventProf results for factory.create")
|
|
63
|
+
expect(output).to match(/Total time: \d{2}:\d{2}\.\d{3}/)
|
|
64
|
+
expect(output).to include("Total events: 3")
|
|
65
|
+
|
|
66
|
+
expect(output).to match(%r{Post \(./event_prof_factory_create_fixture.rb:7\) – \d{2}:\d{2}.\d{3} \(2 / 1\)})
|
|
67
|
+
expect(output).to match(%r{User \(./event_prof_factory_create_fixture.rb:16\) – \d{2}:\d{2}.\d{3} \(1 / 1\)})
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "works with sidekiq.inline" do
|
|
71
|
+
output = run_rspec(
|
|
72
|
+
'event_prof_sidekiq',
|
|
73
|
+
env: { 'EVENT_PROF' => 'sidekiq.inline' }
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
expect(output).to include("EventProf results for sidekiq.inline")
|
|
77
|
+
expect(output).to match(/Total time: \d{2}:\d{2}\.\d{3}/)
|
|
78
|
+
expect(output).to include("Total events: 3")
|
|
79
|
+
|
|
80
|
+
expect(output).to match(%r{SingleJob \(./event_prof_sidekiq_fixture.rb:27\) – \d{2}:\d{2}.\d{3} \(2 / 2\)})
|
|
81
|
+
expect(output).to match(%r{BatchJob \(./event_prof_sidekiq_fixture.rb:39\) – \d{2}:\d{2}.\d{3} \(1 / 2\)})
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "works with sidekiq.jobs" do
|
|
85
|
+
output = run_rspec(
|
|
86
|
+
'event_prof_sidekiq',
|
|
87
|
+
env: { 'EVENT_PROF' => 'sidekiq.jobs' }
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
expect(output).to include("EventProf results for sidekiq.jobs")
|
|
91
|
+
expect(output).to match(/Total time: \d{2}:\d{2}\.\d{3}/)
|
|
92
|
+
expect(output).to include("Total events: 6")
|
|
93
|
+
|
|
94
|
+
expect(output).to include("Top 5 slowest suites (by count):")
|
|
95
|
+
|
|
96
|
+
expect(output).to match(%r{SingleJob \(./event_prof_sidekiq_fixture.rb:27\) – \d{2}:\d{2}.\d{3} \(2 / 2\)})
|
|
97
|
+
expect(output).to match(%r{BatchJob \(./event_prof_sidekiq_fixture.rb:39\) – \d{2}:\d{2}.\d{3} \(4 / 2\)})
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe "FactoryDoctor" do
|
|
6
|
+
specify "RSpec integration", :aggregate_failures do
|
|
7
|
+
output = run_rspec('factory_doctor', env: { 'FDOC' => '1' })
|
|
8
|
+
|
|
9
|
+
expect(output).to include("FactoryDoctor report")
|
|
10
|
+
expect(output).to include("Total (potentially) bad examples: 3")
|
|
11
|
+
expect(output).to match(/Total wasted time: \d{2}:\d{2}\.\d{3}/)
|
|
12
|
+
|
|
13
|
+
expect(output).to include("User (./factory_doctor_fixture.rb:7)")
|
|
14
|
+
expect(output).to include("generates random names (./factory_doctor_fixture.rb:10) – 2 records created")
|
|
15
|
+
expect(output).to include("validates name (./factory_doctor_fixture.rb:15) – 1 record created")
|
|
16
|
+
expect(output).to include("clones (./factory_doctor_fixture.rb:25) – 1 record created")
|
|
17
|
+
expect(output).not_to include("is ignored")
|
|
18
|
+
expect(output).not_to include("creates and reloads user")
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH.unshift File.expand_path("../../../../lib", __FILE__)
|
|
4
|
+
require_relative "../../../support/ar_models"
|
|
5
|
+
require_relative "../../../support/transactional_context"
|
|
6
|
+
require "test_prof/recipes/rspec/any_fixture"
|
|
7
|
+
|
|
8
|
+
shared_context "user", user: true do
|
|
9
|
+
before(:all) do
|
|
10
|
+
@user = TestProf::AnyFixture.register(:user) do
|
|
11
|
+
FactoryGirl.create(:user)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
let(:user) { User.find(@user.id) }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe "User", :user do
|
|
19
|
+
it "creates user" do
|
|
20
|
+
user.name = ''
|
|
21
|
+
expect(user).not_to be_valid
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context "with clean fixture", :transactional, :with_clean_fixture do
|
|
25
|
+
specify "no users" do
|
|
26
|
+
expect(User.count).to eq 0
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe "Post", :user do
|
|
32
|
+
let(:post) { FactoryGirl.create(:post, user: user) }
|
|
33
|
+
|
|
34
|
+
it "creates post with the same user" do
|
|
35
|
+
expect { post }.not_to change(User, :count)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH.unshift File.expand_path("../../../../lib", __FILE__)
|
|
4
|
+
require_relative "../../../support/ar_models"
|
|
5
|
+
require "test_prof/recipes/rspec/before_all"
|
|
6
|
+
|
|
7
|
+
describe "User" do
|
|
8
|
+
context "with before_all" do
|
|
9
|
+
before_all do
|
|
10
|
+
@user = FactoryGirl.create(:user)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
let(:user) { User.find(@user.id) }
|
|
14
|
+
|
|
15
|
+
it "validates name" do
|
|
16
|
+
user.name = ''
|
|
17
|
+
expect(user).not_to be_valid
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "clones" do
|
|
21
|
+
cloned = user.clone
|
|
22
|
+
cloned.save!
|
|
23
|
+
expect(cloned.reload.name).to include("(cloned)")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context "without before_all" do
|
|
28
|
+
specify "no users" do
|
|
29
|
+
expect(User.count).to eq 0
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH.unshift File.expand_path("../../../../lib", __FILE__)
|
|
4
|
+
require_relative "../../../support/ar_models"
|
|
5
|
+
require "test-prof"
|
|
6
|
+
|
|
7
|
+
describe "Post" do
|
|
8
|
+
let(:user) { FactoryGirl.create(:user) }
|
|
9
|
+
|
|
10
|
+
it "generates random names" do
|
|
11
|
+
user2 = FactoryGirl.create(:post).user
|
|
12
|
+
expect(user.name).not_to eq user2.name
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe "User" do
|
|
17
|
+
let(:user) { FactoryGirl.create(:user) }
|
|
18
|
+
|
|
19
|
+
it "validates name" do
|
|
20
|
+
user.name = ''
|
|
21
|
+
expect(user).not_to be_valid
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH.unshift File.expand_path("../../../../lib", __FILE__)
|
|
4
|
+
require "active_support"
|
|
5
|
+
require "test-prof"
|
|
6
|
+
|
|
7
|
+
TestProf::EventProf.configure do |config|
|
|
8
|
+
config.per_example = true
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
module Instrumenter
|
|
12
|
+
def self.notify(_event, time)
|
|
13
|
+
ActiveSupport::Notifications.publish(
|
|
14
|
+
'test.event',
|
|
15
|
+
0,
|
|
16
|
+
time
|
|
17
|
+
)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe "Something" do
|
|
22
|
+
it "invokes once" do
|
|
23
|
+
Instrumenter.notify 'test.event', 40.1
|
|
24
|
+
expect(true).to eq true
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "invokes twice" do
|
|
28
|
+
Instrumenter.notify 'test.event', 140
|
|
29
|
+
Instrumenter.notify 'test.event', 240
|
|
30
|
+
expect(true).to eq true
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "invokes many times" do
|
|
34
|
+
Instrumenter.notify 'test.event', 14
|
|
35
|
+
Instrumenter.notify 'test.event', 40
|
|
36
|
+
Instrumenter.notify 'test.event', 42
|
|
37
|
+
Instrumenter.notify 'test.event', 40
|
|
38
|
+
expect(true).to eq true
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
describe "Another something" do
|
|
43
|
+
it "do nothing" do
|
|
44
|
+
expect(true).to eq true
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "do very long" do
|
|
48
|
+
Instrumenter.notify 'test.event', 1000
|
|
49
|
+
expect(true).to eq true
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH.unshift File.expand_path("../../../../lib", __FILE__)
|
|
4
|
+
require "active_support"
|
|
5
|
+
require "sidekiq/testing"
|
|
6
|
+
|
|
7
|
+
Sidekiq::Testing.inline!
|
|
8
|
+
|
|
9
|
+
class SingleJob
|
|
10
|
+
include Sidekiq::Worker
|
|
11
|
+
|
|
12
|
+
def perform(*_args)
|
|
13
|
+
true
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class BatchJob
|
|
18
|
+
include Sidekiq::Worker
|
|
19
|
+
|
|
20
|
+
def perform(count)
|
|
21
|
+
count.times { SingleJob.perform_async(true) }
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
require "test-prof"
|
|
26
|
+
|
|
27
|
+
describe "SingleJob" do
|
|
28
|
+
it "invokes once" do
|
|
29
|
+
SingleJob.perform_async(1)
|
|
30
|
+
expect(true).to eq true
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "invokes twice" do
|
|
34
|
+
SingleJob.perform_async(2)
|
|
35
|
+
expect(true).to eq true
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe "BatchJob" do
|
|
40
|
+
it "invokes nested" do
|
|
41
|
+
BatchJob.perform_async(3)
|
|
42
|
+
expect(true).to eq true
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context "when fake" do
|
|
46
|
+
it "is fake" do
|
|
47
|
+
Sidekiq::Testing.fake! do
|
|
48
|
+
BatchJob.perform_async(3)
|
|
49
|
+
end
|
|
50
|
+
expect(true).to eq true
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH.unshift File.expand_path("../../../../lib", __FILE__)
|
|
4
|
+
require_relative "../../../support/ar_models"
|
|
5
|
+
require "test-prof"
|
|
6
|
+
|
|
7
|
+
describe "User" do
|
|
8
|
+
let(:user) { FactoryGirl.create(:user) }
|
|
9
|
+
|
|
10
|
+
it "generates random names" do
|
|
11
|
+
user2 = FactoryGirl.create(:user)
|
|
12
|
+
expect(user.name).not_to eq user2.name
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "validates name" do
|
|
16
|
+
user.name = ''
|
|
17
|
+
expect(user).not_to be_valid
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "creates and reloads user" do
|
|
21
|
+
user = FactoryGirl.create(:user, name: 'John')
|
|
22
|
+
expect(User.find(user.id).name).to eq 'John'
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "clones" do
|
|
26
|
+
expect(user.clone.name).to include("(cloned)")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "is ignored", :fd_ignore do
|
|
30
|
+
user.name = ''
|
|
31
|
+
expect(user).not_to be_valid
|
|
32
|
+
end
|
|
33
|
+
end
|