3

私は、、、を使用しrailsmongoidsporkますrspec

経由でテストを実行してrspecいるときに、データベース内のレコード数が増えていることがわかります。どちらpurge!database_cleaner役に立ちませんでした。

私のテストは次のとおりです。

describe MyConvertor do
  context 'working with my model'
    before(:each) do
      FactoryGirl.create :my_model
    end
    # examples go here
  end
end

そして、私の仕様ヘルパーは次のとおりです。

Spork.each_run do
  RSpec.configure do |config|
    # ...
    config.before(:each) do
      Mongoid.purge!
    end
    # ...
  end
end

前に述べたように、私も試しdatabase_cleanerてみましたが、状況は変わりませんでした:

Spork.prefork do
  RSpec.configure do |config|
    config.order = "random"
    config.use_transactional_fixtures = false
  end
end

Spork.each_run do
  RSpec.configure do |config|
    config.before(:suite) do
      DatabaseCleaner[:mongoid].strategy = :truncation
    end

    config.before(:each) do
      DatabaseCleaner.start
    end

    config.after(:each) do
      DatabaseCleaner.clean
    end
  end
end

だから私は一度にいくつかの質問があります.purge!なぜ何もしないのか、そしてなぜDatabaseCleanerうまくいかないのか.

データベース クリーナーの問題が見つかりましたが、有効な解決策はありません。

私は使っている

rails 3.2.11
mongoid 3.0.23
4

1 に答える 1

1

私はMac OSX el capitainでこれを持っていました:

端末上:

brew doctor

この警告が表示されました:

"Warning: /usr/bin occurs before /usr/local/bin This means that system-provided programs will be used instead of those provided by Homebrew."

次に、「usr/local/bin」と「/usr/local/sbin」が一番上になるように、/etc/paths の順序を変更する必要がありました。

端末で再び:

sudo vi /etc/paths

/usr/local/bin
/usr/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin

これは、私がそれを持っていたときの問題を解決しました。

于 2016-06-08T00:21:49.660 に答える