【发布时间】:2015-06-27 00:18:12
【问题描述】:
我的搜索控制器会这样做:
search = Sunspot.search(Item) do
fulltext params[:q] do
fields(:foo, :bar, :bletch)
end
end
在我的 rspec 控制器测试中,我有以下内容:
get :show, :q => q
expect(Sunspot.session).to have_search_params(:fulltext, q, proc do
fields(:foo, :bar, :bletch)
end)
旁注:当我尝试使用块而不是 proc 时,该块从未被执行:
have_search_params(:fulltext, q) do
# This block was never executed
end
我的 support/sunspot.rb 仅包含以下内容:
Sunspot.session = SunspotMatchers::SunspotSessionSpy.new(Sunspot.session)
当我运行测试时,我收到以下错误:
1) SearchController GET search when a user runs a search performs a fulltext search on the right fields
Failure/Error: fields(:foo, :bar, :bletch)
NoMethodError:
undefined method `fields' for #<Sunspot::DSL::Search:0x007fa0f0da0168>
# ./spec/controllers/search_controller_spec.rb:28:in `block (5 levels) in <top (required)>'
# ./spec/controllers/search_controller_spec.rb:27:in `block (4 levels) in <top (required)>'
在进行全文搜索时,测试控制器是否提供正确参数的正确方法是什么?查询此问题时,Google 没有产生相关结果。
【问题讨论】:
标签: ruby-on-rails ruby rspec sunspot