Ruby on rails 如何测试轮胎索引结果?
我想测试我的搜索方法,但是如何测试Ruby on rails 如何测试轮胎索引结果?,ruby-on-rails,ruby,ruby-on-rails-3,elasticsearch,tire,Ruby On Rails,Ruby,Ruby On Rails 3,elasticsearch,Tire,我想测试我的搜索方法,但是如何测试到索引的\u json结果 这是我的测试: describe Search do before do Question.index.delete Question.tire.create_elasticsearch_index app = create :app, name: "Marketing", id: 76 @question1 = create :question, content: "Some super ques
到索引的\u json
结果
这是我的测试:
describe Search do
before do
Question.index.delete
Question.tire.create_elasticsearch_index
app = create :app, name: "Marketing", id: 76
@question1 = create :question, content: "Some super question?", app: app
@question2 = create :question, content: "Some extra question?", app: app
end
describe "#results" do
it "returns matched results" do
Search.new("Some", \[76\]).results.should == \[@question1, @question2\]
end
end
end
这就是我收到的错误:
首先,您并没有在发布的代码中真正测试
到_index_json
——您正在测试对搜索结果的一些期望。这很好,实际上是更合理的做法:),但仍然是另一回事
其次,在集成测试中,请确保在索引测试数据后调用Tire::Index#refresh
,以便可以立即进行搜索——默认延迟为1秒
第三,在代码中创建一些测试模型,然后期望返回这些精确的对象。要使Tire的行为类似于此,请使用:load=>true
选项(从数据库加载模型),或者不要设置对象等价性的期望值,而是测试模型的某些属性(例如内容
)