lib/tram/policy/rspec.rb in tram-policy-0.2.2 vs lib/tram/policy/rspec.rb in tram-policy-0.2.3

- old
+ new

@@ -43,19 +43,28 @@ end locales.flat_map { |locale| I18n.with_locale(locale) { yield } } end - # Collects results for the current locale - def prepare_results(policy_block, tags, locale = I18n.locale) + def prepare_localized_results(policy_block, tags, locale) localized_policy = policy_block.call localized_errors = localized_policy&.errors || [] self.policy = localized_policy.inspect errors[locale] = localized_errors.by_tags(tags) messages[locale] = localized_errors.full_messages end + def prepare_results(policy_block, tags) + original = I18n.locale + I18n.available_locales.each do |locale| + I18n.locale = locale + prepare_localized_results(policy_block, tags, locale) + end + ensure + I18n.locale = original + end + # **************************************************************************** # Checkers for collected results # **************************************************************************** # Checks if selected errors are present in all available locales @@ -86,11 +95,11 @@ # **************************************************************************** # Positive matcher # **************************************************************************** match do |policy_block| - in_available_locales { prepare_results(policy_block, tags) } + prepare_results(policy_block, tags) errored? && translated? end failure_message do |_| text = "The policy: #{policy}\n" @@ -103,10 +112,10 @@ # **************************************************************************** # Negative matcher # **************************************************************************** match_when_negated do |policy_block| - in_available_locales { prepare_results(policy_block, tags) } + prepare_results(policy_block, tags) not_errored? end failure_message_when_negated do |_| text = "#{policy}\nshould not have had any error with tags: #{tags}.\n"