spec/ratchetio_spec.rb in ratchetio-0.4.4 vs spec/ratchetio_spec.rb in ratchetio-0.4.5
- old
+ new
@@ -1,5 +1,6 @@
+require 'logger'
require 'socket'
require 'spec_helper'
describe Ratchetio do
@@ -18,16 +19,16 @@
end
let(:logger_mock) { double("Rails.logger").as_null_object }
it 'should report exceptions without person or request data' do
- logger_mock.should_receive(:info).with('[Ratchet.io] Sending payload')
+ logger_mock.should_receive(:info).with('[Ratchet.io] Success')
Ratchetio.report_exception(@exception)
end
it 'should not report anything when disabled' do
- logger_mock.should_not_receive(:info).with('[Ratchet.io] Sending payload')
+ logger_mock.should_not_receive(:info).with('[Ratchet.io] Success')
Ratchetio.configure do |config|
config.enabled = false
end
Ratchetio.report_exception(@exception)
@@ -36,11 +37,11 @@
config.enabled = true
end
end
it 'should report exceptions with request and person data' do
- logger_mock.should_receive(:info).with('[Ratchet.io] Sending payload')
+ logger_mock.should_receive(:info).with('[Ratchet.io] Success')
request_data = {
:params => { :foo => "bar" },
:url => 'http://localhost/',
:user_ip => '127.0.0.1',
:headers => {},
@@ -83,16 +84,16 @@
end
let(:logger_mock) { double("Rails.logger").as_null_object }
it 'should report simple messages' do
- logger_mock.should_receive(:info).with('[Ratchet.io] Sending payload')
+ logger_mock.should_receive(:info).with('[Ratchet.io] Success')
Ratchetio.report_message("Test message")
end
it 'should not report anything when disabled' do
- logger_mock.should_not_receive(:info).with('[Ratchet.io] Sending payload')
+ logger_mock.should_not_receive(:info).with('[Ratchet.io] Success')
Ratchetio.configure do |config|
config.enabled = false
end
Ratchetio.report_message("Test message that should be ignored")
@@ -101,11 +102,11 @@
config.enabled = true
end
end
it 'should report messages with extra data' do
- logger_mock.should_receive(:info).with('[Ratchet.io] Sending payload')
+ logger_mock.should_receive(:info).with('[Ratchet.io] Success')
Ratchetio.report_message("Test message with extra data", 'debug', :foo => "bar",
:hash => { :a => 123, :b => "xyz" })
end
it 'should not crash with circular extra_data' do
@@ -177,24 +178,48 @@
frames = trace[:frames]
frames.should be_a_kind_of(Array)
frames.each do |frame|
frame[:filename].should be_a_kind_of(String)
- frame[:method].should be_a_kind_of(String)
frame[:lineno].should be_a_kind_of(Fixnum)
+ if frame[:method]
+ frame[:method].should be_a_kind_of(String)
+ end
end
- trace[:exception][:class].should == 'NameError'
- trace[:exception][:message].should match(/^undefined local variable or method `bar' for/)
+ # should be NameError, but can be NoMethodError sometimes on rubinius 1.8
+ # http://yehudakatz.com/2010/01/02/the-craziest-fing-bug-ive-ever-seen/
+ trace[:exception][:class].should match(/NameError|NoMethodError/)
+ trace[:exception][:message].should match(/^undefined local variable or method `bar'/)
end
end
context 'logger' do
- it 'should have its logger configured' do
+ before(:each) do
+ reset_configuration
+ end
+
+ it 'should have use the Rails logger when configured to do so' do
configure
Ratchetio.send(:logger).should == ::Rails.logger
end
+
+ it 'should use the default_logger when no logger is set' do
+ logger = Logger.new(STDERR)
+ Ratchetio.configure do |config|
+ config.default_logger = lambda { logger }
+ end
+ Ratchetio.send(:logger).should == logger
+ end
+
+ it 'should have a default default_logger' do
+ Ratchetio.send(:logger).should_not be_nil
+ end
+
+ after(:each) do
+ reset_configuration
+ end
end
context 'build_payload' do
it 'should build valid json' do
json = Ratchetio.send(:build_payload, {:foo => {:bar => "baz"}})
@@ -246,14 +271,41 @@
# configure with some basic params
def configure
Ratchetio.configure do |config|
# special test access token
- config.access_token = 'aaaabbbbccccddddeeeeffff00001111'
+ config.access_token = test_access_token
config.logger = ::Rails.logger
config.environment = ::Rails.env
config.root = ::Rails.root
config.framework = "Rails: #{::Rails::VERSION::STRING}"
+ end
+ end
+
+ def test_access_token
+ 'aaaabbbbccccddddeeeeffff00001111'
+ end
+
+ def reset_configuration
+ Ratchetio.configure do |config|
+ config.access_token = nil
+ config.branch = nil
+ config.default_logger = lambda { Logger.new(STDERR) }
+ config.enabled = true
+ config.endpoint = Ratchetio::Configuration::DEFAULT_ENDPOINT
+ config.environment = nil
+ config.exception_level_filters = {
+ 'ActiveRecord::RecordNotFound' => 'warning',
+ 'AbstractController::ActionNotFound' => 'warning',
+ 'ActionController::RoutingError' => 'warning'
+ }
+ config.framework = 'Plain'
+ config.logger = nil
+ config.person_method = 'current_user'
+ config.person_id_method = 'id'
+ config.person_username_method = 'username'
+ config.person_email_method = 'email'
+ config.root = nil
end
end
end