Class: Merimee::Rspec::ViewCheckerHelper::HaveACorrectSpellingMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/merimee/rspec/view_checker_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize {|@config| ... } ⇒ HaveACorrectSpellingMatcher

Returns a new instance of HaveACorrectSpellingMatcher.

Yields:

  • (@config)

5
6
7
8
# File 'lib/merimee/rspec/view_checker_helper.rb', line 5

def initialize
  @config = ::RSpec.configuration.merimee_config
  yield @config if block_given?
end

Instance Method Details

#failure_message_for_shouldObject


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/merimee/rspec/view_checker_helper.rb', line 21

def failure_message_for_should
  errs = []
  @errors.sort_by(&:severity).each do |err|
    message = "[#{err.severity} : #{err.type} - #{err.description}] #{err.string}"
    unless err.suggestions.empty?
      message << " (suggested: #{err.suggestions.join(', ')})"
    end
    errs << message
  end
  errs.join("\n")
end

#matches?(rendered) ⇒ Boolean

Returns:

  • (Boolean)

10
11
12
13
14
15
16
17
18
19
# File 'lib/merimee/rspec/view_checker_helper.rb', line 10

def matches?(rendered)
  checker = Merimee::Checker.new(@config)

  if rendered
    @errors = checker.check(rendered)
    @errors.none? {|e| e.severity == :error}
  else
    true
  end
end