httpspec_simple 0.0.1 → 0.1.0
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 449b2744628e5346a0b00d4b2821594d6c7a2fa0
|
4
|
+
data.tar.gz: fe55183fdaf2626edd5f143ec3aa4697597cb580
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 616d09c544780c39a702af97489cbf44514bec61129557a7726903b53668cfd9458e4589154320454a61a8570b8c0d646571e097135266a0439d06b259b99ea1
|
7
|
+
data.tar.gz: bef28e58f66faed2c1b4deb216393ccfe9753cb0a305ba510180dc4990d3de0121c592e1ed08e9dfca5af19029352f8769065d53b2d37a84cad74362de8200b0
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ describe request('/blog/archives/') do
|
|
20
20
|
end
|
21
21
|
```
|
22
22
|
|
23
|
-
## Custom
|
23
|
+
## Custom matchers
|
24
24
|
|
25
25
|
### be_http_ok
|
26
26
|
|
@@ -30,6 +30,16 @@ Example passes if response is 200 ok
|
|
30
30
|
|
31
31
|
Example passes if response time is less than n seconds
|
32
32
|
|
33
|
+
## helper method
|
34
|
+
|
35
|
+
### request(url)
|
36
|
+
|
37
|
+
Do request
|
38
|
+
|
39
|
+
### base_url(prepend_string)
|
40
|
+
|
41
|
+
Prepend to the url string passed to following `request` method
|
42
|
+
|
33
43
|
## Contributing
|
34
44
|
|
35
45
|
1. Fork it
|
@@ -30,4 +30,36 @@ module HttpspecSimple
|
|
30
30
|
"respond within #{expected} seconds"
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
34
|
+
RSpec::Matchers.define :retrieve_body_including do |expected|
|
35
|
+
match do |actual|
|
36
|
+
actual.body.include?(expected)
|
37
|
+
end
|
38
|
+
|
39
|
+
failure_message_for_should do |actual|
|
40
|
+
"expected the body to include \"#{expected}\""
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
RSpec::Matchers.define :retrieve_body_matching do |expected|
|
45
|
+
match do |actual|
|
46
|
+
matchdata = actual.body.match(expected)
|
47
|
+
@captures = matchdata.captures if matchdata
|
48
|
+
!matchdata.nil?
|
49
|
+
end
|
50
|
+
|
51
|
+
failure_message_for_should do |actual|
|
52
|
+
"expected the body to match \"#{expected}\""
|
53
|
+
end
|
54
|
+
|
55
|
+
define_method :description do
|
56
|
+
if @captures
|
57
|
+
messages = []
|
58
|
+
@captures.each_with_index {|capture, index| messages.push("#{index} => \"#{capture}\"")}
|
59
|
+
"retrieve body matching /#{expected}/ {#{messages.join(" ")}}"
|
60
|
+
else
|
61
|
+
"retrieve body matching /#{expected}/"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
33
65
|
end
|
@@ -3,7 +3,7 @@ require 'uri'
|
|
3
3
|
|
4
4
|
module HttpspecSimple
|
5
5
|
class Request
|
6
|
-
attr_reader :response_time, :status
|
6
|
+
attr_reader :response_time, :status, :body
|
7
7
|
|
8
8
|
def initialize(url, opt = {})
|
9
9
|
@url = URI.parse(url)
|
@@ -13,8 +13,8 @@ module HttpspecSimple
|
|
13
13
|
http.open_timeout = opt[:timeout]
|
14
14
|
end
|
15
15
|
retry_count = opt[:retry].to_i
|
16
|
-
|
17
|
-
|
16
|
+
res, @response_time = http.start do |http|
|
17
|
+
process_time do
|
18
18
|
open_timeout_error = if Net.const_defined?(:OpenTimeout) then Net::OpenTimeout else Timeout::Error end
|
19
19
|
read_timeout_error = if Net.const_defined?(:ReadTimeout) then Net::ReadTimeout else Timeout::Error end
|
20
20
|
begin
|
@@ -25,11 +25,12 @@ module HttpspecSimple
|
|
25
25
|
end
|
26
26
|
res
|
27
27
|
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
end
|
29
|
+
@status = res ? res.code : 'timeout'
|
30
|
+
unless res.nil?
|
31
|
+
@body = res.body
|
32
|
+
charset = (res['content-type'] || '').split(';').select{|i| i.start_with?('charset=')}.map{|i| i.sub('charset=', '')}[0]
|
33
|
+
@body.force_encoding(charset) unless charset.nil?
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
@@ -22,4 +22,22 @@ describe 'custom matchers' do
|
|
22
22
|
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
|
23
23
|
end
|
24
24
|
end
|
25
|
+
|
26
|
+
describe '#retrieve_body_including(string)' do
|
27
|
+
it "should check response body" do
|
28
|
+
requests, response = server_start('/' => Proc.new {|req, res| res.body = "<div>body string</div>" }) do
|
29
|
+
request('/')
|
30
|
+
end
|
31
|
+
response.should retrieve_body_including 'dy st'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#retrieve_body_matching(regexp)' do
|
36
|
+
it "should check response body" do
|
37
|
+
requests, response = server_start('/' => Proc.new {|req, res| res.body = "<div>body string</div>" }) do
|
38
|
+
request('/')
|
39
|
+
end
|
40
|
+
response.should retrieve_body_matching %r|<div>(.+?)</div>|
|
41
|
+
end
|
42
|
+
end
|
25
43
|
end
|
@@ -50,4 +50,11 @@ describe HttpspecSimple::Request do
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
53
|
+
|
54
|
+
it "should store the response body" do
|
55
|
+
requests, response = server_start( '/' => Proc.new {|req, res| res.body = "body_string" } ) do
|
56
|
+
HttpspecSimple::Request.new('http://localhost:10080/')
|
57
|
+
end
|
58
|
+
response.body.should == "body_string"
|
59
|
+
end
|
53
60
|
end
|