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
|
require 'rspec/core/profiler'
RSpec.describe 'RSpec::Core::Profiler' do
let(:profiler) { RSpec::Core::Profiler.new }
it 'starts with an empty hash of example_groups' do
expect(profiler.example_groups).to be_empty.and be_a Hash
end
context 'when hooked into the reporter' do
include FormatterSupport
let(:description ) { "My Group" }
let(:now) { ::Time.utc(2015, 6, 2) }
before do
allow(::RSpec::Core::Time).to receive(:now) { now }
end
let(:group) { RSpec.describe "My Group" }
describe '#example_group_started' do
it 'records example groups start time and description' do
expect {
profiler.example_group_started group_notification group
}.to change { profiler.example_groups[group] }.
from(a_hash_excluding(:start, :description)).
to(a_hash_including(:start => now, :description => description))
end
context "when the group is not a top-level group" do
let(:group) { super().describe "nested" }
it 'no-ops since we only consider top-level groups for profiling' do
expect {
profiler.example_group_started group_notification group
}.not_to change(profiler, :example_groups)
end
end
end
describe '#example_group_finished' do
before do
profiler.example_group_started group_notification group
allow(::RSpec::Core::Time).to receive(:now) { now + 1 }
end
it 'records example groups total time and description' do
expect {
profiler.example_group_finished group_notification group
}.to change { profiler.example_groups[group] }.
from(a_hash_excluding(:total_time)).
to(a_hash_including(:total_time => 1.0))
end
context "when the group is not a top-level group" do
let(:group) { super().describe "nested" }
it 'no-ops since we only consider top-level groups for profiling' do
expect {
profiler.example_group_finished group_notification group
}.not_to change(profiler, :example_groups)
end
end
end
describe '#example_started' do
let(:example) { new_example }
before do
allow(example).to receive(:example_group) { group }
allow(group).to receive(:parent_groups) { [group] }
profiler.example_group_started group_notification group
end
it 'increments the count of examples for its parent group' do
expect {
profiler.example_started example_notification example
}.to change { profiler.example_groups[group][:count] }.by 1
end
end
end
end
|