Class: Ndd::RSpec::Rails::Matchers::Controller::HaveATranslatedFlash

Inherits:
TranslationMatcher show all
Defined in:
lib/ndd/rspec/rails/matchers/controller/have_a_translated_flash.rb

Overview

Instance Method Summary collapse

Methods inherited from TranslationMatcher

#in_available_locales, #in_default_locale

Constructor Details

#initialize(message) ⇒ HaveATranslatedFlash


13
14
15
16
# File 'lib/ndd/rspec/rails/matchers/controller/have_a_translated_flash.rb', line 13

def initialize(message)
  super()
  @message = message
end

Instance Method Details

#descriptionString


38
39
40
41
42
43
# File 'lib/ndd/rspec/rails/matchers/controller/have_a_translated_flash.rb', line 38

def description
  description = "have a translated flash message for '#{@message}'"
  description << " on '#{@action}'" if @action.present?
  description << " in #{locales_as_string(@tested_locales)}"
  description
end

#failure_messageString


46
47
48
49
50
51
52
# File 'lib/ndd/rspec/rails/matchers/controller/have_a_translated_flash.rb', line 46

def failure_message
  message = "expected '#{subject_as_string}' to have a translated flash message for '#{@message}'\n"
  message << "but none of the following keys was found:\n"
  message << "#{translation_keys.map { |l| "  - #{l}" }.join("\n")}\n"
  message << "for the locales: #{locales_as_string(@failed_locales)}"
  message
end

#matches?(controller) ⇒ Boolean


28
29
30
31
32
33
34
35
# File 'lib/ndd/rspec/rails/matchers/controller/have_a_translated_flash.rb', line 28

def matches?(controller)
  @controller = controller
  @failed_locales = []
  @tested_locales.each do |tested_locale|
    @failed_locales << tested_locale unless translated_in?(tested_locale)
  end
  @failed_locales.empty?
end

#on_action(action) ⇒ Object

Set the action of the message to test.


21
22
23
24
# File 'lib/ndd/rspec/rails/matchers/controller/have_a_translated_flash.rb', line 21

def on_action(action)
  @action = action
  self
end