我想测试我的多域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可能对此多域内容有问题?

最佳答案

在您的设置中,调用此rack::test函数,该函数将更改主机的值。好吧,它更改了有关假Web请求的返回主机。

host! "#{store.subdomain}.example.com"

关于ruby-on-rails - 使用Capybara测试多域Rails 3应用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4724054/

10-12 22:24