Module: Dommy::RSpec::CapyStyleMatchers

Defined in:
lib/dommy/rspec/capy_style_matchers.rb

Overview

Capybara-style RSpec matchers backed by Dommy.

These mirror Capybara’s matcher names (‘have_selector`, `have_content`, `have_link`, etc.) so existing Capybara test suites can be migrated to a pure-Ruby DOM stack with minimal code changes.

Because the names collide with Capybara::RSpecMatchers, this module should be included into specs that DO NOT also include Capybara —typically view / component / request specs, with feature specs left to Capybara. See the README for a ‘type:` split example.

Examples:

require "dommy/rspec/capy_style_matchers"

RSpec.configure do |c|
  c.include Dommy::TestHelpers,                type: :view
  c.include Dommy::RSpec::CapyStyleMatchers,   type: :view
end

expect(dom).to have_selector("button.primary")
expect(dom).to have_content("Welcome")
expect(dom).to have_link("Sign up", href: "/signup")

Defined Under Namespace

Modules: Negated Classes: Base, HaveButton, HaveContent, HaveField, HaveLink, HaveNoButton, HaveNoContent, HaveNoField, HaveNoLink, HaveNoSelector, HaveSelector

Instance Method Summary collapse

Instance Method Details

#have_button(text = nil, **opts) ⇒ Object



63
64
65
# File 'lib/dommy/rspec/capy_style_matchers.rb', line 63

def have_button(text = nil, **opts)
  HaveButton.new(text, **opts)
end

#have_content(text, **opts) ⇒ Object Also known as: have_text



43
44
45
# File 'lib/dommy/rspec/capy_style_matchers.rb', line 43

def have_content(text, **opts)
  HaveContent.new(text, **opts)
end

#have_field(name_or_label = nil, **opts) ⇒ Object



71
72
73
# File 'lib/dommy/rspec/capy_style_matchers.rb', line 71

def have_field(name_or_label = nil, **opts)
  HaveField.new(name_or_label, **opts)
end


55
56
57
# File 'lib/dommy/rspec/capy_style_matchers.rb', line 55

def have_link(text = nil, **opts)
  HaveLink.new(text, **opts)
end

#have_no_button(text = nil, **opts) ⇒ Object



67
68
69
# File 'lib/dommy/rspec/capy_style_matchers.rb', line 67

def have_no_button(text = nil, **opts)
  HaveNoButton.new(text, **opts)
end

#have_no_content(text, **opts) ⇒ Object Also known as: have_no_text



49
50
51
# File 'lib/dommy/rspec/capy_style_matchers.rb', line 49

def have_no_content(text, **opts)
  HaveNoContent.new(text, **opts)
end

#have_no_field(name_or_label = nil, **opts) ⇒ Object



75
76
77
# File 'lib/dommy/rspec/capy_style_matchers.rb', line 75

def have_no_field(name_or_label = nil, **opts)
  HaveNoField.new(name_or_label, **opts)
end


59
60
61
# File 'lib/dommy/rspec/capy_style_matchers.rb', line 59

def have_no_link(text = nil, **opts)
  HaveNoLink.new(text, **opts)
end

#have_no_selector(selector, **opts) ⇒ Object Also known as: have_no_css



37
38
39
# File 'lib/dommy/rspec/capy_style_matchers.rb', line 37

def have_no_selector(selector, **opts)
  HaveNoSelector.new(selector, **opts)
end

#have_selector(selector, **opts) ⇒ Object Also known as: have_css



31
32
33
# File 'lib/dommy/rspec/capy_style_matchers.rb', line 31

def have_selector(selector, **opts)
  HaveSelector.new(selector, **opts)
end