betterp

0.1.9
Light Mode Dark Mode

Usage

Typical usage of Betterp is identical to usage of Kernel.p and Kernel.pp, simply require betterp somewhere in your project and call #p or #pp as normal.

subject { p 'hi' }

it { is_expected.to include 'hi' }
#### rspec-documentation/pages/010-Usage.md:10 => [#block (3 levels) in example_group] subject { p 'hi' } => "hi"
subject { pp({ foo: 'bar', baz: 'qux' }) }

it { is_expected.to include 'qux' }
#### rspec-documentation/pages/010-Usage.md:16 => [#block (3 levels) in example_group] subject { pp({ foo: 'bar', baz: 'qux' }) } =>
  {:foo=>"bar", :baz=>"qux"}

Profiling

Both #p and #pp can receive a block. If a block is received, the block will be timed and the execution time will be included in the output. The result of the block is returned to the caller.

subject do
  p { sleep(0.1); 'some return value' }
end

it { is_expected.to match /\dms/ }
#### rspec-documentation/pages/010-Usage.md:27 => [#block (3 levels) in example_group] [100.0ms] p { sleep(0.1); 'some return value' } => "some return value"

The execution time is highlighted in green, yellow, or red depending on execution time.

The default thresholds are:

  • low: < 10ms.
  • high: > 100ms.

The thresholds can be modified:

Betterp.configure do |config|
  config.profiling_threshold.low = 100
  config.profiling_threshold.high = 1000
end

Documentation generated by rspec-documentation