I would like to test my search method but how to test to_indexed_json
results.
Here is my test:
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
And this is error which I receive:
First, you're not really testing to_indexed_json
in the posted code -- you're testing some expectations about search results. That's fine, and actually more reasonable thing to do :), but still a different thing.
Second, in integration tests, be sure to call the Tire::Index#refresh
after you index test data, so they are immediately available to search -- the default delay is 1 second.
Third, you're creating some test models in your code, and then expect these exact objects to be returned. To make Tire behave like this, use the :load => true
option (to load the models from the database), or do not set expectations about object equivalence, but test eg. some property of your model (eg. content
).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.