Module: Capybara::RSpecMatchers

Defined in:
lib/capybara/rspec/matchers.rb,
lib/capybara/rspec/matchers/base.rb,
lib/capybara/rspec/matchers/compound.rb,
lib/capybara/rspec/matchers/have_text.rb,
lib/capybara/rspec/matchers/have_style.rb,
lib/capybara/rspec/matchers/have_title.rb,
lib/capybara/rspec/matchers/become_closed.rb,
lib/capybara/rspec/matchers/have_selector.rb,
lib/capybara/rspec/matchers/match_selector.rb,
lib/capybara/rspec/matchers/have_current_path.rb

Defined Under Namespace

Modules: Matchers

Instance Method Summary collapse

Instance Method Details

#become_closed(**options) ⇒ Object

Wait for window to become closed.

Examples:

expect(window).to become_closed(wait: 0.8)

Parameters:

  • options (Hash)

    optional param

Options Hash (**options):

  • :wait (Numeric) — default: Capybara.default_max_wait_time

    Maximum wait time



152
153
154
# File 'lib/capybara/rspec/matchers.rb', line 152

def become_closed(**options)
  Matchers::BecomeClosed.new(options)
end

#have_all_of_selectors(*args, &optional_filter_block) ⇒ Object

RSpec matcher for whether the element(s) matching a group of selectors exist See Node::Matcher#assert_all_of_selectors



21
22
23
# File 'lib/capybara/rspec/matchers.rb', line 21

def have_all_of_selectors(*args, &optional_filter_block)
  Matchers::HaveAllSelectors.new(*args, &optional_filter_block)
end

#have_any_of_selectors(*args, &optional_filter_block) ⇒ Object

RSpec matcher for whether the element(s) matching any of a group of selectors exist See Node::Matcher#assert_any_of_selectors



33
34
35
# File 'lib/capybara/rspec/matchers.rb', line 33

def have_any_of_selectors(*args, &optional_filter_block)
  Matchers::HaveAnySelectors.new(*args, &optional_filter_block)
end

#have_button(locator = nil, **options, &optional_filter_block) ⇒ Object

RSpec matcher for buttons See Node::Matchers#has_button?



# File 'lib/capybara/rspec/matchers.rb', line 79

#have_checked_field(locator = nil, **options, &optional_filter_block) ⇒ Object

RSpec matcher for checked fields See Node::Matchers#has_checked_field?



# File 'lib/capybara/rspec/matchers.rb', line 101

#have_css(css, **options, &optional_filter_block) ⇒ Object

RSpec matcher for whether elements(s) matching a given css selector exist See Node::Matchers#has_css?



# File 'lib/capybara/rspec/matchers.rb', line 57

#have_current_path(path, **options) ⇒ Object

RSpec matcher for the current path See SessionMatchers#assert_current_path



122
123
124
# File 'lib/capybara/rspec/matchers.rb', line 122

def have_current_path(path, **options)
  Matchers::HaveCurrentPath.new(path, options)
end

#have_field(locator = nil, **options, &optional_filter_block) ⇒ Object

RSpec matcher for links See Node::Matchers#has_field?



# File 'lib/capybara/rspec/matchers.rb', line 83

RSpec matcher for links See Node::Matchers#has_link?



# File 'lib/capybara/rspec/matchers.rb', line 75

#have_none_of_selectors(*args, &optional_filter_block) ⇒ Object

RSpec matcher for whether no element(s) matching a group of selectors exist See Node::Matcher#assert_none_of_selectors



27
28
29
# File 'lib/capybara/rspec/matchers.rb', line 27

def have_none_of_selectors(*args, &optional_filter_block)
  Matchers::HaveNoSelectors.new(*args, &optional_filter_block)
end

#have_select(locator = nil, **options, &optional_filter_block) ⇒ Object

RSpec matcher for select elements See Node::Matchers#has_select?



# File 'lib/capybara/rspec/matchers.rb', line 87

#have_selector(*args, &optional_filter_block) ⇒ Object

RSpec matcher for whether the element(s) matching a given selector exist See Node::Matcher#assert_selector



15
16
17
# File 'lib/capybara/rspec/matchers.rb', line 15

def have_selector(*args, &optional_filter_block)
  Matchers::HaveSelector.new(*args, &optional_filter_block)
end

#have_style(styles, **options) ⇒ Object

RSpec matcher for element style See Node::Matchers#has_style?



128
129
130
# File 'lib/capybara/rspec/matchers.rb', line 128

def have_style(styles, **options)
  Matchers::HaveStyle.new(styles, options)
end

#have_table(locator = nil, **options, &optional_filter_block) ⇒ Object

RSpec matcher for table elements See Node::Matchers#has_table?



95
96
97
98
99
# File 'lib/capybara/rspec/matchers.rb', line 95

%i[checked unchecked].each do |state|
  define_method "have_#{state}_field" do |locator = nil, **options, &optional_filter_block|
    Matchers::HaveSelector.new(:field, locator, options.merge(state => true), &optional_filter_block)
  end
end

#have_text(*args) ⇒ Object Also known as: have_content

RSpec matcher for text content See SessionMatchers#assert_text



111
112
113
# File 'lib/capybara/rspec/matchers.rb', line 111

def have_text(*args)
  Matchers::HaveText.new(*args)
end

#have_title(title, **options) ⇒ Object



116
117
118
# File 'lib/capybara/rspec/matchers.rb', line 116

def have_title(title, **options)
  Matchers::HaveTitle.new(title, options)
end

#have_unchecked_field(locator = nil, **options, &optional_filter_block) ⇒ Object

RSpec matcher for unchecked fields See Node::Matchers#has_unchecked_field?



# File 'lib/capybara/rspec/matchers.rb', line 105

#have_xpath(xpath, **options, &optional_filter_block) ⇒ Object

RSpec matcher for whether elements(s) matching a given xpath selector exist See Node::Matchers#has_xpath?



# File 'lib/capybara/rspec/matchers.rb', line 53

#match_css(css, **options, &optional_filter_block) ⇒ Object

RSpec matcher for whether the current element matches a given css selector See Node::Matchers#matches_css?



69
70
71
72
73
# File 'lib/capybara/rspec/matchers.rb', line 69

%i[link button field select table].each do |selector|
  define_method "have_#{selector}" do |locator = nil, **options, &optional_filter_block|
    Matchers::HaveSelector.new(selector, locator, options, &optional_filter_block)
  end
end

#match_selector(*args, &optional_filter_block) ⇒ Object

RSpec matcher for whether the current element matches a given selector See Node::Matchers#assert_matches_selector



39
40
41
# File 'lib/capybara/rspec/matchers.rb', line 39

def match_selector(*args, &optional_filter_block)
  Matchers::MatchSelector.new(*args, &optional_filter_block)
end

#match_xpath(xpath, **options, &optional_filter_block) ⇒ Object

RSpec matcher for whether the current element matches a given xpath selector See Node::Matchers#matches_xpath?



# File 'lib/capybara/rspec/matchers.rb', line 61