lib/rack/app/test.rb in rack-app-5.10.0 vs lib/rack/app/test.rb in rack-app-5.10.1

- old
+ new

@@ -10,20 +10,21 @@ klass.__send__(:extend, self::SingletonMethods) end attr_reader :last_response - Rack::App::Constants::HTTP::METHODS.each do |request_method_type| - request_method = request_method_type.to_s.downcase - define_method(request_method) do |*args| + def __send_rack_app_request__(request_method, *args) + properties = args.select { |e| e.is_a?(Hash) }.reduce({}, &:merge!) + url = args.select { |e| e.is_a?(String) }.first || properties.delete(:url) + mock_request = Rack::MockRequest.new(rack_app) + request_env = Rack::App::Test::Utils.env_by(properties) + return @last_response = mock_request.request(request_method.to_s.upcase, url, request_env) + end - properties = args.select { |e| e.is_a?(Hash) }.reduce({}, &:merge!) - url = args.select { |e| e.is_a?(String) }.first || properties.delete(:url) - mock_request = Rack::MockRequest.new(rack_app) - request_env = Rack::App::Test::Utils.env_by(properties) - return @last_response = mock_request.request(request_method, url, request_env) - + Rack::App::Constants::HTTP::METHODS.each do |request_method_type| + define_method(request_method_type.to_s.downcase) do |*args| + self.__send_rack_app_request__(request_method_type, *args) end end def rack_app(&block) @rack_app ||= lambda do @@ -32,10 +33,10 @@ elsif defined?(described_class) && described_class.respond_to?(:call) described_class else raise('missing class definition') end - end.call + end.call block.is_a?(Proc) ? @rack_app.instance_exec(&block) : @rack_app end end