我在我的网站主页上使用 ElasticSearch。在我的验收测试中,当用户登录时,他会被重定向到主页。
但是在测试中使用 ES 很昂贵(需要创建和删除索引),所以我不想每次用户浏览主页时都必须这样做。
我只想在测试有一些元数据时才进行实际的 ES 搜索:
config.before(:each) do
if example.metadata[:elastic]
Model.create_elasticsearch_index
end
end
scenario "Results should be ordered by distance", :elastic do
# tests...
end
因此,当测试没有 :elastic 元数据时,我需要“模拟”搜索而不使用 ES。
什么是实现这一目标的好方法?