lib/angelo/minitest/helpers.rb in angelo-0.3.3 vs lib/angelo/minitest/helpers.rb in angelo-0.4.0

- old
+ new

@@ -7,29 +7,29 @@ HTTP_URL = 'http://%s:%d' attr_reader :last_response - def define_app &block - + def define_app app = nil, &block before do - app = Class.new Angelo::Base - - app.class_eval { content_type :html } # reset + 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 - app.class_eval &block @server = Angelo::Server.new app app.server = @server - $reactor = Reactor.new unless $reactor.alive? + $reactor = Reactor.new if $reactor == nil || !$reactor.alive? end after do sleep 0.1 @server.terminate if @server and @server.alive? end - end def hc @hc ||= HTTPClient.new end @@ -38,16 +38,12 @@ url = HTTP_URL % [DEFAULT_ADDR, DEFAULT_PORT] url += path if path url end - def hc_req method, path, params = {}, headers = {} - @last_response = if block_given? - hc.__send__ method, url(path), params, headers, &Proc.new - else - hc.__send__ method, url(path), params, headers - end + def hc_req method, path, params = {}, headers = {}, &block + @last_response = hc.__send__ method, url(path), params, headers, &block end private :hc_req def http_req method, path, params = {}, headers = {} params = case params @@ -68,19 +64,12 @@ end end private :http_req [:get, :post, :put, :delete, :options, :head].each do |m| - define_method m do |path, params = {}, headers = {}| - - # http_req m, path, params, headers - - if block_given? - hc_req m, path, params, headers, &Proc.new - else - hc_req m, path, params, headers - end + define_method m do |path, params = {}, headers = {}, &block| + hc_req m, path, params, headers, &block end end def get_sse path, params = {}, headers = {}, &block @last_response = hc.get url(path), params, headers, &block @@ -112,10 +101,48 @@ 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 + module Cellper + + @@stop = false + @@testers = {} + + def define_action sym, &block + define_method sym, &block + end + + def remove_action sym + remove_method sym + end + + def unstop! + @@stop = false + end + + def stop! + @@stop = true + end + + def stop? + @@stop + end + + def testers; @@testers; end + end + + class Reactor + include Celluloid::IO + extend Cellper + end + + class ActorPool + include Celluloid + extend Cellper + end + end class WebsocketHelper include Celluloid::Logger @@ -171,6 +198,7 @@ end end end + end