我正在用 capybara 测试我的自定义设计视图,我需要一个登录用户来测试一些视图,例如:
feature 'user/edit' do
describe "the edit profile process", :type => :feature do
include Devise::TestHelpers
let!(:user){ FactoryGirl.build(:user)
def sign_in(user)
if user.nil?
request.env['warden'].stub(:authenticate!).
and_throw(:warden, {:scope => :user})
controller.stub :current_user => nil
else
request.env['warden'].stub :authenticate! => user
controller.stub :current_user => user
end
end
it "update " do
sign_in(user)
visit '/users/edit'
within("#edit_user") do
#=> something
end
click_on 'Update'
page.should have_content("something")
end
end
end
但我得到了这个错误
Failure/Error: request.env['warden'].stub :authenticate! => user
NoMethodError: undefined method `env' for nil:NilClass