File: profilers_spec.rb

package info (click to toggle)
ruby-test-prof 1.6.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,448 kB
  • sloc: ruby: 13,093; sh: 4; makefile: 4
file content (104 lines) | stat: -rw-r--r-- 3,458 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# frozen_string_literal: true

PROFILERS_AVAILABLE =
  begin
    require "stackprof"
    require "ruby-prof"
    require "vernier"
  rescue LoadError
  end

describe "general profilers", skip: !PROFILERS_AVAILABLE do
  context "RSpec integration" do
    context "ruby prof" do
      specify "per example" do
        output = run_rspec("ruby_prof")

        expect(output).to match(/RubyProf report generated.+ruby_prof_fixture-rb-1-1/)
        expect(output).to include("0 failures")
      end

      specify "global" do
        output = run_rspec("ruby_prof", env: {"TEST_RUBY_PROF" => "1"})

        expect(output).to include("RubyProf enabled globally")
        expect(output).to include("RubyProf report generated")
        expect(output).to include("0 failures")
      end

      specify "examples only" do
        output = run_rspec("ruby_prof", env: {"TEST_RUBY_PROF" => "1", "TEST_RUBY_PROF_BOOT" => "0"})

        expect(output).to include("RubyProf enabled for examples")
        expect(output).to include("RubyProf report generated")
        expect(output).to include("0 failures")
      end
    end

    context "stackprof" do
      specify "per example", skip: "StackProf crashes with segfault occasianally" do
        output = run_rspec("stackprof")

        expect(output).to match(/StackProf report generated.+stackprof_fixture-rb-1-1/)
        expect(output).to include("0 failures")
      end

      specify "global" do
        output = run_rspec("stackprof", env: {"TEST_STACK_PROF" => "1"})

        expect(output).to include("StackProf (raw) enabled globally")
        expect(output).to include("StackProf report generated")
        expect(output).to include("StackProf JSON report generated")
        expect(output).to include("0 failures")
      end
    end

    context "vernier" do
      specify "per example" do
        output = run_rspec("vernier")

        expect(output).to match(/Vernier report generated.+vernier_fixture-rb-1-1/)
        expect(output).to include("0 failures")
      end

      specify "global" do
        output = run_rspec("vernier", env: {"TEST_VERNIER" => "1"})

        expect(output).to include("Vernier enabled globally")
        expect(output).to include("Vernier report generated")
        expect(output).to include("0 failures")
      end

      specify "with hooks vernier contains rails events" do
        output = run_rspec("vernier", env: {"TEST_VERNIER_HOOKS" => "rails"})
        sample_rails_event = "load_config_initializer.railties"
        vernier_report = File.read("tmp/test_prof/vernier-report-wall--vernier_fixture-rb-1-1-.json")

        expect(output).to include("0 failures")
        expect(vernier_report).to match(/#{sample_rails_event}/)
      end
    end
  end

  context "Minitest integration" do
    context "rubyprof" do
      specify "global" do
        output = run_minitest("profilers", env: {"TEST_RUBY_PROF" => "1"})

        expect(output).to include("RubyProf enabled globally")
        expect(output).to include("RubyProf report generated")
        expect(output).to include("0 failures, 0 errors")
      end
    end

    context "stackprof" do
      specify "global" do
        output = run_minitest("profilers", env: {"TEST_STACK_PROF" => "1"})

        expect(output).to include("StackProf (raw) enabled globally")
        expect(output).to include("StackProf report generated")
        expect(output).to include("0 failures, 0 errors")
      end
    end
  end
end