From c06fbcfc935daddb1eb26827466986f2b68c52f9 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Thu, 2 Jan 2014 17:25:31 -0800 Subject: [PATCH] rely directly on rack-mock --- middleman-cli/lib/middleman-cli/build.rb | 5 ++-- .../middleman-core/core_extensions/request.rb | 2 +- .../step_definitions/server_steps.rb | 24 +++++++++++-------- .../middleman-more/extensions/asset_hash.rb | 6 ++--- middleman-core/middleman-core.gemspec | 3 --- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/middleman-cli/lib/middleman-cli/build.rb b/middleman-cli/lib/middleman-cli/build.rb index c4d20923..635d750d 100644 --- a/middleman-cli/lib/middleman-cli/build.rb +++ b/middleman-cli/lib/middleman-cli/build.rb @@ -50,9 +50,8 @@ module Middleman::Cli raise Thor::Error, 'Error: Could not find a Middleman project config, perhaps you are in the wrong folder?' end - # Use Rack::Test for inspecting a running server for output require 'rack' - require 'rack/test' + require 'rack/mock' require 'find' @@ -115,7 +114,7 @@ module Middleman::Cli @to_clean = Set.new @logger = @app.logger - @rack = ::Rack::Test::Session.new(@app.class.to_rack_app) + @rack = ::Rack::MockRequest.new(@app.class.to_rack_app) super(base, @build_dir, config) end diff --git a/middleman-core/lib/middleman-core/core_extensions/request.rb b/middleman-core/lib/middleman-core/core_extensions/request.rb index 352dc557..1ef8b3a6 100644 --- a/middleman-core/lib/middleman-core/core_extensions/request.rb +++ b/middleman-core/lib/middleman-core/core_extensions/request.rb @@ -221,7 +221,7 @@ module Middleman run_hook :before # Get the resource object for this path - resource = sitemap.find_resource_by_destination_path(request_path) + resource = sitemap.find_resource_by_destination_path(request_path.gsub(' ', '%20')) # Return 404 if not in sitemap return not_found(res, request_path) unless resource && !resource.ignored? diff --git a/middleman-core/lib/middleman-core/step_definitions/server_steps.rb b/middleman-core/lib/middleman-core/step_definitions/server_steps.rb index 7f51de6e..9e7ccc5d 100644 --- a/middleman-core/lib/middleman-core/step_definitions/server_steps.rb +++ b/middleman-core/lib/middleman-core/step_definitions/server_steps.rb @@ -1,6 +1,6 @@ # encoding: UTF-8 -require 'rack/test' +require 'rack/mock' Given /^a clean server$/ do @initialize_commands = [] @@ -57,7 +57,7 @@ Given /^the Server is running$/ do end app_rack = @server_inst.class.to_rack_app - @browser = ::Rack::Test::Session.new(::Rack::MockSession.new(app_rack)) + @browser = ::Rack::MockRequest.new(app_rack) end Given /^the Server is running at "([^\"]*)"$/ do |app_path| @@ -66,33 +66,37 @@ Given /^the Server is running at "([^\"]*)"$/ do |app_path| end When /^I go to "([^\"]*)"$/ do |url| - @browser.get(URI.escape(url)) + @last_response = @browser.get(URI.escape(url)) end Then /^going to "([^\"]*)" should not raise an exception$/ do |url| - lambda { @browser.get(URI.escape(url)) }.should_not raise_exception + last_response = nil + lambda { + last_response = @browser.get(URI.escape(url)) + }.should_not raise_exception + @last_response = last_response end Then /^the content type should be "([^\"]*)"$/ do |expected| - @browser.last_response.content_type.should start_with(expected) + @last_response.content_type.should start_with(expected) end Then /^I should see "([^\"]*)"$/ do |expected| - @browser.last_response.body.should include(expected) + @last_response.body.should include(expected) end Then /^I should see '([^\']*)'$/ do |expected| - @browser.last_response.body.should include(expected) + @last_response.body.should include(expected) end Then /^I should see:$/ do |expected| - @browser.last_response.body.should include(expected) + @last_response.body.should include(expected) end Then /^I should not see "([^\"]*)"$/ do |expected| - @browser.last_response.body.should_not include(expected) + @last_response.body.should_not include(expected) end Then /^I should see "([^\"]*)" lines$/ do |lines| - @browser.last_response.body.chomp.split($/).length.should == lines.to_i + @last_response.body.chomp.split($/).length.should == lines.to_i end diff --git a/middleman-core/lib/middleman-more/extensions/asset_hash.rb b/middleman-core/lib/middleman-more/extensions/asset_hash.rb index c417446a..0934dbaa 100644 --- a/middleman-core/lib/middleman-more/extensions/asset_hash.rb +++ b/middleman-core/lib/middleman-more/extensions/asset_hash.rb @@ -8,7 +8,7 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension super require 'digest/sha1' - require 'rack/test' + require 'rack/mock' require 'uri' end @@ -22,7 +22,7 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension # Update the main sitemap resource list # @return [void] def manipulate_resource_list(resources) - @rack_client ||= ::Rack::Test::Session.new(app.class.to_rack_app) + @rack_client = ::Rack::MockRequest.new(app.class.to_rack_app) # Process resources in order: binary images and fonts, then SVG, then JS/CSS. # This is so by the time we get around to the text files (which may reference @@ -43,7 +43,7 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension return if ignored_resource?(resource) # Render through the Rack interface so middleware and mounted apps get a shot - response = @rack_client.get(URI.escape(resource.destination_path), {}, { 'bypass_asset_hash' => 'true' }) + response = @rack_client.get(URI.escape(resource.destination_path), { 'bypass_asset_hash' => 'true' }) raise "#{resource.path} should be in the sitemap!" unless response.status == 200 digest = Digest::SHA1.hexdigest(response.body)[0..7] diff --git a/middleman-core/middleman-core.gemspec b/middleman-core/middleman-core.gemspec index 91a214df..30f59c00 100644 --- a/middleman-core/middleman-core.gemspec +++ b/middleman-core/middleman-core.gemspec @@ -22,9 +22,6 @@ Gem::Specification.new do |s| s.add_dependency("rack", [">= 1.4.5"]) s.add_dependency("tilt", ["~> 1.4.1"]) - # Builder - s.add_dependency("rack-test", ["~> 0.6.2"]) - # Helpers s.add_dependency("activesupport", ["~> 4.0.1"])