0

我真的希望你能帮我重构这个:

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

我真的很想将visitandshould(not) have部分放在 en extraafter(:each)块中,但这会产生令人讨厌的输出。你会怎么做?

4

1 回答 1

0

我认为重构没有多大意义。不过,您可以将路径和内容提取到过滤器(或让)之前的实例变量中,以便从一个地方进行控制。另外,我不喜欢您对规格的描述-使其更具可读性并以一种样式编写。

于 2012-12-28T18:19:11.773 回答