我创建了一个'lil帮助文件来干扰我的规格:
module RemoteMacros
def go_to_another_localhost(port)
Capybara.current_driver = :selenium
Capybara.app_host = "localhost:#{port}"
Capybara.run_server = false
end
def go_webapp
Capybara.current_driver = :rack_test
Capybara.app_host = "localhost:3000"
Capybara.run_server = true
end
end
以下是与之相关的规范:
require "rails_helper"
describe "Placing an ad", :type => :feature do
it "(1) The ad token should match across domains" do
go_to_another_localhost(8000)
visit "/"
expect(page).to have_css( 'iframe[data-nc-token="demo-token"]' )
end
it "(2) can go places" do
go_webapp
visit "/"
save_and_open_page
expect(page).to have_content( 'lol' )
end
end
乍一看,似乎一切都应该按预期工作(已经说了多少次?; D)。但是,我的第二次测试返回红色,带有一个相当特殊的信息:
Placing an ad
(1) The ad token should match across domains
(2) can go places (FAILED - 1)
Failures:
1) Placing an ad (2) can go places
Failure/Error: visit "/"
NoMethodError:
undefined method `empty?' for nil:NilClass
我正在研究的是一些跨域JS。我需要在我的实际Rails应用程序中验证我的另一个域中的JS是否与模型的属性匹配。我得到了第一部分工作,我将我的应用程序转到另一个域,但当我将app_host返回到原始位置时,第二部分在我的脸上爆炸。
我应该如何修改代码以实现我的意图?