Last Updated: February 25, 2016
·
565
· miguelperez

a bit faster rspec tests

Just disable all you observers and run them when necessary.

In the spec_helper.rb file:

RSpec.configure do |config|
  ActiveRecord::Base.observers.disable :all
end

and then on those specs where you need to run the observers do the following:

it "should test something" do
  ModelName.observers.enable :model_name_observer do
    # the code run here will use the observer
  end
end

1 Response
Add your response

Nice and clean. Thanks.

over 1 year ago ·