[英]Load an module in an rspec test
I have the following test... 我有以下测试...
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
Note the 3rd line extend SubdomainHelpers
which I am trying to load from... 请注意第三行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
When I run the text I get the error uninitialized constant SubdomainHelpers (NameError)
How do I call the SubdomainHelpers module from the test? 运行文本时,出现错误uninitialized constant SubdomainHelpers (NameError)
如何从测试中调用SubdomainHelpers模块?
You need to require 'support/subdomain_helpers'
in your rails_helper or the sign_in_spec file. 您需要在rails_helper或sign_in_spec文件中require 'support/subdomain_helpers'
。
Files in the spec/support
subdirectory are automagically loaded into LOAD_PATH
by rspec, but they're not required. rspec将spec/support
子目录中的文件自动加载到LOAD_PATH
,但不是必需的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.