Module: Capybara::RSpecMatchers

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

Defined Under Namespace

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

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



414
415
416
# File 'lib/capybara/rspec/matchers.rb', line 414

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



284
285
286
# File 'lib/capybara/rspec/matchers.rb', line 284

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



296
297
298
# File 'lib/capybara/rspec/matchers.rb', line 296

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

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

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

#have_current_path(path, **options) ⇒ Object

RSpec matcher for the current path See SessionMatchers#assert_current_path



385
386
387
# File 'lib/capybara/rspec/matchers.rb', line 385

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 346

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



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

#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



290
291
292
# File 'lib/capybara/rspec/matchers.rb', line 290

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 350

#have_selector(*args, &optional_filter_block) ⇒ Object

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



278
279
280
# File 'lib/capybara/rspec/matchers.rb', line 278

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?



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

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?



358
359
360
361
362
# File 'lib/capybara/rspec/matchers.rb', line 358

%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



374
375
376
# File 'lib/capybara/rspec/matchers.rb', line 374

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

#have_title(title, **options) ⇒ Object



379
380
381
# File 'lib/capybara/rspec/matchers.rb', line 379

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 368

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

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



332
333
334
335
336
# File 'lib/capybara/rspec/matchers.rb', line 332

%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



302
303
304
# File 'lib/capybara/rspec/matchers.rb', line 302

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 324