lib/tram/policy/rspec.rb in tram-policy-0.3.1 vs lib/tram/policy/rspec.rb in tram-policy-0.4.0

- old
+ new

@@ -32,11 +32,13 @@ def prepare_localized_results(policy_block, tags, locale) I18n.locale = locale local_policy = policy_block.call self.policy = local_policy.inspect - errors[locale] = local_policy&.errors&.by_tags(tags) + errors[locale] = local_policy&.errors&.filter(tags)&.map do |error| + { message: error.message, tags: error.options } # translate immediately + end end def prepare_results(policy_block, tags) original = I18n.locale I18n.available_locales.each do |locale| @@ -60,18 +62,18 @@ errors.values.map(&:empty?).reduce(true, &:&) == true end # Checks if all collected errors are translated def translated? - texts = errors.values.flatten.map(&:message) + texts = errors.values.flatten.map { |err| err[:message] } texts.select { |text| text.start_with?("translation missing") }.empty? end def report_errors text = "Actual errors:\n" errors.each do |locale, local_errors| text << " #{locale}:\n" - local_errors&.each { |error| text << " - #{error.full_message}\n" } + local_errors&.each { |err| text << " - #{err.values.join(" ")}\n" } end text end # ****************************************************************************