【发布时间】:2012-03-20 12:37:23
【问题描述】:
我有一个这样的描述块:
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 {} 块被正确执行,之后的块在空页面上执行,所以它们失败了。
之前:所有块都应该与水豚一起使用,如果是这样,我在这里做错了什么?
【问题讨论】:
标签: ruby-on-rails ruby rspec capybara