2

我正在进行从 Rails 2 -> 3 升级的项目。我们正在删除 Ultrasphinx(Rails 3 不支持)并将其替换为 ThinkingSphinx。一个问题 - 用于搜索的 Cucumber 测试(过去可以工作)失败了,因为 ThinkingSphinx 没有在测试模式下对文件进行索引。

这是 env.rb 的相关部分:

require 'cucumber/thinking_sphinx/external_world'
Cucumber::ThinkingSphinx::ExternalWorld.new
Cucumber::Rails::World.use_transactional_fixtures = false

这是索引我的对象的步骤(在我的 common_steps.rb 文件中声明):

Given /^ThinkingSphinx is indexed$/ do
  puts "Indexing the new database objects"
  # Update all indexes
  ThinkingSphinx::Test.index
  sleep(0.25) # Wait for Sphinx to catch up
end

这就是我的 .feature 文件中的内容(在创建模型对象之后)

And ThinkingSphinx is indexed

这是 ThinkingSphinx 在测试模式下运行时的输出(这是错误的,它应该正在查找文档但不是)

Sphinx 0.9.9-release (r2117)
Copyright (c) 2001-2009, Andrew Aksyonoff

using config file 'C:/Users/PaulG/Programming/Projects/TechTV/config/test.sphinx.conf'...
indexing index 'collection_core'...
collected 0 docs, 0.0 MB
total 0 docs, 0 bytes
total 0.027 sec, 0 bytes/sec, 0.00 docs/sec
distributed index 'collection' can not be directly indexed; skipping.
indexing index 'video_core'...
collected 0 docs, 0.0 MB
total 0 docs, 0 bytes
total 0.018 sec, 0 bytes/sec, 0.00 docs/sec
distributed index 'video' can not be directly indexed; skipping.
total 0 reads, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
total 8 writes, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg
rotating indices: succesfully sent SIGHUP to searchd (pid=4332).

相比之下,这是我运行时得到的输出

rake ts:index

索引开发环境:

Sphinx 0.9.9-release (r2117)
Copyright (c) 2001-2009, Andrew Aksyonoff

using config file 'C:/Users/PaulG/Programming/Projects/TechTV/config/development.sphinx.conf'...
indexing index 'collection_core'...
collected 4 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 4 docs, 39 bytes
total 0.031 sec, 1238 bytes/sec, 127.04 docs/sec
distributed index 'collection' can not be directly indexed; skipping.
indexing index 'video_core'...
collected 4 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 4 docs, 62 bytes
total 0.023 sec, 2614 bytes/sec, 168.66 docs/sec
distributed index 'video' can not be directly indexed; skipping.
total 10 reads, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
total 20 writes, 0.001 sec, 0.1 kb/call avg, 0.0 msec/call avg
rotating indices: succesfully sent SIGHUP to searchd (pid=5476).

注意它是如何在我的开发数据库中实际查找文档的,而不是我的测试数据库。索引器在开发中工作,但不是测试?我已经花了 2 天的时间,并且离解决方案更近了。任何帮助将不胜感激。

4

1 回答 1

4

我今天早上想通了,希望我可以为别人省去我遇到的麻烦。看起来这不是 Cucumber 的错,而是 DatabaseCleaner 的错

我通过更改env.rb中的这一行来解决此问题:

DatabaseCleaner.strategy = :transaction

DatabaseCleaner.strategy = :truncation
于 2011-08-01T22:37:35.833 回答