You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can someone help me and confirm my approach or provide an actual (version 7.x) example how to setup a rSpec-environment for elasticsearch-rails (7.1.1) correctly? I am using Rails 6.1.x and rSpec 3.1.x.
I have doubt if my request tests are setup correctly, or if there is a better approach:
I saw examples with a Product.import and sleep 2 in specs, as well some real complex methods in the spec_helper.rb/rails_helper.rb file.
Currently I have this, it looks slim and works (till now):
rails_helper.rb
# pass 'elasticsearch: true' or ':elasticsearch' to your tests to run this codeconfig.around(:each,elasticsearch: true)do |example|
Product.__elasticsearch__.create_index!(force: true)Product.importProduct.__elasticsearch__.refresh_index!example.runProduct.__elasticsearch__.client.indices.deleteindex: Product.index_nameendconfig.after(:suite)doElasticsearch::Model.client.indices.delete(index: '_all')end
product_request_spec.rb
describe"by_name"dobefore(:each)dotarget=Fabricate:product,{name: term}Fabricate.times(3,:product)# Product.import(force: true) # sometimes it looks I have to use thatendit'respond with a pagination'dopost"/search/by_name/#{term}"expect(response.body).tohave_json_path("data")endend
approach b.) Works but very slow if test amount raise
before(:each)doProduct.__elasticsearch__.create_index!force: trueFabricate:productProduct.import(force: true)sleep2# but slowing down hundred of tests is not my favorite.end
(maybe the docs can supplied with such an example... )
Thank you in advance
The text was updated successfully, but these errors were encountered:
@exocode Having the same issue. Seems like my current setup doesn't work properly, there are inconsitencies.
I couldn't find any documentation on integrating with rspec. Can somebody please suggest something?
Hi there,
Can someone help me and confirm my approach or provide an actual (version 7.x) example how to setup a
rSpec
-environment forelasticsearch-rails (7.1.1)
correctly? I am usingRails 6.1.x
andrSpec 3.1.x
.I have doubt if my request tests are setup correctly, or if there is a better approach:
I saw examples with a
Product.import
andsleep 2
in specs, as well some real complex methods in the spec_helper.rb/rails_helper.rb file.Currently I have this, it looks slim and works (till now):
rails_helper.rb
product_request_spec.rb
Other approaches
product_request_spec.rb
approach a.) (does not work always)
approach b.) Works but very slow if test amount raise
(maybe the docs can supplied with such an example... )
Thank you in advance
The text was updated successfully, but these errors were encountered: