0
我是新來的rails,所以我可能已經完全錯過了這裏的問題,但我似乎在使用測試引用我自己的Page類時遇到問題。別名水豚頁方法
當我有一個測試,有創建一個頁面類的實例(通過FactoryGirl),那麼我無法運行任何Capybara頁面方法(如訪問,fill_in,點擊等)。我得到以下錯誤:
NoMethodError:
undefined method `visit' for #<Page:0x007fdf5eb9d990>
當我添加一個調試器語句,並檢查page
變量是我的Page類的一個實例。我如何確保在執行水豚方法時始終使用水豚頁面?
我的功能規格(我知道這是不完整的,但在之前循環發生錯誤):
require 'spec_helper'
feature 'Modifying a page' do
let(:account) { FactoryGirl.create(:account) }
let!(:page_creator) { FactoryGirl.create(:user, :account => account) }
let!(:standard_user) { FactoryGirl.create(:user, :account => account) }
let!(:site) { FactoryGirl.create(:site, :account => account) }
let!(:page) { FactoryGirl.create(:page, :account => account, :site => site, :creator => page_creator) }
context 'as the creator of the page' do
before(:each) { sign_in_via_form account, page_creator, page_creator.password }
scenario 'with valid information' do
new_page_name = Faker::Lorem.characters(Random.rand(10..100))
new_page_url = Faker::Internet.url
new_page_description = Faker::Lorem.characters(Random.rand(50..250))
click_link site.name
click_link 'Pages'
find("a[href='#{edit_site_page_path([site, page])}'").click
end
end
end
的sign_in_via_form
方法在follwing文件中定義:
module AuthenticationHelpers
include Warden::Test::Helpers
Warden.test_mode!
def sign_in_via_form(account, user, password)
visit "http://#{account.subdomain}.example.com"
fill_in 'Email', :with => user.email
fill_in 'Password', :with => password
click_button 'Sign In'
end
end
我有一些其他功能,對付不同的模型正在運行(並使用上述sign_in_via_form
方法沒有任何問題,這是什麼讓我覺得這是與頁面類。
正如我說的,我是很新的軌道,所以你必須原諒我,如果這些測試看起來有點醜:-)
感謝所有幫助
具有u加config.include豚:: DSL在你spec_helper.rb –
我沒有,但我只是說它和我仍然得到相同的錯誤 –
看看https://github.com/rspec/rspec-rails/issues/503和 http://stackoverflow.com/questions/9059854/capybara-undefined-method-訪問 –