以下是我的导轨控制器:
class MyController < ApplicationController
def index
@client = (current_company.clients.size || 0) >= current_company.subscription.clients # it returns true or false
begin
@obj = Class.all
respond_to do |format|
format.html # index.html.erb
end
rescue
end
end
end
以下是我在(规范/控制器)下的 rspec 代码:
require 'spec_helper'
describe MyController do
describe "GET index" do
it "populates an array of data" do
current_company = mock_model(CompaniesUser)
clients = mock_model(Client)
get :index
.
.
end
end
end
执行后它向我提供以下错误:
Failures:
1) MyController GET index populates an array of clients
Failure/Error: get :index
Double "Company_1" received unexpected message :clients with (no args)
# ./app/controllers/my_controller.rb:20:in `index'
# ./spec/controllers/my_controller_spec.rb:28:in `block (3 levels) in <top (required)>'
那么如何current_compnay.clients.size
在 rspec 控制器中进行这种关联呢?current_company.clients.size
由于未从规范中获取控制器的索引方法中的值,它会提供错误。