在 Cucumber 功能中使用 ThinkingSphinx 进行搜索不会返回任何结果
我正在尝试运行一个进行搜索的功能。我添加了 ThinkingSphinx 文档建议的必要行
require 'cucumber/thinking_sphinx/external_world'
Cucumber::ThinkingSphinx::ExternalWorld.new
,并且还禁用了事务并使用 DatabaseCleaners 截断。我已经设置了功能,因此在添加用户后,我会更新 Sphinx 的索引,然后进行搜索。
Scenario: Add a client to a project
Given I have a project named "ProjectXYZ"
And I have a client named "Tom Client" with an email address "[email protected]"
And the Sphinx indexes are updated
And if I search for "Tom" which is a "Client", I have 1 result
即使用户在那里,搜索也始终返回 0 个结果。如果我检查 User.find_by_first_name("Tom").count.should eq(1) 的计数,它会成功。
以下是我的步骤:
更新索引
Given 'the Sphinx indexes are updated' do
# Update all indexes
ThinkingSphinx::Test.index
sleep(1.0) # Wait for Sphinx to catch up
end
搜索和检查结果
Given /^if I search for "([^"]*)" which is a "([^"]*)", I have (\d+) results?$/ do |query,model,count|
Rails.const_get(model).search_count(query).should == count.to_i
end
我正在使用 Rails 3.0.3、Cucumber 0.9.4 和 Cucumber-Rails 0.3.2
I am trying to run a feature where a search occurs. I added the necessary lines that the ThinkingSphinx documentation recommends
require 'cucumber/thinking_sphinx/external_world'
Cucumber::ThinkingSphinx::ExternalWorld.new
And also disabled using transactions and use DatabaseCleaners truncation instead. I have my feature setup so after I add a user, I update the index for Sphinx, and then I do a search.
Scenario: Add a client to a project
Given I have a project named "ProjectXYZ"
And I have a client named "Tom Client" with an email address "[email protected]"
And the Sphinx indexes are updated
And if I search for "Tom" which is a "Client", I have 1 result
The search always returns 0 results, even though the user is there. If I check the count for User.find_by_first_name("Tom").count.should eq(1) it succeeds.
Here are my steps:
Updating Index
Given 'the Sphinx indexes are updated' do
# Update all indexes
ThinkingSphinx::Test.index
sleep(1.0) # Wait for Sphinx to catch up
end
Searching and checking results
Given /^if I search for "([^"]*)" which is a "([^"]*)", I have (\d+) results?$/ do |query,model,count|
Rails.const_get(model).search_count(query).should == count.to_i
end
I am using Rails 3.0.3, Cucumber 0.9.4, and Cucumber-Rails 0.3.2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
到目前为止,似乎没有什么不合适的地方......如果你还没有,我建议使用 我的博客文章 而不是官方文档作为参考(后者需要更新)。
另外:您是否有使用不同端口的测试/黄瓜环境Sphinx 适合您的开发设置吗?尽管如果 Sphinx 没有在开发环境中运行,那么这应该不会妨碍。
Nothing seems out of place thus far... in case you're not already, I would recommend using my blog post instead of the official docs as a reference (the latter need updating).
Also: do you have the test/cucumber environment using a different port for Sphinx to your development setup? Although if Sphinx isn't running in dev, then that shouldn't get in the way.