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

- old
+ new

@@ -24,41 +24,24 @@ def tags @tags ||= {} end - def messages - @messages ||= {} - end - # **************************************************************************** # Helpers to provide results for all locales # **************************************************************************** - # Runs block in every available locale - def in_available_locales - locales = if respond_to?(:available_locales) - available_locales - else - I18n.available_locales - end - - locales.flat_map { |locale| I18n.with_locale(locale) { yield } } - end - 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 + I18n.locale = locale + local_policy = policy_block.call + self.policy = local_policy.inspect + errors[locale] = local_policy&.errors&.by_tags(tags) 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 @@ -83,12 +66,12 @@ texts.select { |text| text.start_with?("translation missing") }.empty? end def report_errors text = "Actual errors:\n" - messages.each do |locale, list| + errors.each do |locale, local_errors| text << " #{locale}:\n" - list.each { |item| text << " - #{item}\n" } + local_errors&.each { |error| text << " - #{error.full_message}\n" } end text end # ****************************************************************************