spec/lib/request_tracer/trace_spec.rb in request-tracer-0.6.2 vs spec/lib/request_tracer/trace_spec.rb in request-tracer-0.6.3

- old
+ new

@@ -49,13 +49,21 @@ end context '#push(trace_hash)', generative: true, order: :generative do def push(&blk) described_class.push(previous_trace_hash, &blk) end + shared_examples "returning the block value" do + let(:block_value) { rand(1000) } + it 'returns the value from the block' do + returned = push {|t| block_value } + expect(returned).to eq(block_value) + end + end context 'when trace_hash contains a previous trace' do let(:previous_trace) { described_class.create} let(:previous_trace_hash) { previous_trace.to_h } + it_behaves_like "returning the block value" it 'keeps the span_id' do push do |t| expect(t.span_id).to eq(previous_trace.span_id) end end @@ -70,10 +78,11 @@ end end end context 'when no previous trace exists' do let(:previous_trace_hash) { {} } + it_behaves_like "returning the block value" it 'creates a new span_id' do push do |t| expect(t.span_id.i64.to_s).to match /[0-9a-z]+/i end end @@ -85,8 +94,12 @@ it 'does not set a parent_span_id' do push do |t| expect(t.parent_id).to eq(nil) end end + end + context 'when called with nil' do + let(:previous_trace_hash) { nil } + it_behaves_like "returning the block value" end end end