lib/rack/app/test.rb in rack-app-2.3.1 vs lib/rack/app/test.rb in rack-app-3.0.0.alpha
- old
+ new
@@ -1,57 +1,27 @@
require 'uri'
require 'rack/app'
module Rack::App::Test
require 'rack/app/test/utils'
+ require 'rack/app/test/singleton_methods'
def self.included(klass)
- klass.__send__(:extend,SpecHelpers)
+ klass.__send__(:extend, self::SingletonMethods)
end
- module SpecHelpers
+ attr_reader :last_response
- def rack_app(*args,&constructor)
-
- begin
- let(:rack_app){ rack_app_by(*args,&constructor) }
- rescue NoMethodError
- define_method(:rack_app) do
- rack_app_by(*args,&constructor)
- end
- end
-
- end
-
- end
-
- def rack_app_by(*args,&constructor)
- subject_app = nil
- rack_app_class = args.shift
-
- if constructor.nil?
- subject_app = rack_app_class
- else
- subject_app = Class.new(rack_app_class || Rack::App)
- subject_app.class_eval(&constructor)
- end
-
- subject_app
- end
-
[:get, :post, :put, :delete, :options, :patch].each do |request_method|
- define_method(request_method) do |properties|
- properties ||= Hash.new
- url = properties.delete(:url)
- request_env = Rack::App::Test::Utils.request_env_by(request_method, url, properties)
- raw_response = rack_app.call(request_env)
+ define_method(request_method) do |*args|
- body = []
- raw_response[2].each do |e|
- body << e
- end
+ properties = args.select { |e| e.is_a?(Hash) }.reduce({}, &:merge!)
+ url = args.select { |e| e.is_a?(String) }.first || properties.delete(:url)
+ request = Rack::MockRequest.new(rack_app)
+ env = Rack::App::Test::Utils.env_by(properties)
- return Rack::Response.new(body,raw_response[0],raw_response[1])
+ return @last_response = request.__send__(request_method, url, env)
+
end
end
end
\ No newline at end of file