在Cucumber的测试模式下,ThinkingSphinx不会返回任何结果

时间:2011-07-29 22:57:22

标签: ruby-on-rails-3 cucumber thinking-sphinx rails-3-upgrade

我正在从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).

注意它实际上是如何在我的开发数据库中查找文档,而不是我的测试数据库。索引器在dev中工作,但没有测试?我花了两天时间在这上面,并没有更接近解决方案。任何帮助都会受到压倒性的赞赏。

1 个答案:

答案 0 :(得分:4)

今天早上我想出来了,希望我可以把别人遇到的麻烦拯救出来。看起来像这不是Cucumber的错,而是DatabaseCleaner的错误

我通过在 env.rb 中更改此行修复了此问题:

DatabaseCleaner.strategy = :transaction

DatabaseCleaner.strategy = :truncation