Module: Capybara::RSpecMatchers

Defined in:
lib/capybara/rspec/compound.rb,
lib/capybara/rspec/matchers.rb

Defined Under Namespace

Modules: Compound Classes: BecomeClosed, HaveAllSelectors, HaveCurrentPath, HaveNoSelectors, HaveSelector, HaveStyle, HaveText, HaveTitle, MatchSelector, Matcher, NegatedMatcher

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)

Options Hash (**options):

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

    Maximum wait time



392
393
394
# File 'lib/capybara/rspec/matchers.rb', line 392

def become_closed(**options)
  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



268
269
270
# File 'lib/capybara/rspec/matchers.rb', line 268

def have_all_of_selectors(*args, &optional_filter_block)
  HaveAllSelectors.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 320

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

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

#have_current_path(path, **options) ⇒ Object

RSpec matcher for the current path See SessionMatchers#assert_current_path



363
364
365
# File 'lib/capybara/rspec/matchers.rb', line 363

def have_current_path(path, **options)
  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 324

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



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

#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



274
275
276
# File 'lib/capybara/rspec/matchers.rb', line 274

def have_none_of_selectors(*args, &optional_filter_block)
  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 328

#have_selector(*args, &optional_filter_block) ⇒ Object

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



262
263
264
# File 'lib/capybara/rspec/matchers.rb', line 262

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

#have_style(styles, **options) ⇒ Object

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



369
370
371
# File 'lib/capybara/rspec/matchers.rb', line 369

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

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

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



336
337
338
339
340
# File 'lib/capybara/rspec/matchers.rb', line 336

%i[checked unchecked].each do |state|
  define_method "have_#{state}_field" do |locator = nil, **options, &optional_filter_block|
    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



352
353
354
# File 'lib/capybara/rspec/matchers.rb', line 352

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

#have_title(title, **options) ⇒ Object



357
358
359
# File 'lib/capybara/rspec/matchers.rb', line 357

def have_title(title, **options)
  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 346

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

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



310
311
312
313
314
# File 'lib/capybara/rspec/matchers.rb', line 310

%i[link button field select table].each do |selector|
  define_method "have_#{selector}" do |locator = nil, **options, &optional_filter_block|
    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



280
281
282
# File 'lib/capybara/rspec/matchers.rb', line 280

def match_selector(*args, &optional_filter_block)
  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 302