尝试习惯rspec let / subject语法,我无法弄清楚。 我有这个规范:
describe Permission do
subject(:permission){FactoryGirl.create(:permission, role: role, branch: branch, user: user)}
let(:role){FactoryGirl.create(:role, name: 'master')}
let(:branch){FactoryGirl.create(:branch)}
let(:user){FactoryGirl.create(:user)}
context "role_names_by_user_and_branch" do
it "should return role names for the given user / branch pair" do
# permission.save
Permission.role_names_by_user_and_branch(user, branch).should include(role.name)
end
end
end
注意注释掉permission.save
。如果我在测试通过中添加它。
这是我不理解的部分。如果我正在FactoryGirl.create
获得该许可
应该已经保存,查询工作。
我的工厂非常基础:
FactoryGirl.define do
factory :permission do
user
branch
role
end
end