當我用capybara/rspec創建集成測試時,它似乎得到了正確的url和路徑。但它在'click_button'上出錯。rspec水豚 - 子域測試
注: '把current_url' 返回正確路徑:http://StoreName1.lvh.me/login
測試:
require 'spec_helper'
describe "Account access" do
before(:each) do
Factory(:plan)
Factory(:theme)
@account = Factory(:account)
set_host("#{@account.url}")
end
describe "GET /login" do
it "should not sign in for invalid details" do
Factory(:account, :url => 'dan', :email => '[email protected]')
visit "/login"
page.should have_content("Sign in to your store")
fill_in "email", with: "[email protected]"
fill_in "password", with: "donuts"
click_button 'Sign in'
end
end
def set_host(host)
host! host
Capybara.app_host = "http://" + host + ".lvh.me"
end
end
錯誤日誌:
1) Account access GET /login should not sign in for invalid details
Failure/Error: click_button 'Sign in'
ActiveRecord::RecordNotFound:
Couldn't find Account with url = StoreName1
# ./app/controllers/application_controller.rb:11:in `get_account_info'
# (eval):2:in `click_button'
# ./spec/requests/accounts_spec.rb:19:in `block (3 levels) in <top (required)>'
不應該的網址是http://StoreName1.lvh.me:3000/login? – 2012-02-25 07:52:33