Module: RSpec::TagMatchers

Defined in:
lib/rspec/tag_matchers.rb,
lib/rspec/tag_matchers/has_tag.rb,
lib/rspec/tag_matchers/has_form.rb,
lib/rspec/tag_matchers/has_input.rb,
lib/rspec/tag_matchers/has_select.rb,
lib/rspec/tag_matchers/has_checkbox.rb,
lib/rspec/tag_matchers/has_date_select.rb,
lib/rspec/tag_matchers/has_time_select.rb,
lib/rspec/tag_matchers/multiple_input_matcher.rb

Defined Under Namespace

Modules: Helpers Classes: HasCheckbox, HasDateSelect, HasForm, HasInput, HasSelect, HasTag, HasTimeSelect, MultipleInputMatcher

Instance Method Summary collapse

Instance Method Details

#have_checkboxHasCheckbox

Matches <input type="checkbox"> tags in HTML.

Examples:

Matching a checked checkbox for terms_of_service

it { should have_checkbox.for(:terms_of_service).checked }

Matching an unchecked checkbox for terms_of_service

it { should have_checkbox.for(:terms_of_service).not_checked }

See Also:

  • HasCheckbox.checked
  • HasCheckbox.not_checked


20
21
22
# File 'lib/rspec/tag_matchers/has_checkbox.rb', line 20

def have_checkbox
  HasCheckbox.new
end

#have_date_selectHasDateSelect

Matches inputs generated by Rails' date_select helper.

Examples:

Matching a date select for an event's start_date

it { should have_date_select.for(:event => :start_date) }

Matching a date select for a credit card expiration

it { should have_date_select.discard(:day).for(:credit_card => :expiration) }

See Also:



21
22
23
# File 'lib/rspec/tag_matchers/has_date_select.rb', line 21

def have_date_select
  HasDateSelect.new
end

#have_formHasForm

Matches <form> tags in HTML.

Examples:

Matching a simple form

it { should have_form.with_verb(:post).with_action("/signup") }

Matching a form with an overridden method

it { should have_form.with_verb(:put) }

See Also:



20
21
22
# File 'lib/rspec/tag_matchers/has_form.rb', line 20

def have_form
  HasForm.new
end

#have_inputHasInput

Matches <input> tags in HTML.

Examples:

Matching an input for the name attribute on user

it { should have_input.for(:user => :name) }
it { should have_input.for(:user, :name) }

Matching an input with a value of "42".

it { should have_input.value("42") }

See Also:



22
23
24
# File 'lib/rspec/tag_matchers/has_input.rb', line 22

def have_input
  HasInput.new
end

#have_selectHasSelect

Matches <select> tags in HTML.

Examples:

Matching a select tag for a user's role

it { should have_select.for(:user => :role) }


8
9
10
# File 'lib/rspec/tag_matchers/has_select.rb', line 8

def have_select
  HasSelect.new
end

#have_tag(name) ⇒ HasTag

Matches HTML tags by name.

Examples:

Matching anchor tags

it { should have_tag(:a) }

Matching contents of a tag

it { should have_tag(:a).with_content("my site") }

Matching anchor tags that link to "/"

it { should have_tag(:a).with_attribute(:href => "/") }

Matching anchor tags with an even id attribute

it { should have_tag(:a).with_criteria { |elem| elem[:id].to_i.even? } }

See Also:



34
35
36
# File 'lib/rspec/tag_matchers/has_tag.rb', line 34

def have_tag(name)
  HasTag.new(name)
end

#have_time_selectHasTimeSelect

Matches inputs generated by Rails' time_select helper.

Examples:

Matching a time select for an event's start_time

it { should have_time_select.for(:event => :start_time) }


10
11
12
# File 'lib/rspec/tag_matchers/has_time_select.rb', line 10

def have_time_select
  HasTimeSelect.new
end