shakedown 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/shakedown.rb +1 -1
- data/lib/shakedown/runner.rb +4 -4
- data/lib/shakedown/sequence.rb +103 -6
- data/lib/shakedown/version.rb +1 -1
- data/shakedown.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6df497238568876a2b7b9cfe578d2b71e9e92240
|
4
|
+
data.tar.gz: 8c2cd6b461dcd8a00f7bd777d017518d823fc6fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc7673e132a8582292797bfe0087f627a890281d71a4b93d517fd9993ba99ea55f3d2f8a013cb5f3c67f1e6b4cbfc0747112b21d021a67490355e7598332b3a2
|
7
|
+
data.tar.gz: 2a720b8f9bad95fd15ac997a6dd071027cc7fdda3104a562a1684da90d561e32b54b07f2a86c8ea461d55131e8783669e897bf0e7deabf92b290602a4021e983
|
data/lib/shakedown.rb
CHANGED
data/lib/shakedown/runner.rb
CHANGED
@@ -30,13 +30,13 @@ module Shakedown
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def print_status(status, update=false)
|
33
|
-
message = "
|
33
|
+
message = " #{SYMBOLS[status]} #{type.to_s.upcase.ljust(7)} #{url}".send(COLORS[status])
|
34
34
|
|
35
35
|
if update
|
36
|
-
|
37
|
-
puts
|
36
|
+
puts message
|
38
37
|
else
|
39
|
-
|
38
|
+
print message + "\r"
|
39
|
+
$stdout.flush
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
data/lib/shakedown/sequence.rb
CHANGED
@@ -19,16 +19,113 @@ module Shakedown
|
|
19
19
|
[base_url, url].join
|
20
20
|
end
|
21
21
|
|
22
|
-
def get(url, params={}, &
|
23
|
-
|
22
|
+
def get(url, params={}, &assertion)
|
23
|
+
request = Request.new(:get, url_for(url), params)
|
24
|
+
assert(request, assertion)
|
24
25
|
end
|
25
26
|
|
26
|
-
def post(url, params={}, &
|
27
|
-
|
27
|
+
def post(url, params={}, &assertion)
|
28
|
+
request = Request.new(:post, url_for(url), params)
|
29
|
+
assert(request, assertion)
|
28
30
|
end
|
29
31
|
|
30
|
-
def delete(url, params={}, &
|
31
|
-
|
32
|
+
def delete(url, params={}, &assertion)
|
33
|
+
request = Request.new(:delete, url_for(url), params)
|
34
|
+
assert(request, assertion)
|
35
|
+
end
|
36
|
+
|
37
|
+
def assert(request, callable)
|
38
|
+
assertion = Assertion.new(callable)
|
39
|
+
|
40
|
+
if assertion.status != request.status
|
41
|
+
puts " ✖ #{request.type.to_s.upcase.ljust(7)} #{request.url}".red
|
42
|
+
puts
|
43
|
+
puts "Expected: #{assertion.status}"
|
44
|
+
puts " Actual: #{request.status}"
|
45
|
+
puts
|
46
|
+
exit
|
47
|
+
end
|
48
|
+
|
49
|
+
if assertion.body != request.body
|
50
|
+
puts " ✖ #{request.type.to_s.upcase.ljust(7)} #{request.url}".red
|
51
|
+
puts
|
52
|
+
puts "Expected: #{assertion.body}"
|
53
|
+
puts " Actual: #{request.body}"
|
54
|
+
puts
|
55
|
+
exit
|
56
|
+
end
|
57
|
+
|
58
|
+
puts " ✔ #{request.type.to_s.upcase.ljust(7)} #{request.url}".green
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class Assertion
|
63
|
+
class Null
|
64
|
+
def self.==(other)
|
65
|
+
true
|
66
|
+
end
|
67
|
+
def self.!=(other)
|
68
|
+
false
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
attr_reader :status, :body
|
73
|
+
|
74
|
+
def initialize(callable)
|
75
|
+
@status = Null
|
76
|
+
@body = Null
|
77
|
+
unless callable.nil?
|
78
|
+
@body = JSON.parse(instance_eval(&callable).to_json)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def status(code=nil)
|
83
|
+
@status = code unless code.nil?
|
84
|
+
@status
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
class Request
|
89
|
+
attr_reader :type, :url, :params
|
90
|
+
|
91
|
+
def initialize(type, url, params={})
|
92
|
+
@type = type
|
93
|
+
@url = url
|
94
|
+
@params = params
|
95
|
+
end
|
96
|
+
|
97
|
+
def body
|
98
|
+
@body ||= JSON.parse(response.body)
|
99
|
+
end
|
100
|
+
|
101
|
+
def status
|
102
|
+
@status ||= response.code.to_i
|
103
|
+
end
|
104
|
+
|
105
|
+
def uri
|
106
|
+
URI.parse(url)
|
107
|
+
end
|
108
|
+
|
109
|
+
def http
|
110
|
+
Net::HTTP.new(uri.host, uri.port)
|
111
|
+
end
|
112
|
+
|
113
|
+
def response
|
114
|
+
@response ||= http.request(request)
|
115
|
+
end
|
116
|
+
|
117
|
+
def request
|
118
|
+
case type
|
119
|
+
when :get
|
120
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
121
|
+
when :post
|
122
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
123
|
+
when :delete
|
124
|
+
request = Net::HTTP::Delete.new(uri.request_uri)
|
125
|
+
end
|
126
|
+
|
127
|
+
request.set_form_data(params)
|
128
|
+
request
|
32
129
|
end
|
33
130
|
end
|
34
131
|
end
|
data/lib/shakedown/version.rb
CHANGED
data/shakedown.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shakedown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Casey O'Hara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -39,19 +39,19 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: colored
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '1.2'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '1.2'
|
55
55
|
description: ''
|
56
56
|
email:
|
57
57
|
- casey@camber.io
|