Class: RSpecHTML::Element

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/rspec_html/element.rb

Overview

HTML DOM element abstraction

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element, name, options: {}, siblings: []) ⇒ Element

Returns a new instance of Element.



17
18
19
20
21
22
23
# File 'lib/rspec_html/element.rb', line 17

def initialize(element, name, options: {}, siblings: [])
  @name = name
  @element = element
  @options = options
  @siblings = siblings || []
  @search = Search.new(@element, @siblings, self)
end

Instance Attribute Details

#elementObject (readonly)

Returns the value of attribute element.



6
7
8
# File 'lib/rspec_html/element.rb', line 6

def element
  @element
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/rspec_html/element.rb', line 6

def name
  @name
end

#searchObject (readonly)

Returns the value of attribute search.



6
7
8
# File 'lib/rspec_html/element.rb', line 6

def search
  @search
end

Class Method Details

.reconstituted(tag, options = {}) ⇒ Object



64
65
66
# File 'lib/rspec_html/element.rb', line 64

def self.reconstituted(tag, options = {})
  ReconstitutedElement.new(tag, options).to_s
end

Instance Method Details

#html_pathObject



29
30
31
32
33
# File 'lib/rspec_html/element.rb', line 29

def html_path
  @html_path ||= Pathname.new(Dir.mktmpdir('rspec-html')).join('document.html').tap do |path|
    path.write(@element.inner_html)
  end
end

#inspectObject



42
43
44
# File 'lib/rspec_html/element.rb', line 42

def inspect
  reconstituted
end

#openObject



25
26
27
# File 'lib/rspec_html/element.rb', line 25

def open
  Browser.open(html_path)
end

#present?Boolean Also known as: exist?

Returns:

  • (Boolean)


35
36
37
38
39
# File 'lib/rspec_html/element.rb', line 35

def present?
  return true if name == :document

  @search.present?
end

#reconstitutedObject



60
61
62
# File 'lib/rspec_html/element.rb', line 60

def reconstituted
  self.class.reconstituted(name, @options)
end

#to_sObject



46
47
48
# File 'lib/rspec_html/element.rb', line 46

def to_s
  @element.to_s
end