diff --git a/spec/lib/appsignal/transmitter_spec.rb b/spec/lib/appsignal/transmitter_spec.rb index fc740d06..91067e52 100644 --- a/spec/lib/appsignal/transmitter_spec.rb +++ b/spec/lib/appsignal/transmitter_spec.rb @@ -1,6 +1,10 @@ describe Appsignal::Transmitter do + let(:options) { {} } let(:config) do - build_config(:options => { :hostname => "app1.local" }, :logger => Logger.new(log)) + build_config( + :options => { :hostname => "app1.local" }.merge(options), + :logger => Logger.new(log) + ) end let(:base_uri) { "action" } let(:log) { StringIO.new } @@ -89,9 +93,7 @@ context "with ca_file_path config option set" do context "when file does not exist" do - before do - config.config_hash[:ca_file_path] = File.join(resources_dir, "cacert.pem") - end + let(:options) { { :ca_file_path => File.join(resources_dir, "cacert.pem") } } it "ignores the config and logs a warning" do expect(response).to be_kind_of(Net::HTTPResponse) @@ -102,9 +104,7 @@ end context "when not existing file" do - before do - config.config_hash[:ca_file_path] = File.join(tmp_dir, "ca_file_that_does_not_exist") - end + let(:options) { { :ca_file_path => File.join(tmp_dir, "ca_file_that_does_not_exist") } } it "ignores the config and logs a warning" do expect(response).to be_kind_of(Net::HTTPResponse) @@ -116,8 +116,8 @@ context "when not readable file" do let(:file) { File.join(tmp_dir, "ca_file") } + let(:options) { { :ca_file_path => file } } before do - config.config_hash[:ca_file_path] = file File.open(file, "w") { |f| f.chmod 0o000 } end diff --git a/spec/lib/appsignal_spec.rb b/spec/lib/appsignal_spec.rb index c75713a7..d401dc80 100644 --- a/spec/lib/appsignal_spec.rb +++ b/spec/lib/appsignal_spec.rb @@ -376,7 +376,14 @@ def on_load end context "when config is loaded" do - before { Appsignal.configure(:production, :root_path => project_fixture_path) } + let(:options) { {} } + before do + configure( + :env => :production, + :root_path => project_fixture_path, + :options => options + ) + end it "should initialize logging" do Appsignal.start @@ -395,7 +402,7 @@ def on_load Appsignal.config[:ignore_actions] << "my action" end expect_frozen_error do - Appsignal.config.config_hash[:ignore_actions] << "my action" + Appsignal.config[:ignore_actions] << "my action" end expect_frozen_error do Appsignal.config.config_hash.merge!(:option => :value) @@ -410,8 +417,8 @@ def expect_frozen_error(&block) end context "when allocation tracking has been enabled" do + let(:options) { { :enable_allocation_tracking => true } } before do - Appsignal.config.config_hash[:enable_allocation_tracking] = true capture_environment_metadata_report_calls end @@ -426,12 +433,12 @@ def expect_frozen_error(&block) end context "when allocation tracking has been disabled" do + let(:options) { { :enable_allocation_tracking => false } } before do - Appsignal.config.config_hash[:enable_allocation_tracking] = false capture_environment_metadata_report_calls end - it "should not install the allocation event hook" do + it "doesn't install the allocation event hook" do expect(Appsignal::Extension).not_to receive(:install_allocation_event_hook) Appsignal.start expect_not_environment_metadata("ruby_allocation_tracking_enabled") @@ -439,22 +446,18 @@ def expect_frozen_error(&block) end context "when minutely metrics has been enabled" do - before do - Appsignal.config.config_hash[:enable_minutely_probes] = true - end + let(:options) { { :enable_minutely_probes => true } } - it "should start minutely" do + it "starts minutely probes" do expect(Appsignal::Probes).to receive(:start) Appsignal.start end end context "when minutely metrics has been disabled" do - before do - Appsignal.config.config_hash[:enable_minutely_probes] = false - end + let(:options) { { :enable_minutely_probes => false } } - it "should not start minutely" do + it "does not start minutely probes" do expect(Appsignal::Probes).to_not receive(:start) Appsignal.start end diff --git a/spec/support/helpers/config_helpers.rb b/spec/support/helpers/config_helpers.rb index 3fcce928..30f4b522 100644 --- a/spec/support/helpers/config_helpers.rb +++ b/spec/support/helpers/config_helpers.rb @@ -30,14 +30,18 @@ def build_config( end module_function :build_config - def start_agent(env: "production", options: {}, internal_logger: nil) + def configure(env: :default, root_path: project_fixture_path, options: {}) env = "production" if env == :default env ||= "production" - Appsignal.configure(env, :root_path => project_fixture_path) do |config| + Appsignal.configure(env, :root_path => root_path) do |config| options.each do |option, value| config.send("#{option}=", value) end end + end + + def start_agent(env: :default, options: {}, internal_logger: nil) + configure(:env => env, :options => options) Appsignal.start Appsignal.internal_logger = internal_logger if internal_logger end