File: stack_prof_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 (84 lines) | stat: -rw-r--r-- 2,010 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
# frozen_string_literal: true

describe TestProf::StackProf do
  # Use fresh config all for every example
  after { described_class.remove_instance_variable(:@config) }

  describe ".config" do
    subject { described_class.config }

    specify "defaults", :aggregate_failures do
      expect(subject.mode).to eq :wall
      expect(subject.interval).to be_nil
      expect(subject.raw).to eq true
    end
  end

  describe "#profile" do
    let(:stack_prof) { double("stack_prof") }

    before do
      stub_const("StackProf", stack_prof)
    end

    specify "with default config" do
      expect(stack_prof).to receive(:start).with(
        mode: :wall,
        raw: true
      )

      described_class.profile
    end

    specify "with custom config" do
      described_class.config.raw = false
      described_class.config.mode = :cpu

      expect(stack_prof).to receive(:start).with(
        mode: :cpu,
        raw: false
      )

      described_class.profile
    end

    specify "with ignore_gc option" do
      described_class.config.ignore_gc = true

      expect(stack_prof).to receive(:start).with(
        mode: :wall,
        raw: true,
        ignore_gc: true
      )

      described_class.profile
    end

    specify "when block is given" do
      expect(stack_prof).to receive(:run).with(
        out: File.join(TestProf.config.output_dir, "stack-prof-report-wall-raw-stub.dump").to_s,
        mode: :wall,
        raw: true
      )

      described_class.profile("stub") { 0 == 1 }
    end
  end

  describe "#dump" do
    let(:stack_prof) { double("stack_prof") }

    before do
      stub_const("StackProf", stack_prof)
    end

    it "stops profiling and stores results" do
      expect(described_class).to receive(:dump_json_report)
      expect(stack_prof).to receive(:results).with(
        File.join(TestProf.config.output_dir, "stack-prof-report-wall-raw-stub.dump").to_s
      )
      expect(stack_prof).to receive(:stop)
      described_class.dump("stub")
    end
  end
end