diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 3877754d..b29734ac 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2018-12-03 22:29:14 +0000 using RuboCop version 0.60.0. +# on 2018-12-04 18:23:24 +0000 using RuboCop version 0.60.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -86,12 +86,12 @@ Metrics/BlockLength: Metrics/BlockNesting: Max: 4 -# Offense count: 1 +# Offense count: 9 # Configuration parameters: CountComments. Metrics/ClassLength: Max: 315 -# Offense count: 17 +# Offense count: 18 Metrics/CyclomaticComplexity: Max: 30 @@ -103,7 +103,7 @@ Metrics/MethodLength: # Offense count: 1 # Configuration parameters: CountComments. Metrics/ModuleLength: - Max: 395 + Max: 399 # Offense count: 17 Metrics/PerceivedComplexity: @@ -329,7 +329,7 @@ Style/IfInsideElse: Exclude: - 'lib/message_bus.rb' -# Offense count: 22 +# Offense count: 23 # Cop supports --auto-correct. Style/IfUnlessModifier: Exclude: @@ -540,7 +540,7 @@ Style/SpecialGlobalVars: - 'message_bus.gemspec' - 'spec/spec_helper.rb' -# Offense count: 707 +# Offense count: 708 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. # SupportedStyles: single_quotes, double_quotes @@ -648,7 +648,7 @@ Style/ZeroLengthPredicate: - 'lib/message_bus/rack/middleware.rb' - 'spec/lib/message_bus_spec.rb' -# Offense count: 218 +# Offense count: 219 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: diff --git a/lib/message_bus.rb b/lib/message_bus.rb index 490f9e90..00cc7a41 100644 --- a/lib/message_bus.rb +++ b/lib/message_bus.rb @@ -592,7 +592,12 @@ def subscribe_impl(channel, site_id, last_id, &blk) raise MessageBus::BusDestroyed if @destroyed if last_id >= 0 - backlog(channel, last_id, site_id, inclusive: true).each do |m| + existing_messages = backlog(channel, last_id, site_id, inclusive: true) + if existing_messages.empty? + raise ArgumentError, "You tried to subscribe starting from a message that doesn't exist yet." + end + + existing_messages.each do |m| yield m end end diff --git a/spec/lib/message_bus_spec.rb b/spec/lib/message_bus_spec.rb index a152c25e..e1241a16 100644 --- a/spec/lib/message_bus_spec.rb +++ b/spec/lib/message_bus_spec.rb @@ -69,6 +69,12 @@ data1.must_equal ['bananana', "it's so fluffy"] data2.must_equal ['banana', 'bananana', "it's so fluffy"] data3.must_equal ['banana', 'bananana', "it's so fluffy"] + + lambda do + @bus.subscribe("/minion", 4) do |_msg| # This last_id doesn't exist yet + raise "Don't expect any delivery here" + end + end.must_raise ArgumentError end it "can transmit client_ids" do