diff --git a/.rubocop.yml b/.rubocop.yml index af04751a..07cf436f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -39,5 +39,5 @@ Layout/SpaceInsideHashLiteralBraces: Naming/VariableNumber: Enabled: false -Lint/RescueWithoutErrorClass: +Style/RescueStandardError: Enabled: false diff --git a/lib/optimizely/notification_center.rb b/lib/optimizely/notification_center.rb index c30b74c0..2219833a 100644 --- a/lib/optimizely/notification_center.rb +++ b/lib/optimizely/notification_center.rb @@ -42,7 +42,6 @@ def initialize(logger, error_handler) def add_notification_listener(notification_type, notification_callback) return nil unless notification_type_valid?(notification_type) - unless notification_callback @logger.log Logger::ERROR, 'Callback can not be empty.' return nil diff --git a/optimizely-sdk.gemspec b/optimizely-sdk.gemspec index c6575428..63d108c6 100644 --- a/optimizely-sdk.gemspec +++ b/optimizely-sdk.gemspec @@ -18,9 +18,9 @@ Gem::Specification.new do |spec| spec.require_paths = ['lib'] spec.add_development_dependency 'bundler', '~> 1.10' - spec.add_development_dependency 'rake', '~> 10.0' - spec.add_development_dependency 'rspec', '~> 3.4.0' - spec.add_development_dependency 'rubocop', '~> 0.51.0' + spec.add_development_dependency 'rake', '~> 12.0' + spec.add_development_dependency 'rspec', '~> 3.7.0' + spec.add_development_dependency 'rubocop', '~> 0.56.0' spec.add_runtime_dependency 'httparty', '~> 0.11' spec.add_runtime_dependency 'json-schema', '~> 2.6' diff --git a/spec/bucketing_spec.rb b/spec/bucketing_spec.rb index 7de9f20e..d9e72f1f 100644 --- a/spec/bucketing_spec.rb +++ b/spec/bucketing_spec.rb @@ -57,7 +57,7 @@ def get_bucketing_key(bucketing_id, entity_id = nil) expect(bucketer.send(:generate_bucket_value, get_bucketing_key( 'a very very very very very very very very very very very very '\ 'very very very long ppd string' - ))).to eq(6128) + ))).to eq(6128) end it 'should return the proper variation for a user in a mutually exclusive grouped experiment' do diff --git a/spec/notification_center_spec.rb b/spec/notification_center_spec.rb index c2de7eb3..4b91993b 100644 --- a/spec/notification_center_spec.rb +++ b/spec/notification_center_spec.rb @@ -41,9 +41,8 @@ def call; end describe 'test add notification with invalid params' do it 'should log and return nil if notification type is empty' do expect(notification_center.add_notification_listener( - nil, - @callback_reference - )).to eq(nil) + nil, @callback_reference + )).to eq(nil) expect(spy_logger).to have_received(:log).once .with(Logger::ERROR, 'Notification type can not be empty.') end @@ -52,7 +51,7 @@ def call; end expect(notification_center.add_notification_listener( Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE], nil - )).to eq(nil) + )).to eq(nil) expect(spy_logger).to have_received(:log).once .with(Logger::ERROR, 'Callback can not be empty.') end @@ -61,7 +60,7 @@ def call; end expect(notification_center.add_notification_listener( 'Test notification type', @callback_reference - )).to eq(nil) + )).to eq(nil) expect(spy_logger).to have_received(:log).once .with(Logger::ERROR, 'Invalid notification type.') end @@ -70,7 +69,7 @@ def call; end expect(notification_center.add_notification_listener( Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE], 'Invalid callback!' - )).to eq(nil) + )).to eq(nil) expect(spy_logger).to have_received(:log).once .with(Logger::ERROR, 'Invalid notification callback given.') end @@ -81,7 +80,7 @@ def call; end expect(notification_center.add_notification_listener( Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE], @callback_reference - )).to eq(1) + )).to eq(1) # verifies that one notification is added expect(notification_center.notifications[Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE]].length) .to eq(1) @@ -95,7 +94,7 @@ def call; end expect(notification_center.add_notification_listener( value, @callback_reference - )).to eq(notification_id) + )).to eq(notification_id) end notification_center.notifications.each_key do |key| expect(notification_center.notifications[key].length) @@ -141,19 +140,19 @@ def call; end expect(notification_center.add_notification_listener( Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE], @callback_reference - )).to eq(-1) + )).to eq(-1) end it 'should add same callback for a different notification type' do expect(notification_center.add_notification_listener( Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE], @callback_reference - )).to eq(1) + )).to eq(1) expect(notification_center.add_notification_listener( Optimizely::NotificationCenter::NOTIFICATION_TYPES[:TRACK], @callback_reference - )).to eq(2) + )).to eq(2) end end @@ -169,18 +168,18 @@ def call; end expect(@inner_notification_center.add_notification_listener( Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE], @callback_reference - )).to eq(1) + )).to eq(1) expect(@inner_notification_center.add_notification_listener( Optimizely::NotificationCenter::NOTIFICATION_TYPES[:TRACK], @callback_reference - )).to eq(2) + )).to eq(2) # add another callback for NOTIFICATION_TYPES::ACTIVATE expect(@inner_notification_center.add_notification_listener( Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE], @callback_reference_second - )).to eq(3) + )).to eq(3) # Verify that notifications length for NOTIFICATION_TYPES::ACTIVATE is 2 expect(@inner_notification_center.notifications[ Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE]].length).to eq(2) @@ -338,27 +337,27 @@ def call; end expect(@inner_notification_center.add_notification_listener( Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE], @callback_reference - )).to eq(1) + )).to eq(1) expect(@inner_notification_center.add_notification_listener( Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE], @callback_reference_second - )).to eq(2) + )).to eq(2) expect(@inner_notification_center.add_notification_listener( Optimizely::NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE], @callback_reference_third - )).to eq(3) + )).to eq(3) expect(@inner_notification_center.add_notification_listener( Optimizely::NotificationCenter::NOTIFICATION_TYPES[:TRACK], @callback_reference - )).to eq(4) + )).to eq(4) expect(@inner_notification_center.add_notification_listener( Optimizely::NotificationCenter::NOTIFICATION_TYPES[:TRACK], @callback_reference_second - )).to eq(5) + )).to eq(5) # verify that notifications length for each type reflects the just added callbacks diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c41da7fa..63b4a3d6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -17,7 +17,7 @@ # require 'coveralls' Coveralls.wear! -$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) +$LOAD_PATH.unshift File.expand_path('../lib', __dir__) require 'optimizely' require 'spec_params'