module Angelo::Minitest::Helpers
Constants
- HTTP_URL
Attributes
last_response[R]
Public Instance Methods
define_app(app = nil, &block)
click to toggle source
# 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 # reset class_eval &block end end Celluloid.logger.level = ::Logger::ERROR # see spec_helper.rb:9 @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 = {})
click to toggle source
# File lib/angelo/minitest/helpers.rb, line 74 def get_sse path, params = {}, headers = {}, &block @last_response = hc.get url(path), params, headers, &block end
hc()
click to toggle source
# File lib/angelo/minitest/helpers.rb, line 33 def hc @hc ||= HTTPClient.new end
last_response_must_be_html(body = '')
click to toggle source
# 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.headers['Content-Type'].split(';').must_include HTML_TYPE end
last_response_must_be_json(obj = {})
click to toggle source
# 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.headers['Content-Type'].split(';').must_include JSON_TYPE end
url(path = nil)
click to toggle source
# File lib/angelo/minitest/helpers.rb, line 37 def url path = nil url = HTTP_URL % [DEFAULT_ADDR, DEFAULT_PORT] url += path if path url end
websocket_helper(path, params = {}) { |wsh| ... }
click to toggle source
# 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
Private Instance Methods
hc_req(method, path, params = {})
click to toggle source
# File lib/angelo/minitest/helpers.rb, line 43 def hc_req method, path, params = {}, headers = {}, &block @last_response = hc.__send__ method, url(path), params, headers, &block end
http_req(method, path, params = {})
click to toggle source
# File lib/angelo/minitest/helpers.rb, line 48 def http_req method, path, params = {}, headers = {} params = case params when String; {body: params} when Hash case method when :get, :delete, :options {params: params} else {form: params} end end @last_response = case when !headers.empty? ::HTTP.with(headers).__send__ method, url(path), params else ::HTTP.__send__ method, url(path), params end end