assert2 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/assert2/xhtml.rb CHANGED
@@ -87,15 +87,24 @@ class BeHtmlWith
87
87
  element.xpath('text()').map{|x|x.to_s.strip}.reject{|x|x==''}.compact
88
88
  end
89
89
 
90
+ def match_regexp(reference, sample)
91
+ reference =~ /^\(\?/ and
92
+ Regexp.new(reference) =~ sample
93
+ end
94
+
90
95
  def match_text(ref, sam)
91
96
  ref_text = get_texts(ref)
92
97
  # TODO regices?
93
- ref_text.empty? or ( ref_text - get_texts(sam) ).empty?
94
- end
98
+ ref_text.empty? or ( ref_text - (sam_text = get_texts(sam)) ).empty? or
99
+ (ref_text.length == 1 and
100
+ match_regexp(ref_text.first, sam_text.join) )
101
+ end # The irony _is_ lost on us
95
102
 
96
103
  def match_attributes_and_text(reference, sample)
97
104
  reference.attribute_nodes.each do |attr|
98
- deAmpAmp(sample[attr.name]) == deAmpAmp(attr.value) or return false
105
+ ref, sam = deAmpAmp(attr.value), deAmpAmp(sample[attr.name])
106
+ ref == sam or match_regexp(ref, sam) or
107
+ return false
99
108
  end
100
109
 
101
110
  return match_text(reference, sample)
@@ -281,3 +290,9 @@ module Spec; module Matchers
281
290
  BeHtmlWith.new(self, &block)
282
291
  end
283
292
  end; end
293
+
294
+ class Nokogiri::XML::Node
295
+ def content= string
296
+ self.native_content = encode_special_chars(string.to_s)
297
+ end
298
+ end
@@ -80,7 +80,6 @@ end
80
80
  class BeHtmlWith
81
81
 
82
82
  def deAmpAmp(stwing)
83
- p stwing
84
83
  stwing.gsub('&', '&').gsub('&', '&')
85
84
  end # ERGO await a fix in Nokogiri, and hope nobody actually means & !!!
86
85
 
@@ -88,16 +87,25 @@ class BeHtmlWith
88
87
  element.xpath('text()').map{|x|x.to_s.strip}.reject{|x|x==''}.compact
89
88
  end
90
89
 
90
+ def match_regexp(reference, sample)
91
+ p reference
92
+ reference =~ /^\(\?-mix/ and
93
+ Regexp.new(reference) =~ sample
94
+ end
95
+
91
96
  def match_text(ref, sam)
92
97
  ref_text = get_texts(ref)
93
98
  # TODO regices?
94
- ref_text.empty? or ( ref_text - get_texts(sam) ).empty?
95
- end
99
+ ref_text.empty? or ( ref_text - (sam_text = get_texts(sam)) ).empty? or
100
+ (ref_text.length == 1 and
101
+ match_regexp(ref_text.first, sam_text.join) )
102
+ end # The irony _is_ lost on us
96
103
 
97
104
  def match_attributes_and_text(reference, sample)
98
105
  reference.attribute_nodes.each do |attr|
99
- p sample[attr.name]
100
- deAmpAmp(sample[attr.name]) == deAmpAmp(attr.value) or return false
106
+ ref, sam = deAmpAmp(attr.value), deAmpAmp(sample[attr.name])
107
+ ref == sam or match_regexp(ref, sam) or
108
+ return false
101
109
  end
102
110
 
103
111
  return match_text(reference, sample)
@@ -283,3 +291,9 @@ module Spec; module Matchers
283
291
  BeHtmlWith.new(self, &block)
284
292
  end
285
293
  end; end
294
+
295
+ class Nokogiri::XML::Node
296
+ def content= string
297
+ self.native_content = encode_special_chars(string.to_s)
298
+ end
299
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assert2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phlip