diff --git a/spec/support/matchers.rb b/lib/influxdb/rails/helpers/rspec_matchers.rb similarity index 58% rename from spec/support/matchers.rb rename to lib/influxdb/rails/helpers/rspec_matchers.rb index b2af3d1..21b9b20 100644 --- a/spec/support/matchers.rb +++ b/lib/influxdb/rails/helpers/rspec_matchers.rb @@ -1,4 +1,4 @@ -require File.expand_path(File.dirname(__FILE__) + "/test_client") +require_relative "../test_client" require "launchy" module InfluxDB @@ -25,11 +25,24 @@ def save_and_open_metrics ::Launchy.open(file_path) end - private - def metrics TestClient.metrics end + + RSpec.configure do |config| + config.before :each do + InfluxDB::Rails.instance_variable_set :@configuration, nil + InfluxDB::Rails.configure + + allow(InfluxDB::Rails).to receive(:client).and_return(InfluxDB::Rails::TestClient.new) + allow_any_instance_of(InfluxDB::Rails::Configuration) + .to receive(:ignored_environments).and_return(%w[development]) + + InfluxDB::Rails::TestClient.metrics.clear + end + + config.include InfluxDB::Rails::Matchers + end end end end diff --git a/spec/support/test_client.rb b/lib/influxdb/rails/test_client.rb similarity index 100% rename from spec/support/test_client.rb rename to lib/influxdb/rails/test_client.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3271e1b..e688f33 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib")) $LOAD_PATH.unshift(File.dirname(__FILE__)) require "active_support" -require File.expand_path(File.dirname(__FILE__) + "/support/matchers") +require_relative "../lib/influxdb/rails/helpers/rspec_matchers" require File.expand_path(File.dirname(__FILE__) + "/support/broken_client") ENV["RAILS_ENV"] ||= "test" @@ -29,23 +29,11 @@ # use expect syntax config.disable_monkey_patching! - # reset configuration for each spec - config.before :each do - InfluxDB::Rails.instance_variable_set :@configuration, nil - InfluxDB::Rails.configure - - allow(InfluxDB::Rails).to receive(:client).and_return(InfluxDB::Rails::TestClient.new) - allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_environments).and_return(%w[development]) - - InfluxDB::Rails::TestClient.metrics.clear - end - config.after(:each) do travel_back end config.include ActiveSupport::Testing::TimeHelpers config.include ActiveJob::TestHelper - config.include InfluxDB::Rails::Matchers config.include InfluxDB::Rails::BrokenClient end diff --git a/spec/support/broken_client.rb b/spec/support/broken_client.rb index c92c53d..4b5175b 100644 --- a/spec/support/broken_client.rb +++ b/spec/support/broken_client.rb @@ -1,5 +1,3 @@ -require File.expand_path(File.dirname(__FILE__) + "/test_client") - module InfluxDB module Rails module BrokenClient