1

factorygirl でのテストに関して問題があります。

最初のいくつかのコード:

customer_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

factory.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'

require をどこかに置く必要がありますか?ここで何が欠けていますか?

4

2 に答える 2

1

まず、これについて言及する必要があります:

Windows PCでRspecとSporkでGuardを使用していました。-> Guard と rspec が実行された後のテストを高速化するために、Spork を追加しました。

問題を解決するために私がしたこと (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.prefork ブロックを含める必要があります。これにより、メモリに常に保持できるものと、実行ごとにリロードできるものを認識できます。spork ブロックが定義された rspec ファイルがここに表示されません。

于 2012-11-10T13:29:02.360 に答える