Module: Angelo::Minitest::Helpers
- Defined in:
- lib/angelo/minitest/helpers.rb
Defined Under Namespace
Modules: Cellper
Classes: Actor, Reactor
Constant Summary
collapse
- HTTP_URL =
'http://%s:%d'
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#last_response ⇒ Object
Returns the value of attribute last_response.
10
11
12
|
# File 'lib/angelo/minitest/helpers.rb', line 10
def last_response
@last_response
end
|
Instance Method Details
#define_app(app = nil, &block) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/angelo/minitest/helpers.rb', line 12
def define_app app = nil, &block
before do
if app.nil? && block
app = Class.new Angelo::Base do
content_type :html class_eval &block
end
end
Celluloid.logger.level = ::Logger::ERROR
@server = Angelo::Server.new app
app.server = @server
$reactor = Reactor.new if $reactor == nil || !$reactor.alive?
end
after do
sleep 0.1
@server.terminate if @server and @server.alive?
end
end
|
#get_sse(path, params = {}, headers = {}, &block) ⇒ Object
74
75
76
|
# File 'lib/angelo/minitest/helpers.rb', line 74
def get_sse path, params = {}, = {}, &block
@last_response = hc.get url(path), params, , &block
end
|
#hc ⇒ Object
33
34
35
|
# File 'lib/angelo/minitest/helpers.rb', line 33
def hc
@hc ||= HTTPClient.new
end
|
#last_response_must_be_html(body = '') ⇒ Object
94
95
96
97
98
|
# File 'lib/angelo/minitest/helpers.rb', line 94
def last_response_must_be_html body = ''
last_response.status.must_equal 200
last_response.body.to_s.must_equal body
last_response.['Content-Type'].split(';').must_include HTML_TYPE
end
|
#last_response_must_be_json(obj = {}) ⇒ Object
100
101
102
103
104
|
# File 'lib/angelo/minitest/helpers.rb', line 100
def last_response_must_be_json obj = {}
last_response.status.must_equal 200
JSON.parse(last_response.body.to_s).must_equal obj
last_response.['Content-Type'].split(';').must_include JSON_TYPE
end
|
#url(path = nil) ⇒ Object
#websocket_helper(path, params = {}) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/angelo/minitest/helpers.rb', line 78
def websocket_helper path, params = {}
params = params.keys.reduce([]) {|a,k|
a << CGI.escape(k) + '=' + CGI.escape(params[k])
a
}.join('&')
path += "?#{params}" unless params.empty?
wsh = WebsocketHelper.new DEFAULT_ADDR, DEFAULT_PORT, path
if block_given?
yield wsh
wsh.close
else
return wsh
end
end
|