application_handle_info_spec.rb 1008 B

12345678910111213141516171819202122232425262728293031323334
  1. require 'rails_helper'
  2. RSpec.describe ApplicationHandleInfo do
  3. describe '.use' do
  4. it 'requires a block' do
  5. expect { described_class.use('foo') }
  6. .to raise_error(ArgumentError)
  7. end
  8. context 'for a given starting ApplicationHandleInfo' do
  9. before { described_class.current = 'foo' }
  10. it 'runs the block using the given ApplicationHandleInfo' do
  11. described_class.use('bar') do
  12. expect(described_class.current).to eq('bar')
  13. end
  14. end
  15. it 'resets ApplicationHandleInfo to its original value' do
  16. described_class.use('bar') {}
  17. expect(described_class.current).to eq('foo')
  18. end
  19. context 'when an error is raised in the given block' do
  20. it 'does not rescue the error, and still resets ApplicationHandleInfo' do
  21. expect { described_class.use('bar') { raise } }
  22. .to raise_error(StandardError)
  23. .and not_change { described_class.current }
  24. end
  25. end
  26. end
  27. end
  28. end