Ruby on rails 我可以使用之前:所有与水豚?

Ruby on rails 我可以使用之前:所有与水豚?,ruby-on-rails,ruby,rspec,capybara,Ruby On Rails,Ruby,Rspec,Capybara,我有这样一个描述块: describe "Documents" do subject { page } let (:course) { FactoryGirl.create(:course) } describe "new" do before do visit new_course_document_path(course) fill_in "Name", with: "TestDocument" attach_file "Origina

我有这样一个描述块:

describe "Documents" do
  subject { page }
  let (:course) { FactoryGirl.create(:course) }
  describe "new" do
    before do
      visit new_course_document_path(course)
      fill_in "Name", with: "TestDocument"
      attach_file "Original document", "#{Rails.root}/spec/fixtures/03_GUI_concurrency.pdf"
    end
    it { should have_selector('title', text:"Upload document")}
    it { should have_selector('h1', text:"Upload document")}
    describe "when clicking upload" do
      before { click_button "Upload Document" }
      it "should have the document name" do
        subject.should have_selector('p', text: "TestDocument")
      end

      it "should have 22 pages" do
        subject.should have_selector('.page', count: 22)
      end

      describe "when visiting the course page" do
        before { visit course_path(course) }
        it { should have_selector 'li', text: "TestDocument"}
      end
    end
  end
由于在保存文档方面做了大量工作,因此测试的成本相当高。这很好,但速度更慢,因为它实际上上传了3次。因此,显然要做的事情是将before块变成before:all块——但当我这样做时,只有第一个it{}块正确执行,后面的块在空页上执行,因此它们失败

是否在之前:所有块都应该与水豚一起工作,如果是,那么我在这里做错了什么?

水豚在每个示例运行之后,所以当您将
访问新的\u课程\u文档\u路径(课程)
移动到
之前(:all)
块时,从第二个示例开始,您就没有什么可访问的了


我建议只运行您正在进行的测试。这可以通过RSpec或来实现,它将为您节省大量时间。

是的,我已经将这些缓慢的测试放在它们自己的文件中,它们由CI运行。尽管如此,这似乎是相当浪费的,似乎这可以让规范在使用水豚的很多测试中运行得更快。。。