在创建工厂时测试失败

时间:2012-11-07 15:26:24

标签: ruby-on-rails factory-bot

我有一个关于与女工测试的问题:

首先是一些代码:

customesr_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

factories.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:method_missing' [#73C9383A03A6] c:/Ruby193/lib/ruby/gems/1.9.1/gems/guard-rspec-2.1.1/lib/guard/rspec/runner.rb:124:in run_via_drb&#39;

我必须在某个地方提出要求吗?我在这里缺少什么?

2 个答案:

答案 0 :(得分:1)

首先我要提一下:

我在我的Windows PC上使用Guard和Rspec和Spork。 - &GT;我添加了Spork,一旦后卫和rspec正在运行,就会有更快的测试。

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

user = FactoryGirl.create(:signup_customer)
#This is wrong! Has to be:
let(:user) {FactoryGirl.create(:signup_customer)}

答案 1 :(得分:0)

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