Commit 8d218e78 authored by Alec Leamas's avatar Alec Leamas Committed by Alec Leamas

suburi cucumber test.

Adds the features/uri-features test directory, testing sub-uri
deployment. These tests uses script/server since much of this code is
about configuring the server.  They are not run by "rake cucumber", to
run them use "bundle exec rake cucumber features/uri-test".

Tests requires a working app_config.yml setup with pod_url =
"http://localhost:3000/diaspora"

Patches cucumber.yml to always load step definitions from features/**, see
http://thoughtsincomputation.com/posts/cucumber-step-definitions-and-autorequire-hell
parent c92f80b2
......@@ -56,5 +56,6 @@ module Diaspora
config.filter_parameters += [:text]
config.filter_parameters += [:caption]
config.filter_parameters += [:bio]
end
end
......@@ -3,6 +3,6 @@ rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip"
%>
default: <%= std_opts %> features
wip: --tags @wip:3 --wip features
default: <%= std_opts %> -r features
wip: -r features --tags @wip:3 --wip features
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
......@@ -6,6 +6,7 @@
require File.expand_path('../application', __FILE__)
Haml::Template.options[:format] = :html5
Haml::Template.options[:escape_html] = true
ActionController::Base.config.relative_url_root = "/daspora"
if File.exists?(File.expand_path("./config/languages.yml"))
languages = YAML::load(File.open(File.expand_path("./config/languages.yml")))
......@@ -24,6 +25,7 @@ else
LANGUAGE_CODES_MAP = {}
end
#config.action_controller.relative_url_root = "/diaspora"
# Initialize the rails application
Diaspora::Application.initialize!
Given /^configuration parameter (\w+) is ([^ ]+)$/ do |key, value|
require Rails.root.join('config', "initializers", "_load_app_config.rb")
app_value = AppConfig[ key.to_sym]
assert_equal value, app_value,
"You must set #{key} to #{value} and kill running server"
end
When /^I visit url ([^ ]+)$/ do |url|
visit( url)
end
Then /^I should find '([^']*)' in ([^ ]+)$/ do |pattern,file|
found = %x!fgrep -o #{pattern} #{file}!
assert_equal pattern, found.chomp, "Can't find pattern in #{file}"
end
Then /^I should match '([^']*)' in ([^ ]+)$/ do |pattern,file|
found = `egrep -o '#{pattern}' #{file}`
assert_match /#{pattern}/, found.chomp, "Can't find #{pattern} in #{file}"
end
When /^I retrieve ([^ ]+) into ([^ ]+)$/ do |url,file|
system( "wget -q -O #{file} #{url}")
end
Then /^a page\-asset should be ([^ ]+)$/ do |asset_path|
page.has_content?(asset_path)
end
......@@ -71,3 +71,14 @@ Before do
UserFixer.regenerate_user_fixtures
UserFixer.load_user_fixtures
end
Before('@localserver') do
TestServerFixture.start_if_needed
CapybaraSettings.instance.save
Capybara.current_driver = :selenium
Capybara.run_server = false
end
After('@localserver') do
CapybaraSettings.instance.restore
end
ENV["RAILS_ENV"] ||= "test"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
require 'timeout'
require 'socket'
require 'singleton'
require 'capybara/rails'
require 'capybara/cucumber'
require 'capybara/session'
class TestServerFixture
# simple interface to script/server
def self.is_port_open(host, port, tries)
for i in (1..tries)
begin
Timeout::timeout(2) do
begin
s = TCPSocket.new(host, port)
s.close
return true
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
sleep( 2)
end
end
rescue Timeout::Error
return false
end
end
return false
end
def self.start_if_needed
unless TestServerFixture.is_port_open( "localhost", 3000, 2)
system( "script/server -d")
if TestServerFixture.is_port_open( "localhost", 3000, 30)
puts "script/server started"
else
puts "Error: can't start script/server"
end
end
end
end
class CapybaraSettings
# simple save/restore for Capybara
include Singleton
def save
begin
@run_server = Capybara.run_server
@driver = Capybara.current_driver
@host = Capybara.app_host
rescue => e
puts "Saving exception: " + e.inspect
end
end
def restore
begin
Capybara.current_driver = @driver
Capybara.app_host = @host
Capybara.run_server = @run_server
rescue => e
puts "Restore exception: " + e.inspect
end
end
end
@localserver
Feature: Flexible uri deployment
To make it possible to use Diaspora on small home servers,
which might house also other sw, it should be possible to deploy
diaspora on a sub-uri such as http://example.org/diaspora.
Scenario: Serve webfinger request
Given configuration parameter pod_url is http://localhost:3000/diaspora
When I retrieve http://localhost:3000/.well-known/host-meta into tmp/host-meta
Then I should find 'http://localhost:3000/diaspora/webfinger?q={uri}' in tmp/host-meta
Scenario: Present application to user
Given configuration parameter pod_url is http://localhost:3000/diaspora
When I visit url http://localhost:3000/diaspora
And I retrieve http://localhost:3000/diaspora into tmp/index.html
Then I should see "put something in"
And a page-asset should be http://localhost:3000/diaspora/stylesheets/ui.css
And I should match 'http://localhost:3000/diaspora/stylesheets/blueprint/print.css.[0-9]+"' in tmp/index.html
......@@ -18,6 +18,7 @@ begin
t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
t.fork = true # You may get faster startup if you set this to false
t.profile = 'default'
t.cucumber_opts = "features --exclude features/uri-tests/*"
end
Cucumber::Rake::Task.new(:wip, 'Run features that are being worked on') do |t|
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment