我想测试我的多域 RoR3 应用程序。
这是我的 test_helper.rb
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'capybara/rails'
require 'blueprints'
class ActiveSupport::TestCase
end
class ActionDispatch::IntegrationTest
include Capybara
def host
"http://#{subdomain}.lvh.me:3000"
end
def subdomain
@subdomain ? @subdomain : 'demostore'
end
def visit(url)
super("http://#{subdomain}.lvh.me:3000#{url}")
end
end
还有我的集成测试:
require 'test_helper'
class ProductsTest < ActionDispatch::IntegrationTest
def setup
@subdomain = 'demostore'
# creating stuff
end
def teardown
# deleting stuff
end
test "user views product list" do
visit('/')
assert page.has_css?('ul.product-listing')
assert page.has_xpath?("//ul[@class='product-listing']/li", :count => 12)
end
test "user views product page" do
product = Product.first
visit('/')
find(:xpath, "//ul[@class='product-listing']/li/a[1]").click
save_and_open_page
end
end
而且我确定链接存在。单击和填充内容存在问题。
click_link('Existent link title')
也不行。
我认为默认 Capybara 的驱动程序 Rack::Test 可能对这个多域的东西有问题?