<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -4,37 +4,51 @@ module Sinatra
 
     module Methods
 
-      def easy_env_map
-        {
-          :accept =&gt; &quot;HTTP_ACCEPT&quot;,
-          :agent =&gt; &quot;HTTP_USER_AGENT&quot;,
-          :host =&gt; &quot;HTTP_HOST&quot;,
-          :session =&gt; &quot;HTTP_COOKIE&quot;,
-          :cookies =&gt; &quot;HTTP_COOKIE&quot;
-        }
-      end
+      ENV_KEY_NAMES = {
+        :accept =&gt; &quot;HTTP_ACCEPT&quot;,
+        :agent =&gt; &quot;HTTP_USER_AGENT&quot;,
+        :host =&gt; &quot;HTTP_HOST&quot;,
+        :session =&gt; &quot;HTTP_COOKIE&quot;,
+        :cookies =&gt; &quot;HTTP_COOKIE&quot;,
+        :content_type =&gt; &quot;CONTENT_TYPE&quot;
+      }
 
       def session(data, key = 'rack.session')
         data = data.from_params if data.respond_to?(:from_params)
         &quot;#{Rack::Utils.escape(key)}=#{[Marshal.dump(data)].pack(&quot;m*&quot;)}&quot;
       end
 
-      def map_easys(params)
-        easy_env_map.inject(params.dup) do |m, (from, to)|
-          m[to] = m.delete(from) if m.has_key?(from); m
+      def normalize_rack_environment(env)
+        env.inject({}) do |hash,(k,v)|
+          hash[ENV_KEY_NAMES[k] || k] = v
+          hash
         end
       end
 
