2012-04-02 05:52:22 +02:00
|
|
|
# encoding: UTF-8
|
|
|
|
|
2014-01-03 02:25:31 +01:00
|
|
|
require 'rack/mock'
|
2011-11-29 23:17:07 +01:00
|
|
|
|
2011-09-20 19:21:38 +02:00
|
|
|
Given /^a clean server$/ do
|
2011-11-18 22:38:18 +01:00
|
|
|
@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|
|
2011-11-18 22:38:18 +01:00
|
|
|
@initialize_commands ||= []
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2013-12-28 01:26:31 +01:00
|
|
|
if state == 'enabled'
|
2011-11-18 22:38:18 +01:00
|
|
|
@initialize_commands << lambda { activate(feature.to_sym) }
|
|
|
|
end
|
2011-07-24 07:49:32 +02:00
|
|
|
end
|
|
|
|
|
2012-04-26 08:41:09 +02:00
|
|
|
Given /^"([^\"]*)" feature is "enabled" with "([^\"]*)"$/ do |feature, options_str|
|
|
|
|
@initialize_commands ||= []
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2012-04-26 08:41:09 +02:00
|
|
|
options = eval("{#{options_str}}")
|
|
|
|
|
|
|
|
@initialize_commands << lambda { activate(feature.to_sym, options) }
|
|
|
|
end
|
|
|
|
|
2011-07-24 07:49:32 +02:00
|
|
|
Given /^"([^\"]*)" is set to "([^\"]*)"$/ do |variable, value|
|
2011-11-18 22:38:18 +01:00
|
|
|
@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
|
|
|
|
2013-12-28 01:26:31 +01:00
|
|
|
if File.exists?(File.join(root_dir, 'source'))
|
|
|
|
ENV['MM_SOURCE'] = 'source'
|
2011-12-29 00:29:19 +01:00
|
|
|
else
|
2013-12-28 01:26:31 +01:00
|
|
|
ENV['MM_SOURCE'] = ''
|
2011-12-29 00:29:19 +01:00
|
|
|
end
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2013-12-28 01:26:31 +01:00
|
|
|
ENV['MM_ROOT'] = root_dir
|
2012-10-14 07:37:24 +02:00
|
|
|
|
2011-11-18 22:38:18 +01:00
|
|
|
initialize_commands = @initialize_commands || []
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2012-05-17 06:19:03 +02:00
|
|
|
@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
|
2011-11-18 22:38:18 +01:00
|
|
|
end
|
|
|
|
end
|
2012-08-14 00:39:06 +02:00
|
|
|
|
2011-11-18 22:38:18 +01:00
|
|
|
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
|
|
|
|
|
2013-04-06 23:05:26 +02:00
|
|
|
Then /^the content type should be "([^\"]*)"$/ do |expected|
|
2014-01-03 02:25:31 +01:00
|
|
|
@last_response.content_type.should start_with(expected)
|
2013-04-06 23:05:26 +02:00
|
|
|
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
|
|
|
|
2010-09-06 19:59:51 +02:00
|
|
|
Then /^I should see '([^\']*)'$/ do |expected|
|
2014-01-03 02:25:31 +01:00
|
|
|
@last_response.body.should include(expected)
|
2010-09-06 19:59:51 +02:00
|
|
|
end
|
2009-11-23 00:37:11 +01:00
|
|
|
|
2012-04-08 05:00:24 +02:00
|
|
|
Then /^I should see:$/ do |expected|
|
2014-01-03 02:25:31 +01:00
|
|
|
@last_response.body.should include(expected)
|
2012-04-08 05:00:24 +02:00
|
|
|
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
|
|
|
|
|
2014-04-07 21:43:16 +02:00
|
|
|
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
|
2012-04-08 05:00:24 +02:00
|
|
|
end
|