-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test to confirm crash when available locales are enforced but fal…
…lback locale unavailable
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'spec_helper' | ||
|
||
describe Grape::Exceptions::Base do | ||
describe '#compose_message' do | ||
subject { described_class.new.send(:compose_message, key, attributes) } | ||
|
||
let(:key) { :invalid_formatter } | ||
let(:attributes) { { klass: String, to_format: 'xml' } } | ||
|
||
context 'when I18n enforces available locales' do | ||
before { I18n.enforce_available_locales = true } | ||
after { I18n.enforce_available_locales = false } | ||
|
||
context 'when the fallback locale is available' do | ||
before { I18n.available_locales = %i[de en] } | ||
|
||
it 'returns the translated message' do | ||
expect(subject).to eq('cannot convert String to xml') | ||
end | ||
end | ||
|
||
context 'when the fallback locale is not available' do | ||
before { I18n.available_locales = %i[de jp] } | ||
|
||
it 'currently raises an error' do | ||
expect { subject }.to raise_error(I18n::InvalidLocale) | ||
end | ||
end | ||
end | ||
end | ||
end |