assert2 0.5.3 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/assert2/rjs.rb +48 -6
  2. data/lib/assert2/xhtml.rb +17 -9
  3. metadata +2 -2
@@ -63,12 +63,20 @@ module Test; module Unit; module Assertions
63
63
  matchers = matchers_backup.dup
64
64
 
65
65
  thang.value.each do |arg|
66
- @text = eval(arg.value)
66
+ # p arg
67
67
  @matcher = matchers.first # or return @text
68
- @matcher.to_s == @text or /#{ @matcher }/ =~ @text or break
68
+
69
+ if @matcher.kind_of?(Hash) and
70
+ hash = props_to_hash(arg)
71
+ hash_match(hash, @matcher) or break # TODO rename to match_hash
72
+ else
73
+ @text = eval(arg.value)
74
+ @matcher.to_s == @text or /#{ @matcher }/ =~ @text or break
75
+ end
76
+
69
77
  matchers.shift
70
78
  end
71
-
79
+
72
80
  matchers.empty? and
73
81
  matchers_backup.length == thang.value.length and
74
82
  return @text
@@ -80,6 +88,32 @@ module Test; module Unit; module Assertions
80
88
  matchers } not found in #{ js }")
81
89
  end
82
90
 
91
+ def props_to_hash(props)
92
+ case props
93
+ when RKelly::Nodes::ObjectLiteralNode
94
+ hash = {}
95
+
96
+ props.value.each do |thang|
97
+ hash[thang.name.to_sym] = eval(thang.value.value)
98
+ end
99
+
100
+ return hash
101
+
102
+ else
103
+ return nil
104
+ end
105
+ end
106
+
107
+ def hash_match(sample, reference)
108
+ reference.each do |key, value|
109
+ sample[key] == value or
110
+ value.kind_of?(Regexp) && sample[key] =~ value or
111
+ return false
112
+ end
113
+
114
+ return true
115
+ end
116
+
83
117
  class ALERT < AssertRjs
84
118
  def pwn *args, &block
85
119
  @command = :call
@@ -87,6 +121,12 @@ module Test; module Unit; module Assertions
87
121
  end
88
122
  end
89
123
 
124
+ class CALL < AssertRjs
125
+ def pwn *args, &block # TODO use or reject the block
126
+ pwn_call *args, &block
127
+ end
128
+ end
129
+
90
130
  class REMOVE < AssertRjs
91
131
  def pwn *args, &block
92
132
  @command = :call
@@ -101,9 +141,11 @@ module Test; module Unit; module Assertions
101
141
  end
102
142
  end
103
143
 
104
- class CALL < AssertRjs
105
- def pwn *args, &block # TODO use or reject the block
106
- pwn_call *args, &block
144
+ class INSERT_HTML < AssertRjs
145
+ def pwn *args, &block
146
+ @command = :call
147
+ location, id, html = args
148
+ pwn_call 'Element.insert', id, { location.to_sym => html }, &block
107
149
  end
108
150
  end
109
151
 
@@ -97,9 +97,16 @@ class BeHtmlWith
97
97
  end
98
98
 
99
99
  def elemental_children(element = @builder.doc)
100
- element.children.grep(Nokogiri::XML::Element)
101
- end
100
+ element_kids = element.children.grep(Nokogiri::XML::Node)
101
+
102
+ element_kids = element_kids.reject{|k|
103
+ k.class == Nokogiri::XML::Text ||
104
+ k.class == Nokogiri::XML::DTD
105
+ } # CONSIDER rebuild to use not abuse the text nodage!
102
106
 
107
+ return element_kids
108
+ end
109
+
103
110
  def build_deep_xpath(element)
104
111
  path = build_xpath(element)
105
112
  path.index('not(') == 0 and return '/*[ ' + path + ' ]'
@@ -149,9 +156,9 @@ class BeHtmlWith
149
156
 
150
157
  def match_xpath(path, &refer)
151
158
  nodes = @doc.root.xpath_with_callback path, :refer do |element, index|
152
- collect_samples(element, index.to_i)
153
- end
154
-
159
+ collect_samples(element, index.to_i)
160
+ end
161
+
155
162
  @returnable ||= nodes.first # TODO be_with_html must get on board too
156
163
  return nodes
157
164
  end
@@ -242,11 +249,12 @@ class BeHtmlWith
242
249
  ref_text.empty? and return true
243
250
  sam_text = get_texts(sam)
244
251
  (ref_text - sam_text).empty? and return true
245
- ref_text.length == 1 and match_regexp(ref_text.first, sam_text.join)
252
+ got = (ref_text.length == 1 and match_regexp(ref_text.first, sam_text.join))
253
+ return got
246
254
  end
247
255
 
248
256
  def get_texts(element)
249
- element.children.grep(Nokogiri::XML::Text).
257
+ element.children.grep(Nokogiri::XML::Text).
250
258
  map{|x|x.to_s.strip}.select{|x|x.any?}
251
259
  end
252
260
 
@@ -278,7 +286,7 @@ class BeHtmlWith
278
286
 
279
287
  def build_xpath_too(element)
280
288
  path = element.name.sub(/\!$/, '')
281
- element_kids = element.children.grep(Nokogiri::XML::Element)
289
+ element_kids = element.children.grep(Nokogiri::XML::Node)
282
290
  path << '[ '
283
291
  count = @references.length
284
292
  @references << element
@@ -384,4 +392,4 @@ module Nokogiri
384
392
  end
385
393
  end
386
394
  end
387
- end
395
+ 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.5.3
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phlip
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-10 00:00:00 -07:00
12
+ date: 2009-06-20 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15