Module: Angelo::Minitest::Helpers
- Defined in:
- lib/angelo/minitest/helpers.rb
Constant Summary collapse
- HTTP_URL =
'http://%s:%d'
Instance Attribute Summary collapse
-
#last_response ⇒ Object
readonly
Returns the value of attribute last_response.
Instance Method Summary collapse
- #define_app(&block) ⇒ Object
- #get_sse(path, params = {}, headers = {}, &block) ⇒ Object
- #hc ⇒ Object
- #last_response_must_be_html(body = '') ⇒ Object
- #last_response_must_be_json(obj = {}) ⇒ Object
- #url(path = nil) ⇒ Object
- #websocket_helper(path, params = {}) ⇒ Object
Instance Attribute Details
#last_response ⇒ Object (readonly)
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(&block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/angelo/minitest/helpers.rb', line 12 def define_app &block before do app = Class.new Angelo::Base app.class_eval { content_type :html } # reset app.class_eval &block @server = Angelo::Server.new app app.server = @server $reactor = Reactor.new unless $reactor.alive? end after do sleep 0.1 @server.terminate if @server and @server.alive? end end |
#get_sse(path, params = {}, headers = {}, &block) ⇒ Object
82 83 84 |
# File 'lib/angelo/minitest/helpers.rb', line 82 def get_sse path, params = {}, headers = {}, &block @last_response = hc.get url(path), params, headers, &block end |
#hc ⇒ Object
30 31 32 |
# File 'lib/angelo/minitest/helpers.rb', line 30 def hc @hc ||= HTTPClient.new end |
#last_response_must_be_html(body = '') ⇒ Object
102 103 104 105 106 |
# File 'lib/angelo/minitest/helpers.rb', line 102 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 = {}) ⇒ Object
108 109 110 111 112 |
# File 'lib/angelo/minitest/helpers.rb', line 108 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) ⇒ Object
34 35 36 37 38 |
# File 'lib/angelo/minitest/helpers.rb', line 34 def url path = nil url = HTTP_URL % [DEFAULT_ADDR, DEFAULT_PORT] url += path if path url end |
#websocket_helper(path, params = {}) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/angelo/minitest/helpers.rb', line 86 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 |