1

我在使用 factorygirl 进行测试时遇到问题:

首先是一些代码:

customerr_spec.rb:

require 'spec_helper'


describe "customers" do
  describe "signup" do
    #FactoryGirl.find_definitions
    user = FactoryGirl.create(:signup_customer)
    it "has right data" do
      visit signup_path
      fill_in :id, :with => 2110001
      fill_in :name, :with => "AVK POLSKA Sp. zo.o."
      fill_in :email, :with => "my.email@provider.be"
      fill_in :email_confirmation, :with => "my.email@provider.be"
      click_button "Create account"
      page.should have_content("Fireprotection")
    end
end

工厂.rb

FactoryGirl.define do
  factory :signup_customer, class: Customer do
    id = 2110001
    name = "AVK POLSKA Sp. zo.o."
    email = ""
    address_1 = "ul. Jakubowska 1"
    address_2 = "Pniewy 62-045"
    zipcode = 62
    city = "Pniewy"
    currency = "PLN"
    country_id = "PL"
    contact_person_id = "AZU"
    reset_token = nil
    reset_token_init = nil
  end
end

这是我在运行该测试时遇到的错误:

Running tests with args ["--drb", "-f", "progress", "-r", "c:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-rspec-2.1.1/lib/guard/rspec/formatter.rb",
 "-f", "Guard::RSpec::Formatter", "--out", "/dev/null", "--failure-exit-code", "2", "spec"]...
  <-- take tuple(1); slave.run...
09:17:40 - ERROR - Guard::RSpec failed to achieve its <start>, exception was:

[#73C9383A03A6] DRb::DRbUnknownError: ActiveRecord:: [#73C9383A03A6] c:/Ruby193/lib/ruby/1.9.1/drb/drb.rb:1095:in method_missing' [#73C9383A03A6] c:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-rspec-2.1.1/lib/guard/rspec/runner.rb:124:inrun_via_drb'

我必须在某处提出要求吗?我在这里想念什么?

4

2 回答 2

1

首先我必须提到这一点:

我在我的 Windows 电脑上使用 Guard 和 Rspec 和 Spork。-> 我添加了 Spork,以便在 guard 和 rspec 运行后进行更快的测试。

我为解决问题所做的工作(感谢 freenode #RubyOnRails 频道。:

user = FactoryGirl.create(:signup_customer)
#This is wrong! Has to be:
let(:user) {FactoryGirl.create(:signup_customer)}
于 2012-11-09T07:49:50.947 回答
0

你有没有启动spork?您的代码中应该有一些 Spork.prefork 块,以便它知道它可以在整个时间内保留在内存中的内容以及每次运行时可以重新加载的内容。我在这里看不到您定义了 spork 块的 rspec 文件。

于 2012-11-10T13:29:02.360 回答