2013-01-02 19 views
5

कैपिबारा का उपयोग कर परीक्षण तैयार करने का परीक्षण। ऐसा लगता है कि कुछ गलत है क्योंकि मैं rspec और capybara का उपयोग करके साइन इन का परीक्षण नहीं कर सकता। इम कारखाने महिला का उपयोग कर उपयोगकर्तारुपेक कैपिबरा उपयोगकर्ता लॉगिन नहीं कर सकता

FactoryGirl.define do 
factory :user do 
    email '[email protected]' 
    password 'bhaktapur' 
    password_confirmation 'bhaktapur' 
    admin true 
    name 'admin' 
    confirmation_sent_at "#{DateTime.now}" 
    confirmation_token 'anupsumhikichiki' 
    confirmed_at "#{DateTime.now}" 
    username 'username' 
end 
end 

यहाँ परिभाषित करने के लिए मेरी spec_helper.rb

# This file is copied to spec/ when you run 'rails generate rspec:install' 
ENV["RAILS_ENV"] ||= 'test' 
require File.expand_path("../../config/environment", __FILE__) 
require 'rspec/rails' 
require 'rspec/autorun' 
require 'capybara/rspec' 
require 'database_cleaner' 
# FactoryGirl.find_definitions 
Capybara.current_driver = :selenium 
# Requires supporting ruby files with custom matchers and macros, etc, 
# in spec/support/ and its subdirectories. 
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} 
RSpec.configure do |config| 
config.include Devise::TestHelpers, :type => :controller 
config.before(:suite) do 
DatabaseCleaner.strategy = :transaction 
DatabaseCleaner.clean_with :truncation 
end 

config.before(:each) do 
DatabaseCleaner.start 
end 
# config.after(:each) { } 
config.after(:each) do 
DatabaseCleaner.clean 
Warden.test_reset! 
end 
config.fixture_path = "#{::Rails.root}/spec/fixtures" 
config.use_transactional_fixtures = false 

# If true, the base class of anonymous controllers will be inferred 
# automatically. This will be the default behavior in future versions of 
# rspec-rails. 
config.infer_base_class_for_anonymous_controllers = false 
end 

यहाँ है और मेरी कल्पना

require_relative '../spec_helper.rb' 
include Warden::Test::Helpers 
Warden.test_mode! 

feature "the signin process" do 
before :each do 
@user_attr = FactoryGirl.attributes_for(:user) 
# @user = FactoryGirl (:user) 
User.create!(@user_attr) 
end 

scenario "signs me in" do 
    # login_as @user, :scope => :user 
    visit '/' 
    fill_in 'Login', :with => "[email protected]" 
    fill_in 'Password', :with => "bhaktapur" 
    click_button 'Sign in' 
    page.should have_content "Signed in successfully" 
    Warden.test_reset! 
end 
end 

इसके अलावा मेरे उपयोगकर्ता मॉडल confirmable

+0

भीतर मैं अंत में पाया जवाब यहाँ http://stackoverflow.com/questions/6576592/failing-to-test-devise-with-capybara – xecutioner

+0

मैं समाधान पाया का उपयोग कर http://stackoverflow.com/questions/6576592/failing-to-test-devise-with-capybara – xecutioner

उत्तर

3
पर सेट किया जाता है

सभी पुष्टिकरण डेटा बिंदु जोड़ने के बजाय ..

का उपयोग करना चाहिए
@user = FactoryGirl.build(:user) 
@user.skip_confirmation! 
@user.save! 

फिर अपने परिदृश्य

fill_in 'Login', :with => @user.email 
fill_in 'Password', :with => @user.password 
+0

@bullfrog की मदद करने के लिए धन्यवाद लेकिन समस्या अभी भी बनी हुई है। अजीब बात यह है कि जब मैं उपयोगकर्ता को जांचता हूं तो परीक्षण डेटाबेस में मौजूद होता है। – xecutioner

+2

मुझे इस http://stackoverflow.com/questions/6576592/failing-to-test-devise-with-capybara का उपयोग करके समाधान मिला – xecutioner