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

125 lines
3.1 KiB
Ruby
Raw Normal View History

2015-09-19 23:07:42 +02:00
require 'middleman-core/rack'
require 'rspec/expectations'
require 'capybara/cucumber'
2011-09-20 19:21:38 +02:00
Given /^a clean server$/ do
@initialize_commands = []
2016-01-14 02:16:36 +01:00
@activation_commands = []
2011-09-20 19:21:38 +02:00
end
2009-11-23 00:37:11 +01:00
Given /^"([^\"]*)" feature is "([^\"]*)"$/ do |feature, state|
2016-01-14 02:16:36 +01:00
@activation_commands ||= []
if state == 'enabled'
2016-01-14 02:16:36 +01:00
@activation_commands << lambda { activate(feature.to_sym) }
end
end
Given /^"([^\"]*)" feature is "enabled" with "([^\"]*)"$/ do |feature, options_str|
2016-01-14 02:16:36 +01:00
@activation_commands ||= []
options = eval("{#{options_str}}")
2016-01-14 02:16:36 +01:00
@activation_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
2015-08-11 01:58:32 +02:00
root_dir = File.expand_path(expand_path("."))
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 || []
2016-01-14 02:16:36 +01:00
activation_commands = @activation_commands || []
2015-09-20 01:00:38 +02:00
@server_inst = ::Middleman::Application.new do
config[:watcher_disable] = true
config[:show_exceptions] = false
initialize_commands.each do |p|
instance_exec(&p)
end
2016-01-14 02:16:36 +01:00
app.after_configuration_eval do
activation_commands.each do |p|
config_context.instance_exec(&p)
end
end
2015-09-20 01:00:38 +02:00
end
2015-09-20 01:00:38 +02:00
Capybara.app = ::Middleman::Rack.new(@server_inst).to_app
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
Given /^a template named "([^\"]*)" with:$/ do |name, string|
step %Q{a file named "source/#{name}" with:}, string
end
2009-11-23 00:37:11 +01:00
When /^I go to "([^\"]*)"$/ do |url|
2015-09-20 01:00:38 +02:00
visit(URI.encode(url).to_s)
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|
2015-09-20 01:00:38 +02:00
expect{ visit(URI.encode(url).to_s) }.to_not raise_exception
2011-12-01 17:43:26 +01:00
end
Then /^the content type should be "([^\"]*)"$/ do |expected|
2015-09-20 01:00:38 +02:00
expect(page.response_headers['Content-Type']).to start_with expected
end
2016-01-05 15:10:49 +01:00
Then /^the "([^\"]*)" header should contain "([^\"]*)"$/ do |header, expected|
expect(page.response_headers[header]).to include expected
end
2009-11-23 00:37:11 +01:00
Then /^I should see "([^\"]*)"$/ do |expected|
2015-09-20 01:00:38 +02:00
expect(page.body).to 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|
2015-09-20 01:00:38 +02:00
expect(page.body).to include expected
end
2009-11-23 00:37:11 +01:00
Then /^I should see:$/ do |expected|
2015-09-20 01:00:38 +02:00
expect(page.body).to include expected
end
2009-11-23 00:37:11 +01:00
Then /^I should not see "([^\"]*)"$/ do |expected|
2015-09-20 01:00:38 +02:00
expect(page.body).not_to include expected
2009-11-23 00:37:11 +01:00
end
Then /^I should see content matching %r{(.*)}$/ do |expected|
2015-09-20 01:00:38 +02:00
expect(page.body).to match(expected)
end
Then /^I should not see content matching %r{(.*)}$/ do |expected|
2015-09-20 01:00:38 +02:00
expect(page.body).to_not match(expected)
end
2014-07-29 09:03:56 +02:00
Then /^I should not see:$/ do |expected|
2015-09-20 01:00:38 +02:00
expect(page.body).not_to include expected
2014-07-29 09:03:56 +02:00
end
2014-07-29 09:04:10 +02:00
Then /^the status code should be "([^\"]*)"$/ do |expected|
2015-09-20 01:00:38 +02:00
expect(page.status_code).to eq expected.to_i
2014-07-29 09:04:10 +02:00
end
2009-11-23 00:37:11 +01:00
Then /^I should see "([^\"]*)" lines$/ do |lines|
2015-09-20 01:00:38 +02:00
expect(page.body.chomp.split($/).length).to eq lines.to_i
end