Skip to content
This repository
Browse code

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
  • Loading branch information...
commit 8d218e78719eefd6d24a7c4e74f18cec7849a52b 1 parent c92f80b
leamas leamas authored Alec Leamas committed
1  config/application.rb
@@ -56,5 +56,6 @@ class Application < Rails::Application
56 56 config.filter_parameters += [:text]
57 57 config.filter_parameters += [:caption]
58 58 config.filter_parameters += [:bio]
  59 +
59 60 end
60 61 end
4 config/cucumber.yml
@@ -3,6 +3,6 @@ rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
3 3 rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
4 4 std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip"
5 5 %>
6   -default: <%= std_opts %> features
7   -wip: --tags @wip:3 --wip features
  6 +default: <%= std_opts %> -r features
  7 +wip: -r features --tags @wip:3 --wip features
8 8 rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
4 config/environment.rb
@@ -6,6 +6,7 @@
6 6 require File.expand_path('../application', __FILE__)
7 7 Haml::Template.options[:format] = :html5
8 8 Haml::Template.options[:escape_html] = true
  9 +ActionController::Base.config.relative_url_root = "/daspora"
9 10
10 11 if File.exists?(File.expand_path("./config/languages.yml"))
11 12 languages = YAML::load(File.open(File.expand_path("./config/languages.yml")))
@@ -24,6 +25,7 @@
24 25 LANGUAGE_CODES_MAP = {}
25 26 end
26 27
  28 +#config.action_controller.relative_url_root = "/diaspora"
  29 +
27 30 # Initialize the rails application
28 31 Diaspora::Application.initialize!
29   -
33 features/step_definitions/uri-step.rb
... ... @@ -0,0 +1,33 @@
  1 +Given /^configuration parameter (\w+) is ([^ ]+)$/ do |key, value|
  2 + require Rails.root.join('config', "initializers", "_load_app_config.rb")
  3 + app_value = AppConfig[ key.to_sym]
  4 + assert_equal value, app_value,
  5 + "You must set #{key} to #{value} and kill running server"
  6 +end
  7 +
  8 +When /^I visit url ([^ ]+)$/ do |url|
  9 + visit( url)
  10 +end
  11 +
  12 +Then /^I should find '([^']*)' in ([^ ]+)$/ do |pattern,file|
  13 + found = %x!fgrep -o #{pattern} #{file}!
  14 + assert_equal pattern, found.chomp, "Can't find pattern in #{file}"
  15 +end
  16 +
  17 +Then /^I should match '([^']*)' in ([^ ]+)$/ do |pattern,file|
  18 + found = `egrep -o '#{pattern}' #{file}`
  19 + assert_match /#{pattern}/, found.chomp, "Can't find #{pattern} in #{file}"
  20 +end
  21 +
  22 +When /^I retrieve ([^ ]+) into ([^ ]+)$/ do |url,file|
  23 + system( "wget -q -O #{file} #{url}")
  24 +end
  25 +
  26 +Then /^a page\-asset should be ([^ ]+)$/ do |asset_path|
  27 + page.has_content?(asset_path)
  28 +end
  29 +
  30 +
  31 +
  32 +
  33 +
11 features/support/env.rb
@@ -71,3 +71,14 @@ def lpush(*args)
71 71 UserFixer.regenerate_user_fixtures
72 72 UserFixer.load_user_fixtures
73 73 end
  74 +
  75 +Before('@localserver') do
  76 + TestServerFixture.start_if_needed
  77 + CapybaraSettings.instance.save
  78 + Capybara.current_driver = :selenium
  79 + Capybara.run_server = false
  80 +end
  81 +
  82 +After('@localserver') do
  83 + CapybaraSettings.instance.restore
  84 +end
73 features/support/server.rb
... ... @@ -0,0 +1,73 @@
  1 +
  2 +ENV["RAILS_ENV"] ||= "test"
  3 +require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
  4 +
  5 +require 'timeout'
  6 +require 'socket'
  7 +require 'singleton'
  8 +
  9 +require 'capybara/rails'
  10 +require 'capybara/cucumber'
  11 +require 'capybara/session'
  12 +
  13 +class TestServerFixture
  14 +# simple interface to script/server
  15 +
  16 + def self.is_port_open(host, port, tries)
  17 + for i in (1..tries)
  18 + begin
  19 + Timeout::timeout(2) do
  20 + begin
  21 + s = TCPSocket.new(host, port)
  22 + s.close
  23 + return true
  24 + rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
  25 + sleep( 2)
  26 + end
  27 + end
  28 + rescue Timeout::Error
  29 + return false
  30 + end
  31 + end
  32 + return false
  33 + end
  34 +
  35 + def self.start_if_needed
  36 + unless TestServerFixture.is_port_open( "localhost", 3000, 2)
  37 + system( "script/server -d")
  38 + if TestServerFixture.is_port_open( "localhost", 3000, 30)
  39 + puts "script/server started"
  40 + else
  41 + puts "Error: can't start script/server"
  42 + end
  43 + end
  44 + end
  45 +
  46 +end
  47 +
  48 +class CapybaraSettings
  49 +# simple save/restore for Capybara
  50 +
  51 + include Singleton
  52 +
  53 + def save
  54 + begin
  55 + @run_server = Capybara.run_server
  56 + @driver = Capybara.current_driver
  57 + @host = Capybara.app_host
  58 + rescue => e
  59 + puts "Saving exception: " + e.inspect
  60 + end
  61 + end
  62 +
  63 + def restore
  64 + begin
  65 + Capybara.current_driver = @driver
  66 + Capybara.app_host = @host
  67 + Capybara.run_server = @run_server
  68 + rescue => e
  69 + puts "Restore exception: " + e.inspect
  70 + end
  71 + end
  72 +
  73 +end
19 features/uri-tests/uri.feature
... ... @@ -0,0 +1,19 @@
  1 +@localserver
  2 +Feature: Flexible uri deployment
  3 + To make it possible to use Diaspora on small home servers,
  4 + which might house also other sw, it should be possible to deploy
  5 + diaspora on a sub-uri such as http://example.org/diaspora.
  6 +
  7 + Scenario: Serve webfinger request
  8 + Given configuration parameter pod_url is http://localhost:3000/diaspora
  9 + When I retrieve http://localhost:3000/.well-known/host-meta into tmp/host-meta
  10 + Then I should find 'http://localhost:3000/diaspora/webfinger?q={uri}' in tmp/host-meta
  11 +
  12 + Scenario: Present application to user
  13 + Given configuration parameter pod_url is http://localhost:3000/diaspora
  14 + When I visit url http://localhost:3000/diaspora
  15 + And I retrieve http://localhost:3000/diaspora into tmp/index.html
  16 + Then I should see "put something in"
  17 + And a page-asset should be http://localhost:3000/diaspora/stylesheets/ui.css
  18 + And I should match 'http://localhost:3000/diaspora/stylesheets/blueprint/print.css.[0-9]+"' in tmp/index.html
  19 +
1  lib/tasks/cucumber.rake
@@ -18,6 +18,7 @@ begin
18 18 t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
19 19 t.fork = true # You may get faster startup if you set this to false
20 20 t.profile = 'default'
  21 + t.cucumber_opts = "features --exclude features/uri-tests/*"
21 22 end
22 23
23 24 Cucumber::Rake::Task.new(:wip, 'Run features that are being worked on') do |t|

1 comment on commit 8d218e7

leamas
Collaborator

The changes in environment.rb are test garbage, cleared in next patch

Please sign in to comment.
Something went wrong with that request. Please try again.