Skip to content

Commit

Permalink
Wildcards should match blank values and * should only match one term.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmason committed Dec 28, 2017
1 parent 468fe86 commit fa1c7e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/bunny_mock/exchanges/topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def deliver(payload, opts, key)
# @private
def route_to_regex(key)
key = key.gsub('.', '\.')
key = key.gsub(SINGLE_WILDCARD, '(?:\w+)')
key = key.gsub(MULTI_WILDCARD, '\w+\.?')
key = key.gsub(SINGLE_WILDCARD, '(?:\w*)')
key = key.gsub(MULTI_WILDCARD, '[\w\.]*\.?')

Regexp.new(key)
Regexp.new("^#{key}$")
end
end
end
Expand Down
12 changes: 10 additions & 2 deletions spec/unit/bunny_mock/exchanges/topic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,20 @@
expect(@third.message_count).to eql 0
end

it 'should deliver for mixed wildcards' do
it 'should deliver for mixed wildcards, matching * to a single word only' do
@source.publish 'Test', routing_key: 'queue.category.sub.third'

expect(@first.message_count).to eql 1
expect(@second.message_count).to eql 1
expect(@second.message_count).to eql 0
expect(@third.message_count).to eql 1
end

it 'should allow wildcards to match blank values' do
@source.publish 'Test', routing_key: 'queue..sub'

expect(@first.message_count).to eql 1
expect(@second.message_count).to eql 1
expect(@third.message_count).to eql 0
end
end
end

0 comments on commit fa1c7e9

Please sign in to comment.