控制器實例變量我有簡單的控制器:不能得到使用RSpec
class CreditLogsController < BaseController
def show
@account = Account.find_by_email(Base64.urlsafe_decode64(params[:id]))
end
end
,這裏是規範它:
require 'rails_helper'
describe CreditLogsController, type: :controller do
describe 'GET #show' do
it 'responds with 200' do
create(:account)
get :show, params: {id: Base64.urlsafe_encode64('[email protected]')}, format: :html
puts "############# #{controller.instance_variable_get(:account)}"
expect(assigns(:account)).to eql('[email protected]')
end
end
end
的問題是,account
在規範總是nil
,在覆蓋來自控制器的文件代碼分配值爲@account
顯示爲未涵蓋,並且controller.instance_variable_get(:account)
產生了一個錯誤:
`account' is not allowed as an instance variable name.
我在其他規範中有類似的代碼,工作正常,所以我做錯了什麼?
您是否使用FactoryGirl創建帳戶?你正在比較一個對象'@ account'和一個字符串''tes1 @ test.com''?它應該是'expect(指定(:account).email).to eql('[email protected]')' – Thanh
似乎代碼指針未達到show action方法 –