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_title.rb,
lib/capybara/rspec/matchers/count_sugar.rb,
lib/capybara/rspec/matchers/match_style.rb,
lib/capybara/rspec/matchers/match_style.rb,
lib/capybara/rspec/matchers/have_sibling.rb,
lib/capybara/rspec/matchers/become_closed.rb,
lib/capybara/rspec/matchers/have_ancestor.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: CountSugar, 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



175
176
177
# File 'lib/capybara/rspec/matchers.rb', line 175

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



23
24
25
# File 'lib/capybara/rspec/matchers.rb', line 23

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

#have_ancestor(*args, &optional_filter_block) ⇒ Object

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



165
166
167
# File 'lib/capybara/rspec/matchers.rb', line 165

def have_ancestor(*args, &optional_filter_block)
  Matchers::HaveAncestor.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



35
36
37
# File 'lib/capybara/rspec/matchers.rb', line 35

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 81

#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 103

#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 59

#have_current_path(path, **options) ⇒ Object

RSpec matcher for the current path See SessionMatchers#assert_current_path



124
125
126
# File 'lib/capybara/rspec/matchers.rb', line 124

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 85

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



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

#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



29
30
31
# File 'lib/capybara/rspec/matchers.rb', line 29

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 89

#have_selector(*args, &optional_filter_block) ⇒ Object

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



17
18
19
# File 'lib/capybara/rspec/matchers.rb', line 17

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

#have_sibling(*args, &optional_filter_block) ⇒ Object

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



159
160
161
# File 'lib/capybara/rspec/matchers.rb', line 159

def have_sibling(*args, &optional_filter_block)
  Matchers::HaveSibling.new(*args, &optional_filter_block)
end

#have_style(styles, **options) ⇒ Object

Deprecated.


137
138
139
140
# File 'lib/capybara/rspec/matchers.rb', line 137

def have_style(styles, **options)
  warn 'DEPRECATED: have_style is deprecated, please use match_style'
  match_style(styles, **options)
end

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

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



97
98
99
100
101
# File 'lib/capybara/rspec/matchers.rb', line 97

%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 Node::Matchers#assert_text



113
114
115
# File 'lib/capybara/rspec/matchers.rb', line 113

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

#have_title(title, **options) ⇒ Object



118
119
120
# File 'lib/capybara/rspec/matchers.rb', line 118

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 107

#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 55

#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?



71
72
73
74
75
# File 'lib/capybara/rspec/matchers.rb', line 71

%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



41
42
43
# File 'lib/capybara/rspec/matchers.rb', line 41

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

#match_style(styles, **options) ⇒ Object

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



130
131
132
# File 'lib/capybara/rspec/matchers.rb', line 130

def match_style(styles, **options)
  Matchers::MatchStyle.new(styles, options)
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 63