test-prof 0.1.0.pre5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/README.md +16 -4
  4. data/assets/flamegraph.demo.html +173 -0
  5. data/assets/flamegraph.template.html +196 -0
  6. data/assets/src/d3-tip.js +352 -0
  7. data/assets/src/d3-tip.min.js +1 -0
  8. data/assets/src/d3.flameGraph.css +92 -0
  9. data/assets/src/d3.flameGraph.js +459 -0
  10. data/assets/src/d3.flameGraph.min.css +1 -0
  11. data/assets/src/d3.flameGraph.min.js +1 -0
  12. data/assets/src/d3.v4.min.js +8 -0
  13. data/guides/any_fixture.md +1 -1
  14. data/guides/event_prof.md +30 -0
  15. data/guides/factory_default.md +109 -0
  16. data/guides/factory_prof.md +85 -0
  17. data/guides/rubocop.md +48 -0
  18. data/guides/ruby_prof.md +2 -0
  19. data/guides/stack_prof.md +5 -1
  20. data/guides/tag_prof.md +52 -0
  21. data/guides/tests_sampling.md +24 -0
  22. data/lib/test_prof.rb +31 -7
  23. data/lib/test_prof/cops/rspec/aggregate_failures.rb +140 -0
  24. data/lib/test_prof/event_prof/custom_events.rb +3 -3
  25. data/lib/test_prof/event_prof/custom_events/factory_create.rb +10 -8
  26. data/lib/test_prof/event_prof/custom_events/sidekiq_inline.rb +10 -8
  27. data/lib/test_prof/event_prof/custom_events/sidekiq_jobs.rb +12 -10
  28. data/lib/test_prof/event_prof/rspec.rb +5 -1
  29. data/lib/test_prof/factory_default.rb +58 -0
  30. data/lib/test_prof/factory_default/factory_girl_patch.rb +22 -0
  31. data/lib/test_prof/factory_doctor.rb +11 -9
  32. data/lib/test_prof/factory_doctor/rspec.rb +5 -3
  33. data/lib/test_prof/factory_prof.rb +140 -0
  34. data/lib/test_prof/factory_prof/factory_girl_patch.rb +12 -0
  35. data/lib/test_prof/factory_prof/printers/flamegraph.rb +71 -0
  36. data/lib/test_prof/factory_prof/printers/simple.rb +28 -0
  37. data/lib/test_prof/recipes/minitest/sample.rb +29 -0
  38. data/lib/test_prof/recipes/rspec/factory_default.rb +9 -0
  39. data/lib/test_prof/recipes/rspec/sample.rb +13 -0
  40. data/lib/test_prof/rspec_stamp/rspec.rb +5 -1
  41. data/lib/test_prof/rubocop.rb +3 -0
  42. data/lib/test_prof/ruby_prof.rb +6 -12
  43. data/lib/test_prof/stack_prof.rb +14 -7
  44. data/lib/test_prof/tag_prof.rb +8 -0
  45. data/lib/test_prof/tag_prof/rspec.rb +84 -0
  46. data/lib/test_prof/version.rb +1 -1
  47. metadata +48 -41
  48. data/.gitignore +0 -10
  49. data/.rspec +0 -2
  50. data/.rubocop.yml +0 -69
  51. data/.travis.yml +0 -5
  52. data/Gemfile +0 -4
  53. data/Rakefile +0 -8
  54. data/bin/setup +0 -8
  55. data/circle.yml +0 -11
  56. data/spec/integrations/any_fixture_spec.rb +0 -11
  57. data/spec/integrations/before_all_spec.rb +0 -11
  58. data/spec/integrations/event_prof_spec.rb +0 -100
  59. data/spec/integrations/factory_doctor_spec.rb +0 -20
  60. data/spec/integrations/fixtures/rspec/any_fixture_fixture.rb +0 -37
  61. data/spec/integrations/fixtures/rspec/before_all_fixture.rb +0 -32
  62. data/spec/integrations/fixtures/rspec/event_prof_factory_create_fixture.rb +0 -23
  63. data/spec/integrations/fixtures/rspec/event_prof_fixture.rb +0 -51
  64. data/spec/integrations/fixtures/rspec/event_prof_sidekiq_fixture.rb +0 -53
  65. data/spec/integrations/fixtures/rspec/factory_doctor_fixture.rb +0 -33
  66. data/spec/integrations/fixtures/rspec/rspec_stamp_fixture_tmpl.rb +0 -33
  67. data/spec/integrations/rspec_stamp_spec.rb +0 -53
  68. data/spec/spec_helper.rb +0 -38
  69. data/spec/support/ar_models.rb +0 -43
  70. data/spec/support/instrumenter_stub.rb +0 -19
  71. data/spec/support/integration_helpers.rb +0 -13
  72. data/spec/support/transactional_context.rb +0 -11
  73. data/spec/test_prof/any_fixture_spec.rb +0 -66
  74. data/spec/test_prof/event_prof_spec.rb +0 -138
  75. data/spec/test_prof/ext/float_duration_spec.rb +0 -12
  76. data/spec/test_prof/factory_doctor_spec.rb +0 -84
  77. data/spec/test_prof/rspec_stamp/parser_spec.rb +0 -58
  78. data/spec/test_prof/rspec_stamp_spec.rb +0 -281
  79. data/spec/test_prof/ruby_prof_spec.rb +0 -109
  80. data/spec/test_prof/stack_prof_spec.rb +0 -73
  81. data/spec/test_prof_spec.rb +0 -23
  82. data/test-prof.gemspec +0 -35
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
- require "test_prof/ext/float_duration"
5
-
6
- using TestProf::FloatDuration
7
-
8
- describe TestProf::FloatDuration do
9
- it "works" do
10
- expect((27 * 60 + 41.05142).duration).to eq "27:41.051"
11
- end
12
- end
@@ -1,84 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- # Init FactoryDoctor and patch FactoryGirl
6
- TestProf::FactoryDoctor.init
7
-
8
- describe TestProf::FactoryDoctor, :transactional do
9
- before { described_class.start }
10
- after { described_class.stop }
11
-
12
- # Ensure meta-queries have been performed
13
- before(:all) { User.first }
14
-
15
- describe "#result" do
16
- subject(:result) { described_class.result }
17
-
18
- it "is not bad when nothing created" do
19
- FactoryGirl.build_stubbed(:user)
20
- User.first
21
- expect(result).not_to be_bad
22
- expect(result.count).to eq 0
23
- expect(result.time).to eq 0
24
- expect(result.queries_count).to eq 1
25
- end
26
-
27
- it "detects one useless object" do
28
- FactoryGirl.create(:user)
29
- expect(result).to be_bad
30
- expect(result.count).to eq 1
31
- expect(result.time).to be > 0
32
- end
33
-
34
- it "detects not useless object when select" do
35
- user = FactoryGirl.create(:user)
36
- user.reload
37
-
38
- expect(result).not_to be_bad
39
- expect(result.count).to eq 1
40
- expect(result.queries_count).to eq 1
41
- expect(result.time).to be > 0
42
- end
43
-
44
- it "detects not useless object when update" do
45
- user = FactoryGirl.create(:user)
46
- user.update!(name: 'Phil')
47
-
48
- expect(result).not_to be_bad
49
- expect(result.count).to eq 1
50
- expect(result.queries_count).to eq 1
51
- expect(result.time).to be > 0
52
- end
53
-
54
- it "detects many objects" do
55
- FactoryGirl.create_pair(:user)
56
-
57
- expect(result).to be_bad
58
- expect(result.count).to eq 2
59
- expect(result.time).to be > 0
60
- end
61
-
62
- describe "#ignore" do
63
- it "does not track create" do
64
- described_class.ignore do
65
- FactoryGirl.create(:user)
66
- end
67
-
68
- expect(result).not_to be_bad
69
- expect(result.count).to eq 0
70
- expect(result.time).to eq 0
71
- end
72
-
73
- it "does not track queries" do
74
- user = FactoryGirl.create(:user)
75
-
76
- described_class.ignore { user.reload }
77
-
78
- expect(result).to be_bad
79
- expect(result.count).to eq 1
80
- expect(result.time).to be > 0
81
- end
82
- end
83
- end
84
- end
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
- require "test_prof/rspec_stamp/parser"
5
-
6
- describe TestProf::RSpecStamp::Parser do
7
- subject { described_class }
8
-
9
- describe ".parse" do
10
- it "handles simple expr" do
11
- res = subject.parse('it "works"')
12
- expect(res.fname).to eq 'it'
13
- expect(res.desc).to eq 'works'
14
- expect(res.tags).to be_nil
15
- expect(res.htags).to be_nil
16
- end
17
-
18
- it "handles missing desc" do
19
- res = subject.parse('it ')
20
- expect(res.fname).to eq 'it'
21
- expect(res.desc).to be_nil
22
- expect(res.tags).to be_nil
23
- expect(res.htags).to be_nil
24
- end
25
-
26
- it "handles parentheses" do
27
- res = subject.parse(' it("is") ')
28
- expect(res.fname).to eq 'it'
29
- expect(res.desc).to eq 'is'
30
- expect(res.tags).to be_nil
31
- expect(res.htags).to be_nil
32
- end
33
-
34
- it "handles several args" do
35
- res = subject.parse(' it "is o\'h", :cool, :bad ')
36
- expect(res.fname).to eq 'it'
37
- expect(res.desc).to eq "is o'h"
38
- expect(res.tags).to eq(%i[cool bad])
39
- expect(res.htags).to be_nil
40
- end
41
-
42
- it "handles hargs" do
43
- res = subject.parse(' it "is", cool: :bad, type: "feature" ')
44
- expect(res.fname).to eq 'it'
45
- expect(res.desc).to eq "is"
46
- expect(res.tags).to be_nil
47
- expect(res.htags).to eq([%i[cool bad], [:type, "feature"]])
48
- end
49
-
50
- it "handles args and hargs" do
51
- res = subject.parse(' it "is", :cool, :bad, type: :feature ')
52
- expect(res.fname).to eq 'it'
53
- expect(res.desc).to eq "is"
54
- expect(res.tags).to eq(%i[cool bad])
55
- expect(res.htags).to eq([%i[type feature]])
56
- end
57
- end
58
- end
@@ -1,281 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
- require "test_prof/rspec_stamp"
5
-
6
- describe TestProf::RSpecStamp do
7
- subject { described_class }
8
-
9
- describe "#config" do
10
- after { described_class.remove_instance_variable(:@config) }
11
-
12
- subject { described_class.config }
13
-
14
- it "handles array tags" do
15
- subject.tags = [:todo]
16
- expect(subject.tags).to eq([:todo])
17
- end
18
-
19
- it "handles string tags" do
20
- subject.tags = "todo"
21
- expect(subject.tags).to eq([:todo])
22
- end
23
-
24
- it "handle string hash tags" do
25
- subject.tags = "fix:me"
26
- expect(subject.tags).to eq([{ fix: :me }])
27
- end
28
-
29
- it "handle several tags" do
30
- subject.tags = "todo,fix:me"
31
- expect(subject.tags).to eq([:todo, { fix: :me }])
32
- end
33
- end
34
-
35
- describe ".apply_tags" do
36
- let(:code) { source.split("\n") }
37
-
38
- let(:lines) { [1] }
39
-
40
- let(:tags) { [:todo] }
41
-
42
- subject { described_class.apply_tags(code, lines, tags) }
43
-
44
- let(:source) do
45
- <<~CODE
46
- it "doesn't do what it should do" do
47
- expect(subject.body).to eq("OK")
48
- end
49
- CODE
50
- end
51
-
52
- let(:expected) do
53
- <<~CODE
54
- it "doesn't do what it should do", :todo do
55
- expect(subject.body).to eq("OK")
56
- end
57
- CODE
58
- end
59
-
60
- specify do
61
- is_expected.to eq 0
62
- expect(code.join("\n")).to eq expected.strip
63
- end
64
-
65
- context "with several examples" do
66
- let(:source) do
67
- <<~CODE
68
- it 'succeeds' do
69
- expect(subject.body).to eq("OK")
70
- end
71
-
72
- context "not found" do
73
- let(:post) { draft_post }
74
-
75
- it 'fails' do
76
- expect(subject.body).to eq("Not Found")
77
- end
78
- end
79
- CODE
80
- end
81
-
82
- let(:expected) do
83
- <<~CODE
84
- it 'succeeds' do
85
- expect(subject.body).to eq("OK")
86
- end
87
-
88
- context "not found" do
89
- let(:post) { draft_post }
90
-
91
- it 'fails', :todo do
92
- expect(subject.body).to eq("Not Found")
93
- end
94
- end
95
- CODE
96
- end
97
-
98
- let(:lines) { [8] }
99
-
100
- specify do
101
- is_expected.to eq 0
102
- expect(code.join("\n")).to eq expected.strip
103
- end
104
-
105
- context "patch all" do
106
- let(:expected) do
107
- <<~CODE
108
- it 'succeeds', :todo do
109
- expect(subject.body).to eq("OK")
110
- end
111
-
112
- context "not found" do
113
- let(:post) { draft_post }
114
-
115
- it 'fails', :todo do
116
- expect(subject.body).to eq("Not Found")
117
- end
118
- end
119
- CODE
120
- end
121
-
122
- let(:lines) { [1, 8] }
123
-
124
- specify do
125
- is_expected.to eq 0
126
- expect(code.join("\n")).to eq expected.strip
127
- end
128
- end
129
- end
130
-
131
- context "without description" do
132
- let(:source) do
133
- <<~CODE
134
- specify do
135
- expect(subject.body).to eq("Not Found")
136
- end
137
- CODE
138
- end
139
-
140
- let(:expected) do
141
- <<~CODE
142
- specify 'works', :todo do
143
- expect(subject.body).to eq("Not Found")
144
- end
145
- CODE
146
- end
147
-
148
- specify do
149
- is_expected.to eq 0
150
- expect(code.join("\n")).to eq expected.strip
151
- end
152
- end
153
-
154
- context "one-liner" do
155
- let(:source) do
156
- <<~CODE
157
- it("is") { expect(subject.body).to eq("Not Found") }
158
- CODE
159
- end
160
-
161
- let(:expected) do
162
- <<~CODE
163
- it('is', :todo) { expect(subject.body).to eq("Not Found") }
164
- CODE
165
- end
166
-
167
- specify do
168
- is_expected.to eq 0
169
- expect(code.join("\n")).to eq expected.strip
170
- end
171
- end
172
-
173
- context "one-liner without description" do
174
- let(:source) do
175
- <<~CODE
176
- it { expect(subject.body).to eq("Not Found") }
177
- CODE
178
- end
179
-
180
- let(:expected) do
181
- <<~CODE
182
- it('works', :todo) { expect(subject.body).to eq("Not Found") }
183
- CODE
184
- end
185
-
186
- specify do
187
- is_expected.to eq 0
188
- expect(code.join("\n")).to eq expected.strip
189
- end
190
- end
191
-
192
- context "with existing tags" do
193
- let(:source) do
194
- <<~CODE
195
- it 'is "KOI"', :log do
196
- expect(subject.body).to eq("Not Found")
197
- end
198
- CODE
199
- end
200
-
201
- let(:expected) do
202
- <<~CODE
203
- it 'is "KOI"', :log, :todo do
204
- expect(subject.body).to eq("Not Found")
205
- end
206
- CODE
207
- end
208
-
209
- specify do
210
- is_expected.to eq 0
211
- expect(code.join("\n")).to eq expected.strip
212
- end
213
- end
214
-
215
- context "with several tags" do
216
- let(:source) do
217
- <<~CODE
218
- specify do
219
- expect(subject.body).to eq("Not Found")
220
- end
221
- CODE
222
- end
223
-
224
- let(:expected) do
225
- <<~CODE
226
- specify 'works', :todo, a: :b, c: 'd' do
227
- expect(subject.body).to eq("Not Found")
228
- end
229
- CODE
230
- end
231
-
232
- let(:tags) { [{ a: :b }, :todo, { c: 'd' }] }
233
-
234
- specify do
235
- is_expected.to eq 0
236
- expect(code.join("\n")).to eq expected.strip
237
- end
238
-
239
- context "with existing tags" do
240
- let(:source) do
241
- <<~CODE
242
- it 'is', :log, level: :debug do
243
- expect(subject.body).to eq("Not Found")
244
- end
245
- CODE
246
- end
247
-
248
- let(:expected) do
249
- <<~CODE
250
- it 'is', :log, :todo, level: :debug, a: :b, c: 'd' do
251
- expect(subject.body).to eq("Not Found")
252
- end
253
- CODE
254
- end
255
-
256
- specify do
257
- is_expected.to eq 0
258
- expect(code.join("\n")).to eq expected.strip
259
- end
260
- end
261
- end
262
-
263
- context "with multiline description" do
264
- let(:source) do
265
- <<~CODE
266
- it %q{
267
- succeeds
268
- this time
269
- } do
270
- expect(subject.body).to eq("OK")
271
- end
272
- CODE
273
- end
274
-
275
- specify do
276
- is_expected.to eq 1
277
- expect(code.join("\n")).to eq source.strip
278
- end
279
- end
280
- end
281
- end
@@ -1,109 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe TestProf::RubyProf do
6
- # Use fresh config all for every example
7
- after { described_class.remove_instance_variable(:@config) }
8
-
9
- describe ".config" do
10
- subject { described_class.config }
11
-
12
- specify "defaults", :aggregate_failiures do
13
- expect(subject.printer).to eq :call_stack
14
- expect(subject.mode).to eq :wall
15
- expect(subject.min_percent).to eq 1
16
- expect(subject.include_threads).to eq false
17
- end
18
-
19
- describe "#resolve_printer" do
20
- it "works with custom class" do
21
- subject.printer = TestProf
22
- expect(subject.resolve_printer).to eq(['custom', TestProf])
23
- end
24
-
25
- it "raises when unknown printer" do
26
- subject.printer = 'unknown'
27
- expect { subject.resolve_printer }.to raise_error(ArgumentError)
28
- end
29
- end
30
- end
31
-
32
- describe "#profile" do
33
- let(:ruby_prof) { double("ruby_prof") }
34
- let(:profile) { double("profile") }
35
-
36
- before do
37
- stub_const("RubyProf::Profile", ruby_prof)
38
- expect(profile).to receive(:start)
39
- end
40
-
41
- specify "with default config" do
42
- expect(ruby_prof).to receive(:new).with(
43
- merge_fibers: true,
44
- include_threads: [Thread.current]
45
- ).and_return(profile)
46
-
47
- expect(described_class.profile).to be_a(described_class::Report)
48
- end
49
-
50
- specify "with custom config" do
51
- described_class.config.include_threads = true
52
-
53
- expect(ruby_prof).to receive(:new).with(
54
- merge_fibers: true
55
- ).and_return(profile)
56
-
57
- described_class.profile
58
- end
59
- end
60
-
61
- describe "Report#dump" do
62
- let(:ruby_prof) { double("ruby_prof") }
63
- let(:profile) { double("profile") }
64
- let(:result) { double("result") }
65
- let(:printer_class) { double("printer_class") }
66
- let(:printer) { double("printer") }
67
-
68
- before do
69
- stub_const("::RubyProf::Profile", ruby_prof)
70
- expect(ruby_prof).to receive(:new).and_return(profile)
71
- expect(profile).to receive(:start)
72
- expect(profile).to receive(:stop).and_return(result)
73
- end
74
-
75
- subject { described_class.profile }
76
-
77
- specify "with default config" do
78
- expect(result).to receive(:eliminate_methods!)
79
-
80
- stub_const("::RubyProf::CallStackPrinter", printer_class)
81
- expect(printer_class).to receive(:new).with(result).and_return(printer)
82
- expect(printer).to receive(:print).with(anything, min_percent: 1).and_return("")
83
-
84
- subject.dump("stub")
85
-
86
- expect(File.exist?("tmp/ruby-prof-report-call_stack-wall-stub.html")).to eq true
87
- end
88
-
89
- specify "with custom config" do
90
- described_class.config.printer = :flat
91
- described_class.config.eliminate_methods = []
92
- described_class.config.min_percent = 2
93
- described_class.config.mode = :cpu
94
-
95
- TestProf.config.timestamps = true
96
-
97
- expect(result).not_to receive(:eliminate_methods!)
98
-
99
- stub_const("RubyProf::FlatPrinter", printer_class)
100
- expect(printer_class).to receive(:new).with(result).and_return(printer)
101
- expect(printer).to receive(:print).with(anything, min_percent: 2).and_return("")
102
- expect(Time).to receive(:now).and_return(double("now", to_i: 123_454_321))
103
-
104
- subject.dump("stub")
105
-
106
- expect(File.exist?("tmp/ruby-prof-report-flat-cpu-stub-123454321.html")).to eq true
107
- end
108
- end
109
- end