2019-04-10 17:14:34 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe ApplicationHandleInfo do
|
|
|
|
describe '.use' do
|
|
|
|
it 'requires a block' do
|
2019-04-15 01:41:17 +00:00
|
|
|
expect { described_class.use('foo') }
|
2019-04-10 17:14:34 +00:00
|
|
|
.to raise_error(ArgumentError)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for a given starting ApplicationHandleInfo' do
|
2019-04-15 01:41:17 +00:00
|
|
|
before { described_class.current = 'foo' }
|
2019-04-10 17:14:34 +00:00
|
|
|
|
|
|
|
it 'runs the block using the given ApplicationHandleInfo' do
|
2019-04-15 01:41:17 +00:00
|
|
|
described_class.use('bar') do
|
|
|
|
expect(described_class.current).to eq('bar')
|
2019-04-10 17:14:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'resets ApplicationHandleInfo to its original value' do
|
2019-04-15 01:41:17 +00:00
|
|
|
described_class.use('bar') {}
|
2019-04-10 17:14:34 +00:00
|
|
|
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(described_class.current).to eq('foo')
|
2019-04-10 17:14:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when an error is raised in the given block' do
|
|
|
|
it 'does not rescue the error, and still resets ApplicationHandleInfo' do
|
2019-04-15 01:41:17 +00:00
|
|
|
expect { described_class.use('bar') { raise } }
|
2019-04-10 17:14:34 +00:00
|
|
|
.to raise_error(StandardError)
|
2019-04-15 01:41:17 +00:00
|
|
|
.and not_change { described_class.current }
|
2019-04-10 17:14:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|