assert2 0.4.9 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/assert2/rjs.rb +78 -10
- metadata +2 -2
data/lib/assert2/rjs.rb
CHANGED
@@ -13,7 +13,8 @@ module Test; module Unit; module Assertions
|
|
13
13
|
@js, @command, @scope = js, command, scope
|
14
14
|
end
|
15
15
|
|
16
|
-
attr_reader :command, :js, :scope
|
16
|
+
attr_reader :command, :js, :scope, :failure_message
|
17
|
+
# TODO rename js to sample
|
17
18
|
|
18
19
|
def match(kode)
|
19
20
|
RKelly.parse(js).pointcut(kode).
|
@@ -31,12 +32,28 @@ module Test; module Unit; module Assertions
|
|
31
32
|
end
|
32
33
|
|
33
34
|
def flunk(about)
|
34
|
-
|
35
|
+
@failure_message ||= complain(about)
|
35
36
|
end
|
36
|
-
|
37
|
+
|
37
38
|
def match_or_flunk(why)
|
39
|
+
@text = @text.to_s
|
38
40
|
@matcher = @matcher.to_s if @matcher.kind_of?(Symbol)
|
39
|
-
|
41
|
+
return if Regexp.new(@matcher) =~ @text or @text.index(@matcher)
|
42
|
+
@failure_message = scope.build_message(complain(why),
|
43
|
+
"<?> expected to be =~\n<?>.", @text, @matcher)
|
44
|
+
end
|
45
|
+
|
46
|
+
# ERGO blog about how bottom-up TDD decouples
|
47
|
+
# ERGO assert_no_rjs_ ...without! ... oh the humanity!
|
48
|
+
|
49
|
+
def wrap_expectation whatever; yield; end unless defined? wrap_expectation
|
50
|
+
|
51
|
+
def assert_xhtml(why, &block)
|
52
|
+
# scope.assert_xhtml @text, complain(why), &block
|
53
|
+
matcher = BeHtmlWith.new(self, &block)
|
54
|
+
matcher.message = complain(why)
|
55
|
+
matcher.matches?(@text, &block)
|
56
|
+
@failure_message = matcher.failure_message
|
40
57
|
end
|
41
58
|
|
42
59
|
def pwn_call *args, &block # TODO use or reject the block
|
@@ -59,7 +76,7 @@ module Test; module Unit; module Assertions
|
|
59
76
|
|
60
77
|
matchers = matchers_backup.inspect
|
61
78
|
|
62
|
-
|
79
|
+
flunk("#{ command } to #{ target } with arguments #{
|
63
80
|
matchers } not found in #{ js }")
|
64
81
|
end
|
65
82
|
|
@@ -99,9 +116,10 @@ module Test; module Unit; module Assertions
|
|
99
116
|
|
100
117
|
if div_id == target.to_s
|
101
118
|
cornplaint = complain("for ID #{ target } has incorrect payload, in")
|
102
|
-
|
103
|
-
|
104
|
-
|
119
|
+
@text = html
|
120
|
+
match_or_flunk cornplaint if @matcher
|
121
|
+
assert_xhtml cornplaint, &block if block
|
122
|
+
return html # TODO match any html not just the first. Because!
|
105
123
|
end
|
106
124
|
end
|
107
125
|
end
|
@@ -116,17 +134,67 @@ module Test; module Unit; module Assertions
|
|
116
134
|
end
|
117
135
|
end
|
118
136
|
|
119
|
-
def
|
137
|
+
def __interpret_rjs(command, *args, &block)
|
120
138
|
klass = command.to_s.upcase
|
121
139
|
klass = eval("AssertRjs::#{klass}") rescue
|
122
140
|
flunk("#{command} not implemented!")
|
123
141
|
asserter = klass.new(@response.body, command, self)
|
124
|
-
|
142
|
+
sample = asserter.pwn(*args, &block)
|
143
|
+
return sample, asserter
|
144
|
+
end
|
145
|
+
|
146
|
+
def assert_rjs_(command, *args, &block)
|
147
|
+
sample, asserter = __interpret_rjs(command, *args, &block)
|
148
|
+
asserter.failure_message and flunk(asserter.failure_message)
|
149
|
+
return sample
|
125
150
|
end
|
126
151
|
|
152
|
+
def assert_no_rjs_(command, *args, &block)
|
153
|
+
sample, asserter = __interpret_rjs(command, *args, &block)
|
154
|
+
asserter.failure_message and return sample
|
155
|
+
flunk("should not find #{sample.inspect} in\n#{asserter.js}") # TODO complaint system
|
156
|
+
end
|
157
|
+
|
158
|
+
# TODO wrappers for RSpec
|
159
|
+
|
127
160
|
# command == :replace_html or # TODO put me inside the method_missing!
|
128
161
|
# flunk("assert_rjs's alpha version only respects :replace_html")
|
129
162
|
# TODO also crack out the args correctly and gripe if they wrong
|
130
163
|
# TODO TDD the @matcher can be a string or regexp
|
131
164
|
|
132
165
|
end; end; end
|
166
|
+
|
167
|
+
module Spec; module Matchers
|
168
|
+
|
169
|
+
class SendJsTo
|
170
|
+
def initialize(scope, command, *args, &block)
|
171
|
+
@scope, @command, @args, @block = scope, command, args, block
|
172
|
+
end
|
173
|
+
|
174
|
+
def matches?(response, &block)
|
175
|
+
@block = block if block
|
176
|
+
sample, asserter = @scope.__interpret_rjs(response, @command, @args, &@block)
|
177
|
+
return !(@failure_message = asserter.failure_message) # or
|
178
|
+
# @negative_failure_message = "should not find #{sample.inspect} in\n#{asserter.js}" # TODO complaint system
|
179
|
+
end
|
180
|
+
|
181
|
+
attr_reader :failure_message, :negative_failure_message
|
182
|
+
end
|
183
|
+
|
184
|
+
def __interpret_rjs(response, command, *args, &block)
|
185
|
+
klass = command.to_s.upcase
|
186
|
+
klass = eval("Test::Unit::Assertions::AssertRjs::#{klass}") rescue
|
187
|
+
flunk("#{command} not implemented!")
|
188
|
+
asserter = klass.new(response, command, self)
|
189
|
+
sample = asserter.pwn(*args, &block)
|
190
|
+
return sample, asserter
|
191
|
+
end # ERGO further merging!
|
192
|
+
|
193
|
+
def send_js_to(*args, &block)
|
194
|
+
SendJsTo.new(self, *args, &block)
|
195
|
+
end
|
196
|
+
|
197
|
+
def generate_js_to(*args, &block)
|
198
|
+
send_js_to(*args, &block)
|
199
|
+
end
|
200
|
+
end; 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
|
+
version: 0.5.0
|
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-04-
|
12
|
+
date: 2009-04-11 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|