Skip to content

Instantly share code, notes, and snippets.

@mkcode
Created November 17, 2015 23:14
Show Gist options
  • Save mkcode/9f3dc0a36b12eabe6643 to your computer and use it in GitHub Desktop.
Save mkcode/9f3dc0a36b12eabe6643 to your computer and use it in GitHub Desktop.
require 'chewy/rspec'
# Configure rspec to work with chewy
#
# By default, all chewy requests are ignored. This is important in case
# models (or factories by extension) contain after_commit hooks
#
# If a test or example group has chewy: true set on its metadata, then
# the example is run within the update strategy which immediately
# updates the index. Also, the index is purged before every test
# so that index tests work similarly to AR with DatabaseCleaner.
RSpec.configure do |config|
config.before(:suite) do
Chewy.strategy(:bypass)
end
config.around(:each, chewy: true) do |example|
Chewy.strategy(:urgent) do
Chewy.massacre
example.run
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment