我对学习BDD感兴趣,我遵循Setting up a BDD stack on a rails 5 application中提到的免费Rails测试手册,并且几乎完成了第5章引导用户认证系统。
该书第39页的最后一行显示
此时一切都应该是绿色的
但是,当我运行bundle exec cucumber
时,我遇到两种失败的情况(用户登录和用户注销)。黄瓜输出节选如下:
When I fill in the login form #
features/step_definitions/authentication_steps.rb:29
undefined method `current_sign_in_ip' for #<User:0x0055a41ac1eeb8> (NoMethodError)
./features/step_definitions/authentication_steps.rb:32:in `"I fill in the login form"'
features/authentication.feature:15:in `When I fill in the login form'
app / models / user.rb
class User < ApplicationRecord
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:confirmable
end
db / migrate / 20181221105428_add_trackable_to_devise.rb
class AddTrackableToDevise < ActiveRecord::Migration[5.2]
def change
add_column :users, :sign_in_count, :integer, default:0, null: false
add_column :users, :current_sign_in_at, :datetime
add_column :users, :last_sign_in_at, :datetime
add_column :users, :current_sign_in_ip, :inet
add_column :users, :last_sign_in_ip, :inet
end
end
完整代码和pdf书可在github repo上获得。
我将非常感谢您的帮助。
答案 0 :(得分:1)
只需运行rake db:test:prepare即可在测试环境中执行上一次迁移