Class: RspecW3cMatchers::Notices

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_w3c_matchers/notices.rb

Overview

Low level matcher that is used as a base for the high level matchers. You should not need to use this class directly. Look at the definitions in RspecW3cMatchers::InstanceMethods for a complete list of available matchers.

The arguments to Notice are as follows:

page: text containing the html that is being validated
comparator: comparison to be performed, can be :==,:<,:>,:<=,:>=. The number of errors 
          or warnings in the response is compared against the msg_count using this operator.
msg_count: expected number of notices
type: message type, either :errors or :warnings

To create a matcher that checks whether a response has more than 2 warnings you would use the declaration:

RspecW3cMatchers::Notices.new(page,:>,2,:warnings)

To create a matcher that checks to make sure a response has exactly 1 error you would use the declaration:

RspecW3cMatchers::Notices.new(page,:==,1,:errors)

Instance Method Summary collapse

Constructor Details

#initialize(page, comparator, msg_count, type) ⇒ Notices

Returns a new instance of Notices.



25
26
27
28
29
30
# File 'lib/rspec_w3c_matchers/notices.rb', line 25

def initialize(page,comparator,msg_count,type)
  @page = page
  @msg_count = msg_count
  self.comparator = comparator
  self.type = type
end

Instance Method Details

#descriptionObject

description that is returned when none is provided



53
54
55
# File 'lib/rspec_w3c_matchers/notices.rb', line 53

def description
  "should receive #{comparison}#{@msg_count} W3C validation #{type} in #{uri}"
end

#failure_message_for_shouldObject

The failure message used when should() is used and the matches?() method returns false.



39
40
41
42
43
# File 'lib/rspec_w3c_matchers/notices.rb', line 39

def failure_message_for_should          
  ["Expected #{comparison}#{@msg_count} W3C validation #{type} but received #{notices.length} #{type}",
    summary        
  ].join("\n")
end

#failure_message_for_should_notObject

The failure message used when should_not() is used and the matches?() method returns true.



46
47
48
49
50
# File 'lib/rspec_w3c_matchers/notices.rb', line 46

def failure_message_for_should_not      
  ["Did not expect #{comparison}#{@msg_count} W3C validation #{type} but received #{notices.length} #{type}",
    summary        
  ].join("\n")
end

#matches?(response) ⇒ Boolean

Used by the should() and should_not() methods to determine whether the expectation passes or fails.

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/rspec_w3c_matchers/notices.rb', line 33

def matches?(response)
  @response = response      
  notices.length.send(@comparator,@msg_count)
end