RSpec固件未加载

4

我正在接手一个代码库并尝试运行测试。 我对RSpec有些陌生,所以这可能是一个微不足道的问题。

基本上,我可以看出fixture没有被加载。 所有100个测试都以类似的错误失败。

但我不知道原因。 以下是代码。 我可以从哪里开始查找?

在我知道正在运行的spec_helper.rb文件中,我看到:

Spec::Runner.configure do |config|
  config.global_fixtures = :all
end

在spec/controllers/downloads_controller_spec.rb文件中,其中一个测试如下。我知道它正在运行,并且在'describe'之前,Partner.count == 0,因此没有使用fixture。

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe DownloadsController do
  integrate_views

  describe "when PDF is ready" do
    before(:each) do
      @registrant = Factory.create(:step_5_registrant)
      stub(@registrant).merge_pdf { `touch #{@registrant.pdf_file_path}`
}
      @registrant.generate_pdf
      @registrant.save!
    end

    it "provides a link to download the PDF" do
      get :show, :registrant_id => @registrant.to_param
      assert_not_nil assigns[:registrant]
      assert_response :success
      assert_template "show"
      assert_select "span.button a[target=_blank]"
      assert_select "span.button a[onclick]"
    end

    after(:each) do
      `rm #{@registrant.pdf_file_path}`
    end
  end

以下是各个目录中的内容:

spec/fixtures/partners.yml - which contains 2 yaml records:

sponsor:
  id: 1
  username: rtv
  email: rocky@example.com
  crypted_password:
"c8e5b51b237344fe0e72539af0cac7197f094a5e933ffacf6e7fa612363c5933f520710c6427ac31fc4c68a2d7bb48eae601c74b96e7838f9ca1a0740b67576a"
  password_salt: "Y4PPzYx2ert3vC0OhEMo"
  name: Rocky
  organization: Rock The Vote
  url: http://rockthevote.com
  address: 123 Wherever
  city: Washington
  state_id: 9
  zip_code: 20001
  phone: 555-555-1234
  survey_question_1_en: "What school did you go to?"
  survey_question_2_en: "What is your favorite musical group?"
  created_at: <%= Time.now %>
  updated_at: <%= Time.now %>
# TODO: remove partner 2 in production
partner:
  id: 2
  username: bull_winkle
  email: bull_winkle@example.com
  crypted_password:
"c8e5b51b237344fe0e72539af0cac7197f094a5e933ffacf6e7fa612363c5933f520710c6427ac31fc4c68a2d7bb48eae601c74b96e7838f9ca1a0740b67576a"
  password_salt: "Y4PPzYx2ert3vC0OhEMo"
  name: Bullwinkle
  organization: Bullwinkle, Inc.
  url: http://example.com
  address: 123 Wherever
  city: Washington
  state_id: 9
  zip_code: 20001
  phone: 555-555-1234
  survey_question_1_en: "What school did you go to?"
  survey_question_2_en: "What is your favorite musical group?"
  created_at: <%= Time.now %>
  updated_at: <%= Time.now %>
1个回答

4
也许现在已经自动完成了,你已经解决了问题,但是你有检查过你的“spec/spec_helper.rb”文件中是否包含以下内容吗?
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"

干杯


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接