1

如何使用轮胎宝石检查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

或者可能有任何其他解决方法。

4

1 回答 1

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
于 2013-11-10T10:24:32.530 回答