From 9e83d9d8b5d278d24660e57613fe97f51ffc2033 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Fri, 11 Jan 2013 08:02:46 +0100 Subject: [PATCH] easier environment generation This still needs some work, but it should definitly be easier to generate new environments now. Why is that even so much work? --- spec/spec_helper.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c5605ef..1b0dd61 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -33,6 +33,24 @@ class SpecApp end end +def environment(uri = '/foo', options = {}) + http_options = options + if options.has_key?(:method) + http_options['REQUEST_METHOD'] = options[:method].to_s.capitalize + end + if options.has_key?(:payload) + http_options[:input] = options[:payload]. + map {|key, value| "#{key}=#{value}"}. + join('&') + http_options['CONTENT_TYPE'] = 'multipart/form-data' + http_options['REQUEST_METHOD'] = 'POST' unless http_options['REQUEST_METHOD'] + end + http_options['zero.params.custom'] = options[:custom] if options.has_key?(:custom) + http_options.inspect + + Rack::MockRequest.env_for(uri, http_options) +end + class EnvGenerator KEY_REQUEST_METHOD = 'REQUEST_METHOD' KEY_REQUEST_GET = 'GET'