正確`fixture_path`我想附加文件,從黃瓜步:定義黃瓜
When /^I attach an image/ do
page.attach_file("Image", File.join(fixture_path, "green_small.jpg"))
end
出於某種原因,這導致/home/xxx/test/fixtures/green_small.jpg
。 fixture_path的缺省位置是黃瓜中的test/fixtures
。
我正在使用rspec,所以燈具的路徑應該是spec/fixtures
。我Rspec的spec_helper.rb
有這樣配置:
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
end
我已經嘗試沒有成功config/environments/test.rb
設置此。
顯然,我可以自己簡單地建立路徑,page.attach_file("Image", File.join(Rails.root, "spec", "fixtures", "green_small.jpg"))
的作品。但那fixture_path
已經在那裏。設置正確,然後使用它,將使這些步驟變得更輕便更清潔。
但是這不被黃瓜使用。我如何在黃瓜中獲得正確的網址?
attach_file(:csv_file, File.join(RAILS_ROOT, 'features', 'upload-files', 'products_csv_ok.csv'))
好吧,顯然我可以在步驟中設置自己的路徑(我將更新問題以反映這一點)。事情是,我有一個名爲「fixtures_path」的輔助變量(方法?),它已經包含了一個目錄的路徑。只有它是錯誤的道路。設置正確,然後使用它,會使步驟更清潔。 – berkes
您可以在spec_helper.rb中創建一個名爲「fixtures_path」的方法並返回正確的路徑。我認爲這樣可以正常工作。 –