如何使用tire gem检入rspec
测试:ElasticSearch索引中是否存在文档?
示例:
#model
class Car
include Mongoid::Document
include include Tire::Model::Search
include Tire::Model::Callbacks
#...
end
#spec
record = Car.first
record.tire.exist_in_index?.should be_true #wrong code
或者可能是其他任何解决方法。
答案 0 :(得分:1)
您应该创建自定义匹配器:
RSpec::Matchers.define :be_in_search_index do |expected|
match do |actual|
!!actual.tire.index.retrieve(actual.class.name.underscore, actual.id.to_s)
end
end
#...
record.should be_in_search_index