module RSpecHTML::Matchers::Base

Mix-in class to provide a uniform interface and message templating for all matchers.

Attributes

rspec_actual[R]

Public Class Methods

diffable() click to toggle source
# File lib/rspec_html/matchers/base.rb, line 10
def diffable
  @diffable = true
end
diffable?() click to toggle source
# File lib/rspec_html/matchers/base.rb, line 14
def diffable?
  @diffable
end
included(base) click to toggle source
# File lib/rspec_html/matchers/base.rb, line 7
def self.included(base)
  base.class_eval do
    class << self
      def diffable
        @diffable = true
      end

      def diffable?
        @diffable
      end
    end
  end
end
new(expected, options) click to toggle source
# File lib/rspec_html/matchers/base.rb, line 23
def initialize(expected, options)
  @expected = expected
  @options = options
end

Public Instance Methods

description() click to toggle source
# File lib/rspec_html/matchers/base.rb, line 28
def description
  template(:description, @options, @expected)
end
failure_message() click to toggle source
# File lib/rspec_html/matchers/base.rb, line 32
def failure_message
  template(:failure, @options, @expected, @actual)
end
reconstituted(element, options) click to toggle source
# File lib/rspec_html/matchers/base.rb, line 41
def reconstituted(element, options)
  RSpecHTML::Element.reconstituted(element, options)
end
save_actual(actual) click to toggle source
# File lib/rspec_html/matchers/base.rb, line 36
def save_actual(actual)
  @actual = actual
  self
end

Private Instance Methods

filename() click to toggle source
# File lib/rspec_html/matchers/base.rb, line 55
def filename
  _, _, name = self.class.name.rpartition('::')
  (name[0] + name[1..-1].gsub(/(.)([A-Z])/, '\1_\2')).downcase
end
template(type, options, expected, actual = nil) click to toggle source
# File lib/rspec_html/matchers/base.rb, line 47
def template(type, options, expected, actual = nil)
  ERB.new(template_path(type).read).result(binding)
end
template_path(type) click to toggle source
# File lib/rspec_html/matchers/base.rb, line 51
def template_path(type)
  RSpecHTML.root.join('templates', type.to_s, "#{filename}.erb")
end