我有以下测试...
require "rails_helper"
feature "User sign in" do
extend SubdomainHelpers
let!(:account) { FactoryGirl.create(:account) }
let(:sign_in_url) { "http://#{account.subdomain}.example.com/sign_in" }
let(:root_url) { "http://#{account.subdomain}.example.com/" }
within_account_subdomain do
scenario "signs in as an account owner successfully" do
visit root_url
expect(page.current_url).to eq(sign_in_url)
fill_in "Email", :with => account.owner.email
fill_in "Password", :with => "password"
click_button "Sign in"
expect(page).to have_content("You are now signed in.")
expect(page.current_url).to eq(root_url)
end
end
end
请注意我尝试加载的第3行extend SubdomainHelpers
...
module SubdomainHelpers
def within_account_subdomain
let(:subdomain_url) { "http://#{account.subdomain}.example.com" }
before { Capybara.default_host = subdomain_url }
after { Capybara.default_host = "http://www.example.com" }
yield
end
end
当我运行文本时,我收到错误uninitialized constant SubdomainHelpers (NameError)
如何从测试中调用SubdomainHelpers模块?
答案 0 :(得分:0)
您需要在rails_helper或sign_in_spec文件中require 'support/subdomain_helpers'
。
spec/support
子目录中的文件由rspec自动加载到LOAD_PATH
,但不是必需的。