sunspot_matchers gem(または単なるRSpec)でRSpecを使用して、sunspot gemを使用してコードをテストする良い例はありますか?
このエラーで何が起こっているのかを理解しようとしていますが、確かな例は見つかりません。
これが私が現在取り組んでいるモデル、スペック、スペック出力からのスニペットです:
/models/channel.rb
class Channel < ActiveRecord::Base
#...some attributes and methods here
private
# selected_facets is a hash with strings as keys
# facet_categories is an array of symbols
def self.search_results(search_query, selected_facets, facet_categories)
Channel.search do
keywords(search_query)
facet_filter = selected_facets
dynamic :facets do
facet_categories.each do |category_name|
if selected_facets.nil? or selected_facets[category_name.to_s].nil?
facet(category_name)
else
with(category_name, selected_facets[category_name.to_s])
end
end
end
end
end
end
/spec/models/channel_spec.rb
describe ".search_results" do
let(:facet_categories) { [:category1, :category2, :category3] }
let(:query) { "just a test query" }
it "should search for Channels" do
selected_facets = ""
Channel.search_results(query, selected_facets, facet_categories)
Sunspot.session.should be_a_search_for(Channel)
end
context "when there are no selected facets" do
let(:selected_facets) { nil }
it "it facets on that category name" do
channels = Channel.search_results(query, selected_facets, facet_categories)
Sunspot.session.should have_search_params(:facet, :category1)
end
end
context "when there are no selected facets for the given category name" do
it "it facets on the given category name"
end
end
RSpec出力、(r)、(y)、(g)は、失敗、保留、および合格の仕様を示します
Channel
#to_param
(g)parameterizes id and name
#remove_phone_numbers_from_tooltip_terms
(g)removes phone numbers and trailing spaces from tooltip_terms
#remove_characters_from_tooltip_terms
(g)removes non-alphanumeric characters and trailing spaces from tooltip_terms
.search_results
(g)should search for Channels
when there are no selected facets
(r)it facets on that category name (FAILED - 1)
when there are no selected facets for the given category name
(y)it facets on the given category name (PENDING: Not Yet Implemented)
Pending:
Channel.search_results when there are no selected facets for the given category name it facets on the given category name (Not Yet Implemented)
./spec/models/channel_spec.rb:53
1)
Sunspot::UnrecognizedFieldError in 'Channel.search_results when there are no selected facets it facets on that category name'
No field configured for Channel with name 'category1' ./spec/models/channel_spec.rb:48:
Finished in 0.191886 seconds
6 examples, 1 failure, 1 pending
上記のモデルでif/else条件をテストしようとしています。
何か案は?または、全体的なアプローチに関するアドバイスはありますか?
いくつかの良い例/ドキュメントは素晴らしいでしょう...または多分私はどこかで何かを逃しただけです。
ありがとう、
ケントン