我在spec / features
中有一个sign_in_spec.rbrequire 'spec_helper'
feature 'user signs in' do
before(:all) do
Capybara.current_driver = :selenium
end
let!(:user) { FactoryGirl.create(:user) }
@javascript
scenario 'with valid credentials' do
visit('/users/sign_in')
fill_in('Email', :with => user.email)
fill_in('Password', :with => user.password)
click_button('Sign in')
page.should have_content 'Signed in successfully'
end
@javascript
scenario 'with invalid password' do
visit('/users/sign_in')
fill_in('Email', :with => user.email)
fill_in('Password', :with => 'incorrect')
click_button('Sign in')
page.should have_content 'Invalid email or password'
end
end
我遇到第一个场景的问题。这是我的工厂.rb
FactoryGirl.define do
factory :user do
email 'judy.ngai1228@gmail.com'
password 'crackers'
end
end
根据factorygirl doc,create方法应该返回一个保存的实例。我甚至在rails c测试环境和开发环境中创建了一个带有工厂女孩定义的电子邮件/密码的用户。
当我进行测试时,我继续
invalid password/username
它只是不会被发布/无法登录。我使用数据库清理器来清理测试环境.....但工厂女孩创建方法应该做的伎俩。
require 'simplecov'
SimpleCov.start
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
#require 'rspec/autorun'
require 'rspec/rails'
require 'capybara/rspec'
require 'capybara/rails'
require 'database_cleaner'
include Warden::Test::Helpers
Warden.test_mode!
RSpec.configure do |config|
config.include Capybara::DSL
config.include FactoryGirl::Syntax::Methods
#use database cleaner instead
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with :truncation
end
config.before :each do
DatabaseCleaner.start
end
config.after :each do
DatabaseCleaner.clean
end
end
更新使密码更长
FactoryGirl.define do
factory :user do
email 'judy.ngai1228@gmail.com'
password 'crackers123456'
end
end
仍然无法正常工作。