-      %w(get head post put delete).each do |m|
-        define_method(&quot;#{m}_it&quot;) do |path, *args|
-          env, input = if args.size == 2
-            [args.last, args.first]
-          elsif args.size == 1
-            data = args.first
-            data.is_a?(Hash) ? [map_easys(data.delete(:env) || {}), data.to_params] : [nil, data]
-          end
+      %w(get head post put delete).each do |verb|
+        http_method = verb.upcase
+        define_method(&quot;#{verb}_it&quot;) do |path, *args|
           @request = Rack::MockRequest.new(Sinatra.build_application)
-          @response = @request.request(m.upcase, path, {:input =&gt; input}.merge(env || {}))
+          opts, input =
+            case args.size
+            when 2 # input, env
+              input, env = args
+              [env, input]
+            when 1 # params
+              if (data = args.first).kind_of?(Hash)
+                env = (data.delete(:env) || {})
+                [env, data.to_params]
+              else
+                [{}, data]
+              end
+            when 0
+              [{}, '']
+            else
+              raise ArgumentError, &quot;zero, one, or two arguments expected&quot;
+            end
+          opts = normalize_rack_environment(opts)
+          opts[:input] ||= input
+          @response = @request.request(http_method, path, opts)
         end
       end
 
@@ -43,7 +57,11 @@ module Sinatra
       end
 
       def method_missing(name, *args)
-        @response.send(name, *args) rescue super
+        if @response.respond_to?(name)
+          @response.send(name, *args)
+        else
+          super
+        end
       end
 
     end</diff>
      <filename>lib/sinatra/test/methods.rb</filename>
    </modified>
    <modified>
      <diff>@@ -129,7 +129,7 @@ context &quot;Sinatra&quot; do
     body.should.be.empty
   end
 
-  specify &quot;body sets content and ends event&quot; do
+  specify &quot;stop sets content and ends event&quot; do
 
     Sinatra::EventContext.any_instance.expects(:foo).never
 
@@ -236,25 +236,25 @@ context &quot;Sinatra&quot; do
   end
 
 
-  specify &quot;put'n with POST&quot; do
+  specify &quot;supports PUT&quot; do
     put '/' do
       'puted'
     end
-    post_it '/', :_method =&gt; 'PUT'
+    put_it '/'
     assert_equal 'puted', body
   end
 
-  specify &quot;put'n wth PUT&quot; do
+  specify &quot;rewrites POSTs with _method param to PUT&quot; do
     put '/' do
       'puted'
     end
-    put_it '/'
+    post_it '/', :_method =&gt; 'PUT'
     assert_equal 'puted', body
   end
 
   # Some Ajax libraries downcase the _method parameter value. Make
   # sure we can handle that.
-  specify &quot;put'n with POST and lowercase _method param&quot; do
+  specify &quot;rewrites POSTs with lowercase _method param to PUT&quot; do
     put '/' do
       'puted'
     end
@@ -263,7 +263,7 @@ context &quot;Sinatra&quot; do
   end
 
   # Ignore any _method parameters specified in GET requests or on the query string in POST requests.
-  specify &quot;not put'n with GET&quot; do
+  specify &quot;does not rewrite GETs with _method param to PUT&quot; do
     get '/' do
       'getted'
     end
@@ -272,7 +272,7 @@ context &quot;Sinatra&quot; do
     body.should.equal 'getted'
   end
 
-  specify &quot;_method query string parameter ignored on POST&quot; do
+  specify &quot;ignores _method query string parameter on non-POST requests&quot; do
     post '/' do
       'posted'
     end
@@ -284,4 +284,16 @@ context &quot;Sinatra&quot; do
     body.should.equal 'posted'
   end
 
+  specify &quot;does not read body if content type is not url encoded&quot; do
+    post '/foo.xml' do
+      request.env['CONTENT_TYPE'].should.be == 'application/xml'
+      request.content_type.should.be == 'application/xml'
+      request.body.read
+    end
+
+    post_it '/foo.xml', '&lt;foo&gt;&lt;/foo&gt;', :content_type =&gt; 'application/xml'
+    @response.should.be.ok
+    @response.body.should.be == '&lt;foo&gt;&lt;/foo&gt;'
+  end
+
 end</diff>
      <filename>test/app_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -216,6 +216,37 @@ context &quot;Events in an app&quot; do
     body.should.equal &quot;Look ma, a path with spaces!&quot;
   end
 
+  specify &quot;route based on host&quot; do
+
+    get '/' do
+      'asdf'
+    end
+
+    get_it '/'
+    assert ok?
+    assert_equal('asdf', body)
+
+    get '/foo', :host =&gt; 'foo.sinatrarb.com' do
+      'in foo!'
+    end
+
+    get '/foo', :host =&gt; 'bar.sinatrarb.com'  do
+      'in bar!'
+    end
+
+    get_it '/foo', {}, 'HTTP_HOST' =&gt; 'foo.sinatrarb.com'
+    assert ok?
+    assert_equal 'in foo!', body
+
+    get_it '/foo', {}, 'HTTP_HOST' =&gt; 'bar.sinatrarb.com'
+    assert ok?
+    assert_equal 'in bar!', body
+
+    get_it '/foo'
+    assert not_found?
+
+  end
+
 end
 
 </diff>
      <filename>test/application_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 require File.dirname(__FILE__) + '/helper'
 
-context &quot;Custom Errors (in general)&quot; do
+context &quot;Custom Errors&quot; do
 
   setup do
     Sinatra.application = nil</diff>
      <filename>test/custom_error_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 require File.dirname(__FILE__) + '/helper'
 
-context &quot;Templates (in general)&quot; do
+context &quot;Templates&quot; do
 
   specify &quot;are read from files if Symbols&quot; do
 </diff>
      <filename>test/template_test.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>test/diddy_test.rb</filename>
    </removed>
    <removed>
      <filename>test/rest_test.rb</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>491023a17b0d64261d113831ca11e2fe147ffcbe</id>
    </parent>
  </parents>
  <author>
    <name>Ryan Tomayko</name>
    <email>rtomayko@gmail.com</email>
  </author>
  <url>http://github.com/rtomayko/sinatra/commit/eef025c7f515f777fc780dec526f379dd7048648</url>
  <id>eef025c7f515f777fc780dec526f379dd7048648</id>
  <committed-date>2008-09-07T06:23:02-07:00</committed-date>
  <authored-date>2008-09-07T06:23:02-07:00</authored-date>
  <message>test refactoring and cleanup

Man. These tests kind of suck. Someone needs to organize
this shit semi-logically.</message>
  <tree>0f338ce58250d6aaed0bb4a3d1dcc34ab6e1915d</tree>
  <committer>
    <name>Ryan Tomayko</name>
    <email>rtomayko@gmail.com</email>
  </committer>
</commit>
