middleman/middleman-core/lib/middleman-core/step_definitions/server_steps.rb
Ben Hollis 7a4aa109a6 Overhaul content-type handling, making it configurable via page/proxy commands as well as frontmatter with the 'content_type' parameter.
Now, users can set content type explicitly for their files in a number of ways, or rely on automatic file-extension content types. Proxied files default to automatic file-extension content types, but then fall back to the content type of the resource they proxy to. There is also a bug fixed around correctly setting content type inside send_file. Fixes #821.
2013-04-06 15:11:25 -07:00

97 lines
2.4 KiB
Ruby

# encoding: UTF-8
require "rack/test"
Given /^a clean server$/ do
@initialize_commands = []
end
Given /^"([^\"]*)" feature is "([^\"]*)"$/ do |feature, state|
@initialize_commands ||= []
if state == "enabled"
@initialize_commands << lambda { activate(feature.to_sym) }
end
end
Given /^"([^\"]*)" feature is "enabled" with "([^\"]*)"$/ do |feature, options_str|
@initialize_commands ||= []
options = eval("{#{options_str}}")
@initialize_commands << lambda { activate(feature.to_sym, options) }
end
Given /^"([^\"]*)" is set to "([^\"]*)"$/ do |variable, value|
@initialize_commands ||= []
@initialize_commands << lambda { set(variable.to_sym, value) }
end
Given /^current environment is "([^\"]*)"$/ do |env|
@current_env = env.to_sym
end
Given /^the Server is running$/ do
root_dir = File.expand_path(current_dir)
if File.exists?(File.join(root_dir, "source"))
ENV["MM_SOURCE"] = "source"
else
ENV["MM_SOURCE"] = ""
end
ENV["MM_ROOT"] = root_dir
initialize_commands = @initialize_commands || []
initialize_commands.unshift lambda {
set :environment, @current_env || :development
set :show_exceptions, false
}
@server_inst = Middleman::Application.server.inst do
initialize_commands.each do |p|
instance_exec(&p)
end
end
app_rack = @server_inst.class.to_rack_app
@browser = ::Rack::Test::Session.new(::Rack::MockSession.new(app_rack))
end
Given /^the Server is running at "([^\"]*)"$/ do |app_path|
step %Q{a fixture app "#{app_path}"}
step %Q{the Server is running}
end
When /^I go to "([^\"]*)"$/ do |url|
@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
end
Then /^the content type should be "([^\"]*)"$/ do |expected|
@browser.last_response.content_type.should start_with(expected)
end
Then /^I should see "([^\"]*)"$/ do |expected|
@browser.last_response.body.should include(expected)
end
Then /^I should see '([^\']*)'$/ do |expected|
@browser.last_response.body.should include(expected)
end
Then /^I should see:$/ do |expected|
@browser.last_response.body.should include(expected)
end
Then /^I should not see "([^\"]*)"$/ do |expected|
@browser.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
end