Ruby on rails 重构资源规范,要将不同的角色分组(rspec rails)
我真的希望你能帮我重构这个:Ruby on rails 重构资源规范,要将不同的角色分组(rspec rails),ruby-on-rails,rspec,Ruby On Rails,Rspec,我真的希望你能帮我重构这个: context "a deactivated resource" do before(:each) @resource = FactoryGirl.create(:deactivatedresource) end it "does not show in the search (as registred User)" do as_user # does the log in visit pat
context "a deactivated resource" do
before(:each)
@resource = FactoryGirl.create(:deactivatedresource)
end
it "does not show in the search (as registred User)" do
as_user # does the log in
visit path_to_search_page
page.should_not have_content @resource.name
end
it "is visible to the resource owner" do
as_resource_owner(@resource)
visit path_to_search_page
page.should_have content @resource.name
end
it "as unregistred user" do
as_unregistred_user # checks for log out and logs out if necessary
visit path_to_search_page
page.should_not have_content @resource.name
end
我真的想在(:each)块之后,将访问和应该(不应该)在en extra中包含部分,但这会产生令人讨厌的输出。
您将如何做到这一点?我认为重构没有多大意义。不过,您可以在before filter(或let)中提取实例变量的路径和内容,以便从一个位置进行控制。另外,我不喜欢你对规格的描述——让它更具可读性,并用一种风格书写