我已经为我的用户模型构建了一个控制器规范,它通过了,尽管我觉得它应该失败。规格如下:
describe UsersController do
include Devise::TestHelpers
let (:user) do
FactoryGirl.create(:user)
end
let (:other_user) do
FactoryGirl.create(:user)
end
before :each do
@request.env["devise.mapping"] = Devise.mappings[:user]
sign_in user
end
describe "#index" do
it "can GET 'index'" do
get :index
response.should be_success
end
it "populates a list of users" do
get :index
expect(assigns(:users)).to eq([user])
end
end
end
“expect(assigns(:users)).to eq([user])”行通过了,但我觉得它应该失败。毕竟,我在顶部创建了两个用户(user 和 other_user)。我显然误解了发生了什么,所以有人可以解释一下吗?