Class: BeValidAsset::BeValidMarkup

Inherits:
BeValidBase show all
Defined in:
lib/be_valid_asset/be_valid_markup.rb

Direct Known Subclasses

BeValidXhtml

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ BeValidMarkup

Returns a new instance of BeValidMarkup.



16
17
18
# File 'lib/be_valid_asset/be_valid_markup.rb', line 16

def initialize(options = {})
  @fragment = options[:fragment]
end

Instance Method Details

#descriptionObject



46
47
48
# File 'lib/be_valid_asset/be_valid_markup.rb', line 46

def description
  "be valid markup"
end

#failure_messageObject



50
51
52
# File 'lib/be_valid_asset/be_valid_markup.rb', line 50

def failure_message
 " expected markup to be valid, but validation produced these errors:\n#{@message}"
end

#matches?(fragment) ⇒ Boolean

Assert that markup (html/xhtml) is valid according the W3C validator web service.

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/be_valid_asset/be_valid_markup.rb', line 22

def matches?(fragment)

  if fragment.respond_to? :source
    fragment = fragment.source.to_s
  elsif fragment.respond_to? :body
    fragment = fragment.body.to_s
  end

  fragment = apply_modifiers_to_fragment(fragment)

  if fragment.empty?
    @message = "Response was blank (maybe a missing integrate_views)"
    return false
  end

  query_params = { :fragment => fragment }
  if @fragment
    query_params[:prefill] = '1'
    query_params[:prefill_doctype] = 'xhtml10'
  end
  
  return validate(query_params)
end

#negative_failure_messageObject



54
55
56
# File 'lib/be_valid_asset/be_valid_markup.rb', line 54

def negative_failure_message
  " expected to not be valid, but was (missing validation?)"
end