Class: RSpecHtmlMatchers::NokogiriTextHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec-html-matchers/nokogiri_text_helper.rb

Constant Summary collapse

NON_BREAKING_SPACE =
"\u00a0"

Instance Method Summary collapse

Constructor Details

#initialize(text, squeeze_text = false) ⇒ NokogiriTextHelper

Returns a new instance of NokogiriTextHelper.



10
11
12
13
# File 'lib/rspec-html-matchers/nokogiri_text_helper.rb', line 10

def initialize text, squeeze_text = false
  @text = text
  @squeeze_text = squeeze_text
end

Instance Method Details

#content(node_set) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/rspec-html-matchers/nokogiri_text_helper.rb', line 15

def content node_set
  node_set.find_all do |node|
    actual_content = node.content.gsub(NON_BREAKING_SPACE, ' ')
    actual_content = node.content.gsub(/\s+/, ' ').strip if @squeeze_text

    actual_content == @text
  end
end