strelka 0.0.1.pre.305 → 0.0.1.pre.308
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/ChangeLog +27 -3
- data/Manifest.txt +1 -0
- data/lib/strelka/constants.rb +3 -2
- data/lib/strelka/cookie.rb +4 -0
- data/lib/strelka/testing.rb +185 -0
- data/spec/lib/helpers.rb +3 -169
- metadata +3 -2
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/ChangeLog
CHANGED
@@ -1,12 +1,36 @@
|
|
1
|
+
2012-09-21 Michael Granger <ged@FaerieMUD.org>
|
2
|
+
|
3
|
+
* Manifest.txt, lib/strelka/testing.rb, spec/lib/helpers.rb:
|
4
|
+
Split out some testing helper functions and RSpec matchers.
|
5
|
+
|
6
|
+
Put them into 'strelka/testing' ala 'mongrel2/testing'.
|
7
|
+
[c58b05ad837b] [tip]
|
8
|
+
|
9
|
+
* lib/strelka/constants.rb:
|
10
|
+
Header fix
|
11
|
+
[44a9b3386915]
|
12
|
+
|
13
|
+
* lib/strelka/cookie.rb:
|
14
|
+
Added reference docs to Strelka::Cookie
|
15
|
+
[91dc69268b9b]
|
16
|
+
|
1
17
|
2012-09-18 Michael Granger <ged@FaerieMUD.org>
|
2
18
|
|
19
|
+
* .rvm.gems, Rakefile:
|
20
|
+
Bump mongrel2 dependency.
|
21
|
+
[8d94f8575209]
|
22
|
+
|
23
|
+
* .rvm.gems:
|
24
|
+
Update rvm gems to match gem dependencies
|
25
|
+
[f5ffb135b975]
|
26
|
+
|
3
27
|
* lib/strelka/authprovider/basic.rb,
|
4
28
|
spec/strelka/authprovider/basic_spec.rb:
|
5
29
|
Simplified Strelka::AuthProvider::Basic.
|
6
30
|
|
7
31
|
- removed the pbkdf2_hmac stuff for simplicity
|
8
32
|
- made it easier to use it as a base class for other auth providers.
|
9
|
-
[dbb4523ad258]
|
33
|
+
[dbb4523ad258]
|
10
34
|
|
11
35
|
* Rakefile:
|
12
36
|
Update dependencies
|
@@ -34,7 +58,7 @@
|
|
34
58
|
|
35
59
|
Got most of the default plugins covered at least minimally. Split
|
36
60
|
out the rest of the manual into RDoc pages.
|
37
|
-
[41ef7a20e7cb]
|
61
|
+
[41ef7a20e7cb] [github/master]
|
38
62
|
|
39
63
|
2012-08-24 Mahlon E. Smith <mahlon@martini.nu>
|
40
64
|
|
@@ -1041,7 +1065,7 @@
|
|
1041
1065
|
|
1042
1066
|
* lib/strelka/app/errors.rb, spec/strelka/app/errors_spec.rb:
|
1043
1067
|
Add documentation for the Errors plugin, improve test coverage.
|
1044
|
-
[ff3ef6e5a7a1]
|
1068
|
+
[ff3ef6e5a7a1] [github/master@default]
|
1045
1069
|
|
1046
1070
|
* Manifest.txt:
|
1047
1071
|
Add session files to the manifest
|
data/Manifest.txt
CHANGED
data/lib/strelka/constants.rb
CHANGED
data/lib/strelka/cookie.rb
CHANGED
@@ -0,0 +1,185 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# vim: set nosta noet ts=4 sw=4:
|
3
|
+
# encoding: utf-8
|
4
|
+
|
5
|
+
require 'rspec'
|
6
|
+
require 'rspec/matchers'
|
7
|
+
|
8
|
+
# A collection of testing functions and classes for use in Strelka handlers
|
9
|
+
# and libraries.
|
10
|
+
module Strelka::Testing
|
11
|
+
|
12
|
+
###############
|
13
|
+
module_function
|
14
|
+
###############
|
15
|
+
|
16
|
+
#
|
17
|
+
# Matchers
|
18
|
+
#
|
19
|
+
|
20
|
+
# Route matcher
|
21
|
+
RSpec::Matchers.define( :match_route ) do |routename|
|
22
|
+
match do |route|
|
23
|
+
route[:action] == routename
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Collection .all? matcher
|
28
|
+
RSpec::Matchers.define( :all_be_a ) do |expected|
|
29
|
+
match do |collection|
|
30
|
+
collection.all? {|obj| obj.is_a?(expected) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# finish_with matcher
|
35
|
+
class FinishWithMatcher
|
36
|
+
|
37
|
+
### Create a new matcher for the specified +status+, +expected_message+, and
|
38
|
+
### +expected_headers+.
|
39
|
+
def initialize( status, expected_message=nil, expected_headers={} )
|
40
|
+
|
41
|
+
# Allow headers, but no message
|
42
|
+
if expected_message.is_a?( Hash )
|
43
|
+
expected_headers = expected_message
|
44
|
+
expected_message = nil
|
45
|
+
end
|
46
|
+
|
47
|
+
@expected_status = status
|
48
|
+
@expected_message = expected_message
|
49
|
+
@expected_headers = expected_headers || {}
|
50
|
+
|
51
|
+
@failure = nil
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
######
|
56
|
+
public
|
57
|
+
######
|
58
|
+
|
59
|
+
##
|
60
|
+
# The data structures expected to be part of the response's status_info.
|
61
|
+
attr_reader :expected_status, :expected_message, :expected_headers
|
62
|
+
|
63
|
+
|
64
|
+
### Also expect a header with the given +name+ and +value+ from the response.
|
65
|
+
def and_header( name, value=nil )
|
66
|
+
if name.is_a?( Hash )
|
67
|
+
self.expected_headers.merge!( name )
|
68
|
+
else
|
69
|
+
self.expected_headers[ name ] = value
|
70
|
+
end
|
71
|
+
return self
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
### RSpec matcher API -- call the +given_proc+ and ensure that it behaves in
|
76
|
+
### the expected manner.
|
77
|
+
def matches?( given_proc )
|
78
|
+
result = nil
|
79
|
+
status_info = catch( :finish ) do
|
80
|
+
given_proc.call
|
81
|
+
nil
|
82
|
+
end
|
83
|
+
|
84
|
+
return self.check_finish( status_info ) &&
|
85
|
+
self.check_status_code( status_info ) &&
|
86
|
+
self.check_message( status_info ) &&
|
87
|
+
self.check_headers( status_info )
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
### Check the result from calling the proc to ensure it's a status
|
92
|
+
### info Hash, returning true if so, or setting the failure message and
|
93
|
+
### returning false if not.
|
94
|
+
def check_finish( status_info )
|
95
|
+
return true if status_info && status_info.is_a?( Hash )
|
96
|
+
@failure = "an abnormal status"
|
97
|
+
return false
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
### Check the result's status code against the expectation, returning true if
|
102
|
+
### it was the same, or setting the failure message and returning false if not.
|
103
|
+
def check_status_code( status_info )
|
104
|
+
return true if status_info[:status] == self.expected_status
|
105
|
+
@failure = "a %d status, but got %d instead" %
|
106
|
+
[ self.expected_status, status_info[:status] ]
|
107
|
+
return false
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
### Check the result's status message against the expectation, returning true if
|
112
|
+
### it was present and matched the expectation, or setting the failure message
|
113
|
+
### and returning false if not.
|
114
|
+
def check_message( status_info )
|
115
|
+
msg = self.expected_message or return true
|
116
|
+
|
117
|
+
if msg.respond_to?( :match )
|
118
|
+
return true if msg.match( status_info[:message] )
|
119
|
+
@failure = "a message matching %p, but got: %p" % [ msg, status_info[:message] ]
|
120
|
+
return false
|
121
|
+
else
|
122
|
+
return true if msg == status_info[:message]
|
123
|
+
@failure = "the message %p, but got: %p" % [ msg, status_info[:message] ]
|
124
|
+
return false
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
### Check the result's headers against the expectation, returning true if all
|
130
|
+
### expected headers were present and set to expected values, or setting the failure
|
131
|
+
### message and returning false if not.
|
132
|
+
def check_headers( status_info )
|
133
|
+
headers = self.expected_headers or return true
|
134
|
+
return true if headers.empty?
|
135
|
+
|
136
|
+
status_headers = status_info[:headers]
|
137
|
+
headers.each do |name, value|
|
138
|
+
unless status_value = status_headers[ name ]
|
139
|
+
@failure = "a %s header" % [ name ]
|
140
|
+
return false
|
141
|
+
end
|
142
|
+
|
143
|
+
if value.respond_to?( :match )
|
144
|
+
unless value.match( status_value )
|
145
|
+
@failure = "a %s header matching %p, but got %p" %
|
146
|
+
[ name, value, status_value ]
|
147
|
+
return false
|
148
|
+
end
|
149
|
+
else
|
150
|
+
unless value == status_value
|
151
|
+
@failure = "the %s header %p, but got %p" %
|
152
|
+
[ name, value, status_value ]
|
153
|
+
return false
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
return true
|
159
|
+
end
|
160
|
+
|
161
|
+
|
162
|
+
### Return a message suitable for describing when the matcher fails when it should succeed.
|
163
|
+
def failure_message_for_should
|
164
|
+
return "expected response to finish_with %s" % [ @failure ]
|
165
|
+
end
|
166
|
+
|
167
|
+
|
168
|
+
### Return a message suitable for describing when the matcher succeeds when it should fail.
|
169
|
+
def failure_message_for_should_not
|
170
|
+
return "expected response not to finish_with %s" % [ @failure ]
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
end # class FinishWithMatcher
|
175
|
+
|
176
|
+
|
177
|
+
### Match a response thrown via the +finish_with+ function.
|
178
|
+
def finish_with( status, message=nil, headers={} )
|
179
|
+
FinishWithMatcher.new( status, message, headers )
|
180
|
+
end
|
181
|
+
|
182
|
+
|
183
|
+
end # module Strelka::Testing
|
184
|
+
|
185
|
+
|
data/spec/lib/helpers.rb
CHANGED
@@ -38,6 +38,7 @@ require 'mongrel2'
|
|
38
38
|
require 'mongrel2/testing'
|
39
39
|
|
40
40
|
require 'strelka'
|
41
|
+
require 'strelka/testing'
|
41
42
|
|
42
43
|
require 'spec/lib/constants'
|
43
44
|
|
@@ -46,7 +47,8 @@ Loggability.format_with( :color ) if $stdout.tty?
|
|
46
47
|
|
47
48
|
### RSpec helper functions.
|
48
49
|
module Strelka::SpecHelpers
|
49
|
-
include Strelka::TestConstants
|
50
|
+
include Strelka::TestConstants,
|
51
|
+
Strelka::Testing
|
50
52
|
|
51
53
|
###############
|
52
54
|
module_function
|
@@ -88,174 +90,6 @@ module Strelka::SpecHelpers
|
|
88
90
|
return tempdir
|
89
91
|
end
|
90
92
|
|
91
|
-
|
92
|
-
#
|
93
|
-
# Matchers
|
94
|
-
#
|
95
|
-
|
96
|
-
# Route matcher
|
97
|
-
RSpec::Matchers.define( :match_route ) do |routename|
|
98
|
-
match do |route|
|
99
|
-
route[:action] == routename
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
# Collection .all? matcher
|
104
|
-
RSpec::Matchers.define( :all_be_a ) do |expected|
|
105
|
-
match do |collection|
|
106
|
-
collection.all? {|obj| obj.is_a?(expected) }
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
# finish_with matcher
|
111
|
-
class FinishWithMatcher
|
112
|
-
|
113
|
-
### Create a new matcher for the specified +status+, +expected_message+, and
|
114
|
-
### +expected_headers+.
|
115
|
-
def initialize( status, expected_message=nil, expected_headers={} )
|
116
|
-
|
117
|
-
# Allow headers, but no message
|
118
|
-
if expected_message.is_a?( Hash )
|
119
|
-
expected_headers = expected_message
|
120
|
-
expected_message = nil
|
121
|
-
end
|
122
|
-
|
123
|
-
@expected_status = status
|
124
|
-
@expected_message = expected_message
|
125
|
-
@expected_headers = expected_headers || {}
|
126
|
-
|
127
|
-
@failure = nil
|
128
|
-
end
|
129
|
-
|
130
|
-
|
131
|
-
######
|
132
|
-
public
|
133
|
-
######
|
134
|
-
|
135
|
-
##
|
136
|
-
# The data structures expected to be part of the response's status_info.
|
137
|
-
attr_reader :expected_status, :expected_message, :expected_headers
|
138
|
-
|
139
|
-
|
140
|
-
### Also expect a header with the given +name+ and +value+ from the response.
|
141
|
-
def and_header( name, value=nil )
|
142
|
-
if name.is_a?( Hash )
|
143
|
-
self.expected_headers.merge!( name )
|
144
|
-
else
|
145
|
-
self.expected_headers[ name ] = value
|
146
|
-
end
|
147
|
-
return self
|
148
|
-
end
|
149
|
-
|
150
|
-
|
151
|
-
### RSpec matcher API -- call the +given_proc+ and ensure that it behaves in
|
152
|
-
### the expected manner.
|
153
|
-
def matches?( given_proc )
|
154
|
-
result = nil
|
155
|
-
status_info = catch( :finish ) do
|
156
|
-
given_proc.call
|
157
|
-
nil
|
158
|
-
end
|
159
|
-
|
160
|
-
return self.check_finish( status_info ) &&
|
161
|
-
self.check_status_code( status_info ) &&
|
162
|
-
self.check_message( status_info ) &&
|
163
|
-
self.check_headers( status_info )
|
164
|
-
end
|
165
|
-
|
166
|
-
|
167
|
-
### Check the result from calling the proc to ensure it's a status
|
168
|
-
### info Hash, returning true if so, or setting the failure message and
|
169
|
-
### returning false if not.
|
170
|
-
def check_finish( status_info )
|
171
|
-
return true if status_info && status_info.is_a?( Hash )
|
172
|
-
@failure = "an abnormal status"
|
173
|
-
return false
|
174
|
-
end
|
175
|
-
|
176
|
-
|
177
|
-
### Check the result's status code against the expectation, returning true if
|
178
|
-
### it was the same, or setting the failure message and returning false if not.
|
179
|
-
def check_status_code( status_info )
|
180
|
-
return true if status_info[:status] == self.expected_status
|
181
|
-
@failure = "a %d status, but got %d instead" %
|
182
|
-
[ self.expected_status, status_info[:status] ]
|
183
|
-
return false
|
184
|
-
end
|
185
|
-
|
186
|
-
|
187
|
-
### Check the result's status message against the expectation, returning true if
|
188
|
-
### it was present and matched the expectation, or setting the failure message
|
189
|
-
### and returning false if not.
|
190
|
-
def check_message( status_info )
|
191
|
-
msg = self.expected_message or return true
|
192
|
-
|
193
|
-
if msg.respond_to?( :match )
|
194
|
-
return true if msg.match( status_info[:message] )
|
195
|
-
@failure = "a message matching %p, but got: %p" % [ msg, status_info[:message] ]
|
196
|
-
return false
|
197
|
-
else
|
198
|
-
return true if msg == status_info[:message]
|
199
|
-
@failure = "the message %p, but got: %p" % [ msg, status_info[:message] ]
|
200
|
-
return false
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
|
205
|
-
### Check the result's headers against the expectation, returning true if all
|
206
|
-
### expected headers were present and set to expected values, or setting the failure
|
207
|
-
### message and returning false if not.
|
208
|
-
def check_headers( status_info )
|
209
|
-
headers = self.expected_headers or return true
|
210
|
-
return true if headers.empty?
|
211
|
-
|
212
|
-
status_headers = status_info[:headers]
|
213
|
-
headers.each do |name, value|
|
214
|
-
unless status_value = status_headers[ name ]
|
215
|
-
@failure = "a %s header" % [ name ]
|
216
|
-
return false
|
217
|
-
end
|
218
|
-
|
219
|
-
if value.respond_to?( :match )
|
220
|
-
unless value.match( status_value )
|
221
|
-
@failure = "a %s header matching %p, but got %p" %
|
222
|
-
[ name, value, status_value ]
|
223
|
-
return false
|
224
|
-
end
|
225
|
-
else
|
226
|
-
unless value == status_value
|
227
|
-
@failure = "the %s header %p, but got %p" %
|
228
|
-
[ name, value, status_value ]
|
229
|
-
return false
|
230
|
-
end
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
return true
|
235
|
-
end
|
236
|
-
|
237
|
-
|
238
|
-
### Return a message suitable for describing when the matcher fails when it should succeed.
|
239
|
-
def failure_message_for_should
|
240
|
-
return "expected response to finish_with %s" % [ @failure ]
|
241
|
-
end
|
242
|
-
|
243
|
-
|
244
|
-
### Return a message suitable for describing when the matcher succeeds when it should fail.
|
245
|
-
def failure_message_for_should_not
|
246
|
-
return "expected response not to finish_with %s" % [ @failure ]
|
247
|
-
end
|
248
|
-
|
249
|
-
|
250
|
-
end # class FinishWithMatcher
|
251
|
-
|
252
|
-
|
253
|
-
### Match a response thrown via the +finish_with+ function.
|
254
|
-
def finish_with( status, message=nil, headers={} )
|
255
|
-
FinishWithMatcher.new( status, message, headers )
|
256
|
-
end
|
257
|
-
|
258
|
-
|
259
93
|
end
|
260
94
|
|
261
95
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strelka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.pre.
|
4
|
+
version: 0.0.1.pre.308
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
YUhDS0xaZFNLai9SSHVUT3QrZ2JsUmV4OEZBaDhOZUEKY21saFhlNDZwWk5K
|
37
37
|
Z1dLYnhaYWg4NWpJang5NWhSOHZPSStOQU01aUg5a09xSzEzRHJ4YWNUS1Bo
|
38
38
|
cWo1UGp3RgotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
|
39
|
-
date: 2012-09-
|
39
|
+
date: 2012-09-22 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: configurability
|
@@ -427,6 +427,7 @@ files:
|
|
427
427
|
- lib/strelka/session.rb
|
428
428
|
- lib/strelka/session/db.rb
|
429
429
|
- lib/strelka/session/default.rb
|
430
|
+
- lib/strelka/testing.rb
|
430
431
|
- spec/data/error.tmpl
|
431
432
|
- spec/data/forms/2_images.form
|
432
433
|
- spec/data/forms/singleupload.form
|
metadata.gz.sig
CHANGED
Binary file
|