spec/lib/appsignal/transaction_spec.rb in appsignal-2.0.6 vs spec/lib/appsignal/transaction_spec.rb in appsignal-2.1.0.alpha.1
- old
+ new
@@ -20,11 +20,11 @@
let(:transaction) { Appsignal::Transaction.new('1', namespace, request, options) }
before { Timecop.freeze(time) }
after { Timecop.return }
- describe "class methods" do
+ context "class methods" do
describe ".create" do
it "should add the transaction to thread local" do
Appsignal::Extension.should_receive(:start_transaction).with('1', 'http_request', 0)
created_transaction = Appsignal::Transaction.create('1', namespace, request, options)
@@ -464,33 +464,25 @@
end
end
describe "#start_event" do
it "should start the event in the extension" do
- expect(transaction.ext).to receive(:start_event).with(0).and_call_original
+ transaction.ext.should_receive(:start_event)
transaction.start_event
end
end
describe "#finish_event" do
- let(:fake_gc_time) { 123 }
- before do
- described_class.garbage_collection_profiler
- .should_receive(:total_time)
- .at_least(:once)
- .and_return(fake_gc_time)
- end
-
it "should finish the event in the extension" do
transaction.ext.should_receive(:finish_event).with(
'name',
'title',
'body',
1,
- fake_gc_time
- ).and_call_original
+ 0
+ )
transaction.finish_event(
'name',
'title',
'body',
@@ -502,40 +494,39 @@
transaction.ext.should_receive(:finish_event).with(
'name',
'',
'',
0,
- fake_gc_time
- ).and_call_original
+ 0
+ )
transaction.finish_event(
'name',
nil,
nil,
nil
)
end
- end
- describe "#record_event" do
- let(:fake_gc_time) { 123 }
- before do
- described_class.garbage_collection_profiler
- .should_receive(:total_time)
- .at_least(:once)
- .and_return(fake_gc_time)
+ it "should add garbage collection time" do
+ allow_any_instance_of(Appsignal::GarbageCollectionProfiler)
+ .to receive(:internal_profiler)
+ .and_return(FakeGCProfiler.new(0.12345))
+
+ transaction.finish_event('name', nil, nil, nil)
end
+ end
+ describe "#record_event" do
it "should record the event in the extension" do
transaction.ext.should_receive(:record_event).with(
'name',
'title',
'body',
1000,
- 1,
- fake_gc_time
- ).and_call_original
+ 1
+ )
transaction.record_event(
'name',
'title',
'body',
@@ -548,13 +539,12 @@
transaction.ext.should_receive(:record_event).with(
'name',
'',
'',
1000,
- 0,
- fake_gc_time
- ).and_call_original
+ 0
+ )
transaction.record_event(
'name',
nil,
nil,
@@ -607,22 +597,10 @@
# protected
describe "#background_queue_start" do
subject { transaction.send(:background_queue_start) }
- context "when request is nil" do
- let(:request) { nil }
-
- it { should eq nil }
- end
-
- context "when env is nil" do
- before { expect(transaction.request).to receive(:env).and_return(nil) }
-
- it { should eq nil }
- end
-
context "when queue start is nil" do
it { should eq nil }
end
context "when queue start is set" do
@@ -636,18 +614,12 @@
let(:slightly_earlier_time) { fixed_time - 0.4 }
let(:slightly_earlier_time_value) { (slightly_earlier_time * factor).to_i }
subject { transaction.send(:http_queue_start) }
shared_examples "http queue start" do
- context "when request is nil" do
- let(:request) { nil }
-
- it { should be_nil }
- end
-
context "when env is nil" do
- before { expect(transaction.request).to receive(:env).and_return(nil) }
+ before { transaction.request.stub(:env => nil) }
it { should be_nil }
end
context "with no relevant header set" do
@@ -777,20 +749,12 @@
describe "#sanitized_environment" do
let(:whitelisted_keys) { Appsignal::Transaction::ENV_METHODS }
subject { transaction.send(:sanitized_environment) }
- context "when request is nil" do
- let(:request) { nil }
-
- it "returns nil" do
- expect(subject).to be_nil
- end
- end
-
context "when env is nil" do
- before { expect(transaction.request).to receive(:env).and_return(nil) }
+ before { transaction.request.stub(:env => nil) }
it { should be_nil }
end
context "when env is present" do
@@ -807,26 +771,18 @@
end
describe '#sanitized_session_data' do
subject { transaction.send(:sanitized_session_data) }
- context "when request is nil" do
- let(:request) { nil }
+ context "when env is nil" do
+ before { transaction.request.stub(:session => nil) }
- it "returns nil" do
- expect(subject).to be_nil
- end
- end
-
- context "when session is nil" do
- before { expect(transaction.request).to receive(:session).and_return(nil) }
-
it { should be_nil }
end
- context "when session is empty" do
- before { expect(transaction.request).to receive(:session).and_return({}) }
+ context "when env is empty" do
+ before { transaction.request.stub(:session => {}) }
it { should eq({}) }
end
context "when request class does not have a session method" do
@@ -886,17 +842,11 @@
end
describe "#metadata" do
subject { transaction.send(:metadata) }
- context "when request is nil" do
- let(:request) { nil }
-
- it { should be_nil }
- end
-
context "when env is nil" do
- before { expect(transaction.request).to receive(:env).and_return(nil) }
+ before { transaction.request.stub(:env => nil) }
it { should be_nil }
end
context "when env is present" do