From a00acc0824953ad6e9b8f00fb4cec07c70a6872e Mon Sep 17 00:00:00 2001 From: Joey Geiger Date: Thu, 5 Jun 2014 11:53:00 -0600 Subject: [PATCH 1/2] Fix rspec deprecation warnings --- spec/abstract_logger_spec.rb | 2 +- spec/configurable_spec.rb | 8 ++++---- spec/initializer_spec.rb | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/abstract_logger_spec.rb b/spec/abstract_logger_spec.rb index 8affbb2..5fc3595 100644 --- a/spec/abstract_logger_spec.rb +++ b/spec/abstract_logger_spec.rb @@ -67,7 +67,7 @@ IO.readlines( @log_file ).last.should match(/\[ANY\].*Unknown test/) end - pending "should log the caller file and line number" do + skip "should log the caller file and line number" do f = File.basename(__FILE__) l = __LINE__ + 2 diff --git a/spec/configurable_spec.rb b/spec/configurable_spec.rb index f200799..4de47a3 100644 --- a/spec/configurable_spec.rb +++ b/spec/configurable_spec.rb @@ -16,21 +16,21 @@ class FooConfig it "should support default values" do lambda { - @foo.has_default.should be_true - }.should_not raise_error( NoMethodError ) + @foo.has_default.should be_truthy + }.should_not raise_error end it "should support overwriting unlocked defaults" do lambda { @foo.has_default = false - @foo.has_default.should be_false + @foo.has_default.should be_falsey }.should_not raise_error end it "should support no default values" do lambda { @foo.no_default.should be_nil - }.should_not raise_error( NoMethodError ) + }.should_not raise_error end it "should allow setting locked values once" do diff --git a/spec/initializer_spec.rb b/spec/initializer_spec.rb index 26ceeb9..d06e04f 100644 --- a/spec/initializer_spec.rb +++ b/spec/initializer_spec.rb @@ -12,7 +12,7 @@ it "should configure threads to abort on exceptions" do subject.configure_exception_handling - expect( Thread.abort_on_exception ).to be_true + expect( Thread.abort_on_exception ).to be_truthy end it "should not configure safely if the gem isn't available" do From 21ab7a819a16f221e60755dd8ae375d2ec3c373c Mon Sep 17 00:00:00 2001 From: Joey Geiger Date: Thu, 5 Jun 2014 13:20:11 -0600 Subject: [PATCH 2/2] Prepend DAEMON_ROOT if passed log_path is relative When running locally on a Mac, it seems that passing a relative path to the log argument doesn't create the expected log file. This will prepend the DAEMON_ROOT to the passed in path if needed so we get a good path. --- lib/daemon_kit/abstract_logger.rb | 10 +++++++++- spec/abstract_logger_spec.rb | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/daemon_kit/abstract_logger.rb b/lib/daemon_kit/abstract_logger.rb index 6b80203..6cd3e85 100644 --- a/lib/daemon_kit/abstract_logger.rb +++ b/lib/daemon_kit/abstract_logger.rb @@ -42,7 +42,7 @@ def initialize( log_path = nil ) if log_path.to_s == "syslog" @backend = :syslog else - @logger_file = log_path || "#{DAEMON_ROOT}/log/#{DAEMON_ENV}.log" + @logger_file = set_logger_file(log_path) @backend = :logger end @@ -194,6 +194,14 @@ def create_logger end end + def set_logger_file(log_path) + if log_path + log_path.start_with?('/') ? log_path : [DAEMON_ROOT, log_path].join('/') + else + "#{DAEMON_ROOT}/log/#{DAEMON_ENV}.log" + end + end + def create_standard_logger log_path = File.dirname( @logger_file ) unless File.directory?( log_path ) diff --git a/spec/abstract_logger_spec.rb b/spec/abstract_logger_spec.rb index 5fc3595..13b705d 100644 --- a/spec/abstract_logger_spec.rb +++ b/spec/abstract_logger_spec.rb @@ -8,6 +8,20 @@ @logger.level = :debug end + context "custom log files" do + it "should set relative log files" do + @log_file = "log/spec_custom.log" + @logger = DaemonKit::AbstractLogger.new( @log_file ) + expect(@logger.instance_variable_get("@logger_file")).to eq("#{DAEMON_ROOT}/log/spec_custom.log") + end + + it "should set absolute log files" do + @log_file = "/var/log/spec_custom.log" + @logger = DaemonKit::AbstractLogger.new( @log_file ) + expect(@logger.instance_variable_get("@logger_file")).to eq("/var/log/spec_custom.log") + end + end + it "should have a log level" do @logger.level.should == :debug end