Created
March 14, 2012 03:42
-
-
Save sj26/2033862 to your computer and use it in GitHub Desktop.
Temporarily swap in I18n translations for a context
This file contains hidden or 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
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