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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ebfcbbf3ca9f9b6189b8cc74fd49dba588a64326
4
- data.tar.gz: e6d6cf59453bf5b279f18f7fae8b019f3be992de
3
+ metadata.gz: 6df497238568876a2b7b9cfe578d2b71e9e92240
4
+ data.tar.gz: 8c2cd6b461dcd8a00f7bd777d017518d823fc6fb
5
5
  SHA512:
6
- metadata.gz: f8b8ec20c4e3a0621e1f4c3763b9037fcc0111077b90d29c25d451fda338d13a96b9075a54acf9ee1511d002ec25571a356c489a6fe587e71f33b8700298781d
7
- data.tar.gz: b912947cc9709b294e8f910cf8ce0547b1678a67f4f5f9ef74f8c162496ba5b488a6e3ea930556878e5e479eb4989aef363a044be07d5548ba91a5a97934cd45
6
+ metadata.gz: dc7673e132a8582292797bfe0087f627a890281d71a4b93d517fd9993ba99ea55f3d2f8a013cb5f3c67f1e6b4cbfc0747112b21d021a67490355e7598332b3a2
7
+ data.tar.gz: 2a720b8f9bad95fd15ac997a6dd071027cc7fdda3104a562a1684da90d561e32b54b07f2a86c8ea461d55131e8783669e897bf0e7deabf92b290602a4021e983
@@ -1,7 +1,7 @@
1
1
  require "net/http"
2
2
  require "uri"
3
3
  require "json"
4
- require "formatador"
4
+ require "colored"
5
5
 
6
6
  require_relative "./shakedown/version"
7
7
  require_relative "./shakedown/configuration"
@@ -30,13 +30,13 @@ module Shakedown
30
30
  end
31
31
 
32
32
  def print_status(status, update=false)
33
- message = "[#{COLORS[status]}]#{SYMBOLS[status]} #{type.to_s.upcase.ljust(8)} #{url}[/]"
33
+ message = " #{SYMBOLS[status]} #{type.to_s.upcase.ljust(7)} #{url}".send(COLORS[status])
34
34
 
35
35
  if update
36
- Formatador.redisplay(message)
37
- puts
36
+ puts message
38
37
  else
39
- Formatador.display(message)
38
+ print message + "\r"
39
+ $stdout.flush
40
40
  end
41
41
  end
42
42
 
@@ -19,16 +19,113 @@ module Shakedown
19
19
  [base_url, url].join
20
20
  end
21
21
 
22
- def get(url, params={}, &assertions)
23
- Runner.new(:get, url_for(url), params).run.assert(assertions)
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={}, &assertions)
27
- Runner.new(:post, url_for(url), params).run.assert(assertions)
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={}, &assertions)
31
- Runner.new(:delete, url_for(url), params).run.assert(assertions)
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
@@ -1,3 +1,3 @@
1
1
  module Shakedown
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -20,6 +20,6 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_dependency "formatador", "~> 0.2.5"
23
+ spec.add_dependency "colored", "~> 1.2"
24
24
  end
25
25
 
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.2
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-03-08 00:00:00.000000000 Z
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: formatador
42
+ name: colored
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.2.5
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: 0.2.5
54
+ version: '1.2'
55
55
  description: ''
56
56
  email:
57
57
  - casey@camber.io