webpoke 0.0.42 → 0.0.45
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.
- checksums.yaml +4 -4
- data/bin/poke +12 -8
- data/lib/Webpoke/Class.rb +1 -1
- data/lib/Webpoke/Test.rb +42 -5
- data/lib/Webpoke/version.rb +1 -1
- data/lib/webpoke.rb +104 -42
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0c431ea215a727e9877d8f74240ccb0e90eb7bd
|
4
|
+
data.tar.gz: 245c37771d159e896332d10de48b4a0a9efec6af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 812bc22f223f176cbfc28cfdc7ae1d3ae257be7f87ed5bd0de9501be62b8f79a18ce1eabd71895662b36aece783b9dd474710db61494a479fe96054c70f59bed
|
7
|
+
data.tar.gz: ac2eb679c651ec5f86162c02f3126c61a1a1abf66b70f73064f78d8a3917a5443d3b22e8c53ce6207bb89c5f9dbedd487e58f703cc3e2402afc6c1fcc65f0271
|
data/bin/poke
CHANGED
@@ -46,7 +46,7 @@ optparser = OptionParser.new do |opts|
|
|
46
46
|
puts "<#{format}> is not a recognized format, try [#{formats.join(', ')}]"
|
47
47
|
exit
|
48
48
|
end
|
49
|
-
|
49
|
+
options[:format] = format;
|
50
50
|
end
|
51
51
|
|
52
52
|
if !ARGV[0]
|
@@ -71,11 +71,15 @@ elsif (File.file?(file))
|
|
71
71
|
require File.expand_path(file)
|
72
72
|
end
|
73
73
|
|
74
|
-
|
75
|
-
options[:doc]
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
Webpoke.run(options[:group])
|
74
|
+
begin
|
75
|
+
if options[:doc]
|
76
|
+
options[:doc] << Webpoke.document(options[:group])
|
77
|
+
exit 0
|
78
|
+
end
|
80
79
|
|
81
|
-
|
80
|
+
Webpoke.run(options[:group])
|
81
|
+
puts Webpoke.results()
|
82
|
+
rescue Interrupt => e
|
83
|
+
puts Webpoke.results()
|
84
|
+
exit!
|
85
|
+
end
|
data/lib/Webpoke/Class.rb
CHANGED
@@ -2,7 +2,7 @@ class Class
|
|
2
2
|
|
3
3
|
def mark_accessible (*args)
|
4
4
|
args.each do |arg|
|
5
|
-
self.class_eval("def #{arg} (val=nil); if (val) then @#{arg} = val; else @#{arg}; end end")
|
5
|
+
self.class_eval("def #{arg} (val=nil); if (val != nil) then @#{arg} = val; else @#{arg}; end end")
|
6
6
|
self.class_eval("def #{arg}=(val);@#{arg}=val;end")
|
7
7
|
end
|
8
8
|
end
|
data/lib/Webpoke/Test.rb
CHANGED
@@ -3,16 +3,36 @@
|
|
3
3
|
=end
|
4
4
|
class Webpoke::Test
|
5
5
|
|
6
|
-
mark_accessible :description, :group, :url, :method, :success, :query, :should_fail, :headers, :data
|
6
|
+
mark_accessible :description, :group, :url, :method, :success, :query, :should_fail, :headers, :data, :body, :on_success, :dependant, :depends_on, :response, :parse
|
7
7
|
|
8
8
|
def initialize(&block)
|
9
|
+
@parse = true
|
10
|
+
@on_success = [];
|
9
11
|
instance_eval(&block);
|
10
12
|
@group = @group || ''
|
11
13
|
@method = @method || 'get'
|
12
14
|
@headers = @headers || {}
|
15
|
+
@on_success = [];
|
16
|
+
end
|
17
|
+
|
18
|
+
def should_parse?
|
19
|
+
return @parse
|
20
|
+
end
|
21
|
+
|
22
|
+
def on (response, &block)
|
23
|
+
|
24
|
+
if (response == 'success')
|
25
|
+
@on_success << block
|
26
|
+
else
|
27
|
+
@on_error << block
|
28
|
+
end
|
13
29
|
|
14
30
|
end
|
15
31
|
|
32
|
+
def depends_on otherTest
|
33
|
+
otherTest.on_success << self
|
34
|
+
self.dependant = true;
|
35
|
+
end
|
16
36
|
|
17
37
|
def default_success (code, body)
|
18
38
|
if @should_fail
|
@@ -22,7 +42,6 @@ class Webpoke::Test
|
|
22
42
|
end
|
23
43
|
end
|
24
44
|
|
25
|
-
|
26
45
|
def success (&block)
|
27
46
|
@success = block
|
28
47
|
end
|
@@ -83,11 +102,20 @@ Returns the test description
|
|
83
102
|
end
|
84
103
|
|
85
104
|
|
105
|
+
def dependant?
|
106
|
+
@dependant
|
107
|
+
end
|
108
|
+
|
109
|
+
|
86
110
|
=begin rdoc
|
87
111
|
Run the test
|
88
112
|
=end
|
89
113
|
def passed? (response, body)
|
90
114
|
|
115
|
+
@response = {
|
116
|
+
body: body,
|
117
|
+
code: response
|
118
|
+
}
|
91
119
|
if !self.default_success(response, body)
|
92
120
|
return false
|
93
121
|
end
|
@@ -98,9 +126,7 @@ Returns the test description
|
|
98
126
|
result = @success.call(response, body)
|
99
127
|
rescue Exception => e
|
100
128
|
result = false
|
101
|
-
Webpoke.
|
102
|
-
Webpoke.log e
|
103
|
-
Webpoke.log e.backtrace.join "\n"
|
129
|
+
raise Webpoke::TestSuccessError.new(e.message, e)
|
104
130
|
end
|
105
131
|
else
|
106
132
|
result = self.default_success(response, body)
|
@@ -113,4 +139,15 @@ Returns the test description
|
|
113
139
|
end
|
114
140
|
|
115
141
|
class Webpoke::TestError < StandardError
|
142
|
+
attr_accessor :object
|
143
|
+
def initialize(message=nil, object=nil)
|
144
|
+
super(message)
|
145
|
+
self.object = object
|
146
|
+
end
|
147
|
+
end
|
148
|
+
class Webpoke::TestSuccessError < Webpoke::TestError
|
149
|
+
end
|
150
|
+
class Webpoke::TestHTTPError < Webpoke::TestError
|
151
|
+
end
|
152
|
+
class Webpoke::TestParseError < Webpoke::TestError
|
116
153
|
end
|
data/lib/Webpoke/version.rb
CHANGED
data/lib/webpoke.rb
CHANGED
@@ -49,7 +49,9 @@ module Webpoke
|
|
49
49
|
# Adds a test to the queue
|
50
50
|
# @param block [Proc] the configuration for this test
|
51
51
|
def test(&block)
|
52
|
-
|
52
|
+
test = Test.new(&block)
|
53
|
+
$tests << test
|
54
|
+
return test
|
53
55
|
end
|
54
56
|
|
55
57
|
|
@@ -79,6 +81,10 @@ module Webpoke
|
|
79
81
|
end
|
80
82
|
end
|
81
83
|
|
84
|
+
if test.body
|
85
|
+
args[:body] = test.body
|
86
|
+
end
|
87
|
+
|
82
88
|
args[:query] = test.query if test.query
|
83
89
|
|
84
90
|
args
|
@@ -91,55 +97,90 @@ module Webpoke
|
|
91
97
|
$config = Webpoke::Config.new(&block)
|
92
98
|
end
|
93
99
|
|
100
|
+
def run_test(test)
|
101
|
+
|
102
|
+
$tested +=1
|
103
|
+
fqu = if test.url.match(/^https?:\/\//i) then test.url; else $config.base+test.url; end
|
104
|
+
args = args_for_test(test)
|
105
|
+
|
106
|
+
log "#{$tested}: #{test.description}".bold
|
107
|
+
log "#{test.method.upcase}: #{test.url}...", false
|
108
|
+
$config.beforeSend(test.method, fqu, args) if $config.beforeSend
|
109
|
+
|
110
|
+
begin
|
111
|
+
r = HTTParty.send(test.method, fqu, args)
|
112
|
+
rescue Interrupt
|
113
|
+
puts Webpoke.results
|
114
|
+
exit!
|
115
|
+
rescue Exception => e
|
116
|
+
raise Webpoke::TestHTTPError.new(e.message, e)
|
117
|
+
end
|
118
|
+
|
119
|
+
body = r.body
|
120
|
+
begin
|
121
|
+
if test.should_parse? && $config.parse[:output] && body.is_a?(String)
|
122
|
+
body = $config.parse[:output].call(r.body)
|
123
|
+
end
|
124
|
+
rescue Exception => e
|
125
|
+
raise Webpoke::TestParseError.new(e.message, body)
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
if test.passed?(r.code, body)
|
130
|
+
true
|
131
|
+
else
|
132
|
+
if $config.on_failure
|
133
|
+
log $config.on_failure.call(r.code, body)
|
134
|
+
end
|
135
|
+
false
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
def gauge_success(test)
|
141
|
+
begin
|
142
|
+
success = run_test test
|
143
|
+
rescue Webpoke::TestHTTPError => e
|
144
|
+
log 'FAIL:'.red
|
145
|
+
log e
|
146
|
+
$errors += 1;
|
147
|
+
rescue Webpoke::TestParseError => e
|
148
|
+
log "Parsing failure: ".red
|
149
|
+
log "\t#{e}"
|
150
|
+
log "Data:"
|
151
|
+
log "\t"+e.object
|
152
|
+
$errors += 1;
|
153
|
+
rescue Webpoke::TestSuccessError => e
|
154
|
+
log "\nError while executing success for test".red
|
155
|
+
log e
|
156
|
+
log e.backtrace.join "\n"
|
157
|
+
end
|
158
|
+
|
159
|
+
if (success)
|
160
|
+
$successes +=1
|
161
|
+
log "OK!".green
|
162
|
+
test.on_success.each do |dependent|
|
163
|
+
dt = dependent.call()
|
164
|
+
gauge_success dt
|
165
|
+
end
|
166
|
+
else
|
167
|
+
$errors += 1
|
168
|
+
log "FAIL!".red
|
169
|
+
end
|
170
|
+
return success
|
171
|
+
|
172
|
+
end
|
173
|
+
|
94
174
|
|
95
175
|
def run (group=nil)
|
96
176
|
|
97
177
|
$tests.each do |test|
|
98
178
|
next if group && test.group != group
|
99
|
-
$tested +=1
|
100
|
-
|
101
|
-
fqu = if test.url.match(/^https?:\/\//i) then url; else $config.base+test.url; end
|
102
|
-
|
103
|
-
args = args_for_test(test)
|
104
179
|
|
105
|
-
|
180
|
+
next if test.dependant?
|
106
181
|
|
107
|
-
|
108
|
-
log "#{test.method.upcase}: #{test.url}...", false
|
109
|
-
begin
|
110
|
-
r = HTTParty.send(test.method, fqu, args)
|
111
|
-
rescue Exception => e
|
112
|
-
log 'FAIL:'.red
|
113
|
-
log e
|
114
|
-
$errors += 1;
|
115
|
-
next;
|
116
|
-
end
|
117
|
-
|
118
|
-
body = r.body
|
119
|
-
begin
|
120
|
-
if $config.parse[:output] && body.is_a?(String)
|
121
|
-
body = $config.parse[:output].call(r.body)
|
122
|
-
end
|
123
|
-
rescue Exception => e
|
124
|
-
log "Parsing failure: ".red
|
125
|
-
log "\t#{e}"
|
126
|
-
log "Data:"
|
127
|
-
log "\t"+r.body
|
128
|
-
$errors += 1;
|
129
|
-
next;
|
130
|
-
end
|
182
|
+
gauge_success(test)
|
131
183
|
|
132
|
-
|
133
|
-
if test.passed?(r.code, body)
|
134
|
-
$successes +=1
|
135
|
-
log "OK!".green
|
136
|
-
else
|
137
|
-
log "FAIL!".red
|
138
|
-
|
139
|
-
if $config.on_failure
|
140
|
-
log $config.on_failure.call(r.code, body)
|
141
|
-
end
|
142
|
-
end
|
143
184
|
end
|
144
185
|
|
145
186
|
end
|
@@ -170,6 +211,27 @@ module Webpoke
|
|
170
211
|
|
171
212
|
end
|
172
213
|
|
214
|
+
|
215
|
+
def Webpoke.results()
|
216
|
+
|
217
|
+
if $config.format == 'stdout'
|
218
|
+
puts "\nTests: #{Webpoke.tested}, success: #{Webpoke.success}, errors: #{Webpoke.failed}";
|
219
|
+
else
|
220
|
+
puts JSON.pretty_generate({
|
221
|
+
tests: Webpoke.tested,
|
222
|
+
success: Webpoke.success,
|
223
|
+
errors: Webpoke.failed
|
224
|
+
})
|
225
|
+
end
|
226
|
+
|
227
|
+
if (Webpoke.failed > 0)
|
228
|
+
exit 1;
|
229
|
+
else
|
230
|
+
exit 0;
|
231
|
+
end
|
232
|
+
|
233
|
+
end
|
234
|
+
|
173
235
|
def Webpoke.success
|
174
236
|
return $successes
|
175
237
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webpoke
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.45
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Hidalgo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|