Module: Dommy::RSpec::Matchers

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

Overview

Custom RSpec matchers for asserting against Dommy DOM objects.

Examples:

RSpec config

require "dommy/rspec"
RSpec.configure do |c|
  c.include Dommy::RSpec::Matchers
end

Usage

expect(root).to contain_dom("button.primary")
expect(root).to contain_dom("li", count: 3)
expect(root).to contain_dom("h1", text: "Welcome")
expect(root).to contain_dom_text("Submit")
expect(button).to have_dom_attribute("type", "button")
expect(button).to have_dom_class("primary")
expect(root).to match_dom_html("<h1>Hello</h1>")

Defined Under Namespace

Classes: ContainDom, ContainDomText, HaveDomAttribute, HaveDomClass, MatchDomHtml

Instance Method Summary collapse

Instance Method Details

#contain_dom(selector, text: nil, count: nil) ⇒ Object



25
26
27
# File 'lib/dommy/rspec/matchers.rb', line 25

def contain_dom(selector, text: nil, count: nil)
  ContainDom.new(selector, text: text, count: count)
end

#contain_dom_text(text) ⇒ Object



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

def contain_dom_text(text)
  ContainDomText.new(text)
end

#have_dom_attribute(name, value = UNSET) ⇒ Object



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

def have_dom_attribute(name, value = UNSET)
  HaveDomAttribute.new(name, value)
end

#have_dom_class(class_name) ⇒ Object



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

def have_dom_class(class_name)
  HaveDomClass.new(class_name)
end

#match_dom_html(expected_html) ⇒ Object



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

def match_dom_html(expected_html)
  MatchDomHtml.new(expected_html)
end