Ruby on rails RSpec分配(:项)。eq([项])是否应返回零
我是RSpec的新手,显然做错了什么 具有索引操作的基本控制器:Ruby on rails RSpec分配(:项)。eq([项])是否应返回零,ruby-on-rails,Ruby On Rails,我是RSpec的新手,显然做错了什么 具有索引操作的基本控制器: class TransactionsController < ApplicationController before_filter :authenticate_user! def index @transactions = current_user.transactions respond_to do |format| format.html { render layout: "ite
class TransactionsController < ApplicationController
before_filter :authenticate_user!
def index
@transactions = current_user.transactions
respond_to do |format|
format.html { render layout: "items" } # index.html.erb
format.json { render json: @transactions }
end
end
end
因此,除了行赋值(:transactions)之外,所有操作都有效。eq([transaction])
是否应返回nil,因此我得到以下错误:
Failure/Error: assigns(:transactions).should eq([transaction])
expected: [#<Transaction id: 1, user_id: 1, text: "some transaction", date: "2013-02-02", money: #<BigDecimal:b8a8e90,'0.999E1',18(18)>, created_at: "2013-02-02 09:17:42", updated_at: "2013-02-02 09:17:42">]
got: nil
(compared using ==)
# ./spec/controllers/transactions_controller_spec.rb:17:in `block (3 levels) in <top (required)>'
失败/错误:分配(:事务)。应eq([事务])
期望值:[#]
得:零
(使用==进行比较)
#./spec/controllers/transactions\u controller\u spec.rb:17:in'block(3级)in'
如果您有任何建议,我将不胜感激,因为我花了一整天的时间在这上面。首先,如果您在过滤之前使用
:验证用户代码>您需要通过该过滤器
这可以通过在某些用户中使用sign\u来实现
其次,在分配事务时@transactions=current\u user.transactions
您希望规范中应该有一些,您必须创建分配给当前用户的事务。创建(:事务,用户:某些用户)
您能检查get:index to controller.index是否有效吗?如果是,您必须检查路线
Failure/Error: assigns(:transactions).should eq([transaction])
expected: [#<Transaction id: 1, user_id: 1, text: "some transaction", date: "2013-02-02", money: #<BigDecimal:b8a8e90,'0.999E1',18(18)>, created_at: "2013-02-02 09:17:42", updated_at: "2013-02-02 09:17:42">]
got: nil
(compared using ==)
# ./spec/controllers/transactions_controller_spec.rb:17:in `block (3 levels) in <top (required)>'