Class: RSpec::TagMatchers::HasCheckbox

Inherits:
HasInput show all
Defined in:
lib/rspec/tag_matchers/has_checkbox.rb

Overview

A matcher that matches <input type="checkbox"> tags.

Instance Method Summary collapse

Methods inherited from HasInput

#for, #value

Methods inherited from HasTag

#description, #failure_message, #matches?, #negative_failure_message, #test_attribute, #with_attribute, #with_content, #with_count, #with_criteria

Methods included from RSpec::TagMatchers::Helpers::SentenceHelper

#make_sentence

Constructor Details

#initializeHasCheckbox

Initializes a HasCheckbox matcher that matches elements named input with a type attribute of checkbox.



29
30
31
32
# File 'lib/rspec/tag_matchers/has_checkbox.rb', line 29

def initialize
  super
  with_attribute(:type => :checkbox)
end

Instance Method Details

#checkedHasCheckbox

Specifies that the checkbox must be selected. A checkbox is considered to be checked if it has a checked attribute.

Examples:

Checkboxes which are considered checked

<input type="checkbox" checked="checked" />
<input type="checkbox" checked="1" />
<input type="checkbox" checked />

Returns:



43
44
45
46
# File 'lib/rspec/tag_matchers/has_checkbox.rb', line 43

def checked
  with_attribute(:checked => true)
  self
end

#not_checkedHasCheckbox

Specifies that the checkbox must not be selected. A checkbox is not checked if it has no checked attribute.

Examples:

An unchecked checkbox

<input type="checkbox" />

Returns:



55
56
57
58
# File 'lib/rspec/tag_matchers/has_checkbox.rb', line 55

def not_checked
  with_attribute(:checked => false)
  self
end