discourse/spec/lib/method_profiler_spec.rb
David Taylor c9dab6fd08
DEV: Automatically require 'rails_helper' in all specs (#16077)
It's very easy to forget to add `require 'rails_helper'` at the top of every core/plugin spec file, and omissions can cause some very confusing/sporadic errors.

By setting this flag in `.rspec`, we can remove the need for `require 'rails_helper'` entirely.
2022-03-01 17:50:50 +00:00

41 lines
827 B
Ruby

# frozen_string_literal: true
describe MethodProfiler do
class Sneetch
def beach
end
def recurse(count = 5)
if count > 0
recurse(count - 1)
end
end
end
it "can bypass recursion on demand" do
MethodProfiler.patch(Sneetch, [:recurse], :recurse, no_recurse: true)
MethodProfiler.start
Sneetch.new.recurse
result = MethodProfiler.stop
expect(result[:recurse][:calls]).to eq(1)
end
it "can transfer data between threads" do
MethodProfiler.patch(Sneetch, [:beach], :at_beach)
MethodProfiler.start
Sneetch.new.beach
data = MethodProfiler.transfer
result = nil
Thread.new do
MethodProfiler.start(data)
Sneetch.new.beach
result = MethodProfiler.stop
end.join
expect(result[:at_beach][:calls]).to eq(2)
end
end