diff options
author | Gibheer <gibheer@gmail.com> | 2013-01-11 08:02:46 +0100 |
---|---|---|
committer | Gibheer <gibheer@gmail.com> | 2013-01-11 08:02:46 +0100 |
commit | 9e83d9d8b5d278d24660e57613fe97f51ffc2033 (patch) | |
tree | 9a2b6a2f06418f3812cd31daed9e2e1c1e6d362a /spec/spec_helper.rb | |
parent | d645a2eb499940d2d6c71b07c6d03c32171708d0 (diff) |
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?
Diffstat (limited to 'spec/spec_helper.rb')
-rw-r--r-- | spec/spec_helper.rb | 18 |
1 files changed, 18 insertions, 0 deletions
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' |