Tag: stub

RSpec:如何存根inheritance方法current_user(没有设计)?

我有一个基于MHartl的RoR4教程的控制器 就像MHartl一样, 我没有使用Devise ,我推出了自己的身份validation系统 因为视图调用current_user.admin?无法使用RSpec for UsersController#Edit current_user.admin? 并且控制器调用@path_switch = path_switch 我不断得到RSpec错误: 1) User Pages Edit Failure/Error: visit edit_user_path(user) NoMethodError: undefined method `admin?’ for nil:NilClass # ./app/controllers/users_controller.rb:106:in `path_switch’ # ./app/controllers/users_controller.rb:53:in `edit’ # ./spec/requests/user_pages_spec.rb:54:in `block (3 levels) in ‘ UsersController: class UsersController < ApplicationController … def edit @user = User.find(params[:id]) @path_switch ||= path_switch #error end … […]