Skip to content

Commit

Permalink
Clean up initial support for verbose logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristandunn committed Feb 12, 2014
1 parent 04b115c commit f0e1a96
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 24 deletions.
4 changes: 2 additions & 2 deletions lib/pusher-fake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def self.javascript(options = {})
"new Pusher(#{arguments})"
end

def self.info(message)
def self.log(message)
if configuration.verbose
configuration.logger.info(message)
configuration.logger << "#{message}\n"
end
end
end
4 changes: 2 additions & 2 deletions lib/pusher-fake/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Configuration
# @return [String] The Pusher API key. (Defaults to +PUSHER_API_KEY+.)
attr_accessor :key

# @return [Logger] Instance of a Logger class for verbose logging.
# @return [IO] An IO instance for verbose logging.
attr_accessor :logger

# @return [String] The Pusher API token. (Defaults to +PUSHER_API_SECRET+.)
Expand All @@ -32,7 +32,7 @@ class Configuration
def initialize
self.app_id = "PUSHER_APP_ID"
self.key = "PUSHER_API_KEY"
self.logger = Logger.new(STDOUT)
self.logger = STDOUT.to_io
self.secret = "PUSHER_API_SECRET"
self.verbose = false
self.webhooks = []
Expand Down
14 changes: 1 addition & 13 deletions spec/lib/pusher-fake/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,14 @@
describe PusherFake::Configuration do
it { should have_configuration_option(:app_id).with_default("PUSHER_APP_ID") }
it { should have_configuration_option(:key).with_default("PUSHER_API_KEY") }
it { should have_configuration_option(:logger) }
it { should have_configuration_option(:logger).with_default(STDOUT.to_io) }
it { should have_configuration_option(:secret).with_default("PUSHER_API_SECRET") }
it { should have_configuration_option(:socket_options).with_default({ host: "127.0.0.1", port: 8080 }) }
it { should have_configuration_option(:verbose).with_default(false) }
it { should have_configuration_option(:web_options).with_default({ host: "127.0.0.1", port: 8081 }) }
it { should have_configuration_option(:webhooks).with_default([]) }
end

describe PusherFake::Configuration, "#logger" do
let(:logger) { mock }

before do
Logger.stubs(:new).with(STDOUT).returns(logger)
end

it "defaults to Logger on STDOUT" do
subject.logger.should == logger
end
end

describe PusherFake::Configuration, "#to_options" do
it "includes the socket host as wsHost" do
subject.to_options.should include(wsHost: subject.socket_options[:host])
Expand Down
14 changes: 7 additions & 7 deletions spec/lib/pusher_fake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
end
end

describe PusherFake, ".info" do
let(:logger) { stub(info: true) }
describe PusherFake, ".log" do
let(:logger) { stub(:<< => "") }
let(:message) { "Hello world." }
let(:configuration) { subject.configuration }

Expand All @@ -70,19 +70,19 @@
configuration.logger = logger
end

it "forwards message to Logger#info when verbose" do
it "forwards message to logger when verbose" do
configuration.verbose = true

subject.info(message)
subject.log(message)

logger.should have_received(:info).with(message).once
logger.should have_received(:<<).with(message + "\n").once
end

it "does not forward message when not verbose" do
configuration.verbose = false

subject.info(message)
subject.log(message)

logger.should have_received(:info).never
logger.should have_received(:<<).never
end
end

0 comments on commit f0e1a96

Please sign in to comment.