middleman/middleman-core/lib/middleman-core/step_definitions/server_steps.rb

105 lines
2.5 KiB
Ruby
Raw Normal View History

# encoding: UTF-8
2014-01-03 02:25:31 +01:00
require 'rack/mock'
2011-09-20 19:21:38 +02:00
Given /^a clean server$/ do
@initialize_commands = []
2011-09-20 19:21:38 +02:00
end
2009-11-23 00:37:11 +01:00
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 ||= []
2014-01-01 03:21:30 +01:00
@initialize_commands << lambda {
2014-04-29 20:43:05 +02:00
config[variable.to_sym] = value
2014-01-01 03:21:30 +01:00
}
2009-11-23 00:37:11 +01:00
end
2012-03-29 19:22:43 +02:00
Given /^the Server is running$/ do
2011-12-31 22:44:50 +01:00
root_dir = File.expand_path(current_dir)
2011-12-29 00:29:19 +01:00
if File.exists?(File.join(root_dir, 'source'))
ENV['MM_SOURCE'] = 'source'
2011-12-29 00:29:19 +01:00
else
ENV['MM_SOURCE'] = ''
2011-12-29 00:29:19 +01:00
end
ENV['MM_ROOT'] = root_dir
initialize_commands = @initialize_commands || []
@server_inst = Middleman::Application.server.inst do
2014-06-07 00:32:00 +02:00
app.initialized do
initialize_commands.each do |p|
config_context.instance_exec(&p)
end
end
end
app_rack = @server_inst.class.to_rack_app
2014-01-03 02:25:31 +01:00
@browser = ::Rack::MockRequest.new(app_rack)
2009-11-30 20:32:02 +01:00
end
2012-03-29 19:22:43 +02:00
Given /^the Server is running at "([^\"]*)"$/ do |app_path|
step %Q{a fixture app "#{app_path}"}
step %Q{the Server is running}
end
2009-11-23 00:37:11 +01:00
When /^I go to "([^\"]*)"$/ do |url|
2014-01-03 02:25:31 +01:00
@last_response = @browser.get(URI.escape(url))
2009-11-23 00:37:11 +01:00
end
2011-12-01 17:43:26 +01:00
Then /^going to "([^\"]*)" should not raise an exception$/ do |url|
2014-01-03 02:25:31 +01:00
last_response = nil
lambda {
last_response = @browser.get(URI.escape(url))
}.should_not raise_exception
@last_response = last_response
2011-12-01 17:43:26 +01:00
end
Then /^the content type should be "([^\"]*)"$/ do |expected|
2014-01-03 02:25:31 +01:00
@last_response.content_type.should start_with(expected)
end
2009-11-23 00:37:11 +01:00
Then /^I should see "([^\"]*)"$/ do |expected|
2014-01-03 02:25:31 +01:00
@last_response.body.should include(expected)
2009-11-23 00:37:11 +01:00
end
2011-04-25 22:45:54 +02:00
Then /^I should see '([^\']*)'$/ do |expected|
2014-01-03 02:25:31 +01:00
@last_response.body.should include(expected)
end
2009-11-23 00:37:11 +01:00
Then /^I should see:$/ do |expected|
2014-01-03 02:25:31 +01:00
@last_response.body.should include(expected)
end
2009-11-23 00:37:11 +01:00
Then /^I should not see "([^\"]*)"$/ do |expected|
2014-01-03 02:25:31 +01:00
@last_response.body.should_not include(expected)
2009-11-23 00:37:11 +01:00
end
Then /^I should see content matching %r{(.*)}$/ do |expected|
@last_response.body.should match(expected)
end
Then /^I should not see content matching %r{(.*)}$/ do |expected|
@last_response.body.should_not match(expected)
end
2009-11-23 00:37:11 +01:00
Then /^I should see "([^\"]*)" lines$/ do |lines|
2014-01-03 02:25:31 +01:00
@last_response.body.chomp.split($/).length.should == lines.to_i
end