以下は私のレールコントローラーです:
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
以下は、(spec/controller) の下にある私の 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
仕様からコントローラのインデックス メソッドで値を取得できないため、エラーが発生します。