ruby-on-rails - RSpec 夹具未加载

标签 ruby-on-rails ruby-on-rails-3 rspec

我正在接管一个代码库并试图运行测试。我是
RSpec 有点新,所以这可能是一个微不足道的问题。

基本上我可以说灯具没有加载。全部 100
测试失败并出现类似错误。

但我不知道为什么。下面是代码。你能看到任何东西或给我一个线索在哪里看。到目前为止,我是空的......

谢谢!

皮托萨拉斯

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

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

spec/controllers/downloads_controller_spec.rb 中的测试之一
在下面。我知道它正在运行,我知道在“描述”之前,
Partner.count == 0,所以没有固定装置。
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 %>

最佳答案

也许这现在自动完成并且您已经解决了它,但是您是否检查过您的“spec/spec_helper.rb”包含:

# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"

干杯

关于ruby-on-rails - RSpec 夹具未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9824819/

相关文章:

ruby - 在特定命名空间中测试

ruby-on-rails-3 - 混合 has_one 和 has_and_belongs_to_many 关联

ruby-on-rails - 如何使用 Active Storage 保留存储空间和加载时间?

ruby-on-rails - 使用 API key 时如何跳过设计身份验证?

javascript - 停止 element.style 覆盖我的 css 样式

ruby-on-rails-3 - 如何使用mailman处理传入的邮件并将其更新到数据库中

ruby-on-rails - 有没有办法从 Rails 控制台查看方法的源代码?

ruby-on-rails - spec/rails_helper.rb 与 spec/spec_helper.rb 有何不同?我需要它吗?

ruby-on-rails - 无法在 ruby​​ rspec 中解析哈希

ruby-on-rails - 我如何在 Rails 的 lib 类中访问 session