Skip to content

Instantly share code, notes, and snippets.

@sj26
Created March 14, 2012 03:42
Show Gist options
  • Save sj26/2033862 to your computer and use it in GitHub Desktop.
Save sj26/2033862 to your computer and use it in GitHub Desktop.
Temporarily swap in I18n translations for a context
module RSpecWithTranslations
def with_translations *args, &block
translations = args.extract_options!
args = args.presence || ["with translations"]
context *args do
around do |example|
begin
old, I18n.backend = I18n.backend, I18n::Backend::KeyValue.new(translations)
example.call
ensure
I18n.backend = old
end
end
instance_eval &block
end
end
end
RSpec::configure do |config|
config.extend RSpecWithTranslations
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment