我正在尝试通过rspec在视图助手中设置局部变量。我的例行如下
def time_format(time)
now = Time.now.in_time_zone(current_user.timezone)
end
Run Code Online (Sandbox Code Playgroud)
我的规格文件如下:
it 'return 12 hour format' do
user = User.first
assign(:current_user, user)
expect(helper.time_format(900)).to eq('9:00 AM')
end
Run Code Online (Sandbox Code Playgroud)
规范失败并抛出错误未定义的局部变量或方法“ current_user”
“ current_user”驻留在application_controller中