【发布时间】:2016-03-11 19:00:13
【问题描述】:
我正在尝试通过 rspec 在视图助手中设置局部变量。我的日常是这样的
def time_format(time)
now = Time.now.in_time_zone(current_user.timezone)
end
我的规范文件如下:
it 'return 12 hour format' do
user = User.first
assign(:current_user, user)
expect(helper.time_format(900)).to eq('9:00 AM')
end
规范失败并抛出错误未定义的局部变量或方法'current_user'
'current_user' 驻留在 application_controller 中
【问题讨论】:
标签: ruby-on-rails ruby rspec helper