dre*_*ake 9 integration-testing ruby-on-rails capybara
我想测试我的多域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
Run Code Online (Sandbox Code Playgroud)
我的集成测试:
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
Run Code Online (Sandbox Code Playgroud)
而且我确定链接存在.点击和填充内容存在问题.
click_link('Existent link title')
Run Code Online (Sandbox Code Playgroud)
不起作用.
我认为默认的Capybara的驱动程序Rack :: Test可能会遇到这个多域名的问题?
在您的设置中,调用该rack::test 函数,这将更改主机的值。嗯,它更改了关于虚假 Web 请求返回的主机。
host! "#{store.subdomain}.example.com"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5800 次 |
| 最近记录: |