以下は私のspec/controllers / superadmin /users_controller_spec.rbにあります:
describe "GET index" do
it "receives the where action twice" do
User.should_receive(:where).twice
get :index
end
it "assigns @superadmins" do
get :index
assigns[:superadmins].should_not be_nil
end
it "assigns @admins" do
get :index
assigns[:admins].should_not be_nil
end
end
以下は私のapp/controllers / superadmin /users_controller.rbにあります:
class Superadmin::UsersController < SuperadminController
def index
@superadmins = User.where(:role => 'superadmin')
@admins = User.where(:role => 'admin')
end
...
end
私が正しく思い出せば、このテストは以前は合格でした。テストおよび開発環境のデータベースとしてPostgreSQLを設定して以来、このテストは失敗しています...理由はわかりません。
エラーメッセージ:
Failures:
1) Superadmin::UsersController GET index receives the where action twice
Failure/Error: User.should_receive(:where).twice
(<User(id: integer, role: string, first_name: string, last_name: string, login: string, email: string, crypted_password: string, password_salt: string, persistence_token: string, single_access_token: string, perishable_token: string, login_count: integer, failed_login_count: integer, last_request_at: datetime, current_login_at: datetime, last_login_at: datetime, current_login_ip: string, last_login_ip: string, created_at: datetime, updated_at: datetime, restaurant_id: integer, organization_id: integer) (class)>).where(any args)
expected: 2 times
received: 0 times
# ./spec/controllers/superadmin/users_controller_spec.rb:6:in `block (3 levels) in <top (required)>'
2) Superadmin::UsersController GET index assigns @superadmins
Failure/Error: assigns[:superadmins].should_not be_nil
expected: not nil
got: nil
# ./spec/controllers/superadmin/users_controller_spec.rb:12:in `block (3 levels) in <top (required)>'
3) Superadmin::UsersController GET index assigns @admins
Failure/Error: assigns[:admins].should_not be_nil
expected: not nil
got: nil
# ./spec/controllers/superadmin/users_controller_spec.rb:17:in `block (3 levels) in <top (required)>
支援に感謝します!