我是 RSpec 的新手,所以我正在为一个简单的测试寻求一些帮助:
# controller method
def show
@group = Group.find(params[:id])
@group_members = @group.group_members.order("posts ASC")
end
# in my rspec
it "should show order correctly" do
@group = FactoryGirl.create(:group)
@user_1 = FactoryGirl.create(:user, user_name: "Gary")
@user_2 = FactoryGirl.create(:user, user_name: "Shawn")
@user_3 = FactoryGirl.create(:user, user_name: "Gus")
@user_4 = FactoryGirl.create(:user, user_name: "Jack")
@group_member_1 = FactoryGirl.create(:group_member, group_id: @group.id, user_id: @user_1.id, posts: 30)
@group_member_2 = FactoryGirl.create(:group_member, group_id: @group.id, user_id: @user_2.id, posts: 20)
@group_member_3 = FactoryGirl.create(:group_member, group_id: @group.id, user_id: @user_3.id, posts: 10)
@group_member_4 = FactoryGirl.create(:group_member, group_id: @group.id, user_id: @user_4.id, posts: 15)
visit group_path(@group)
# how do i assert the order of the array?
end
有人可以帮我一个声明来检查数组是否正确排序吗?