lapine 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +39 -0
- data/lib/lapine/exchange.rb +1 -1
- data/lib/lapine/test/exchange.rb +83 -0
- data/lib/lapine/test/rspec_helper.rb +19 -0
- data/lib/lapine/version.rb +1 -1
- metadata +5 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: db131a0aa239e502ac31258568eb2180c3699c95
         | 
| 4 | 
            +
              data.tar.gz: c2c3302d3ced52aa11d78d477241be7af4183cf7
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9a29396753fe50307e752fd5a06cd1f02ddf64b011ca65869be06b770d47e68492c88cd8bec89019a6d2a70fe3bc658e2047f6f6895f0ea0ea8f84d8acfde102
         | 
| 7 | 
            +
              data.tar.gz: 67122efa1ccb92aa40b0e5237e5218e05c55d30aa1f26e0f9350a62d0d7c8912172a1af1d7537b4b78c593b23e7f5e257864a8d0c6975b691167b0e53149b627
         | 
    
        data/README.md
    CHANGED
    
    | @@ -78,6 +78,45 @@ are arbitrary. | |
| 78 78 | 
             
              complex or assumed very specific configurations different from what
         | 
| 79 79 | 
             
              we want.
         | 
| 80 80 |  | 
| 81 | 
            +
             | 
| 82 | 
            +
            ## Testing
         | 
| 83 | 
            +
             | 
| 84 | 
            +
            Lapine comes with helpers to stub out calls to RabbitMQ. This allows you
         | 
| 85 | 
            +
            to write tests using Lapine, without having to actually run RabbitMQ in
         | 
| 86 | 
            +
            your test suite.
         | 
| 87 | 
            +
             | 
| 88 | 
            +
            ```ruby
         | 
| 89 | 
            +
            require 'lapine/test/rspec_helper'
         | 
| 90 | 
            +
             | 
| 91 | 
            +
            RSpec.configure do |config|
         | 
| 92 | 
            +
              config.include Lapine::Test::RSpecHelper, fake_rabbit: true
         | 
| 93 | 
            +
             | 
| 94 | 
            +
              config.before :each, :fake_rabbit do |example|
         | 
| 95 | 
            +
                Lapine::Test::RSpecHelper.setup(example)
         | 
| 96 | 
            +
              end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
              config.after :each, :fake_rabbit do
         | 
| 99 | 
            +
                Lapine::Test::RSpecHelper.teardown
         | 
| 100 | 
            +
              end
         | 
| 101 | 
            +
            end
         | 
| 102 | 
            +
            ```
         | 
| 103 | 
            +
             | 
| 104 | 
            +
            An example test would look something like this:
         | 
| 105 | 
            +
             | 
| 106 | 
            +
            ```ruby
         | 
| 107 | 
            +
            RSpec.describe MyPublisher, fake_rabbit: true do
         | 
| 108 | 
            +
              let(:exchange) { Lapine.find_exchange('my.topic') }
         | 
| 109 | 
            +
              let(:queue) { exchange.channel.queue.bind(exchange) }
         | 
| 110 | 
            +
             | 
| 111 | 
            +
              describe 'publishing' do
         | 
| 112 | 
            +
                it 'adds a message to a queue' do
         | 
| 113 | 
            +
                  MyPublisher.new.publish('my.things')
         | 
| 114 | 
            +
                  expect(queue.message_count).to eq(1)
         | 
| 115 | 
            +
                end
         | 
| 116 | 
            +
              end
         | 
| 117 | 
            +
            end
         | 
| 118 | 
            +
            ```
         | 
| 119 | 
            +
             | 
| 81 120 | 
             
            ## Contributing
         | 
| 82 121 |  | 
| 83 122 | 
             
            1. Fork it ( https://github.com/[my-github-username]/lapine/fork )
         | 
    
        data/lib/lapine/exchange.rb
    CHANGED
    
    
| @@ -0,0 +1,83 @@ | |
| 1 | 
            +
            module Lapine
         | 
| 2 | 
            +
              module Test
         | 
| 3 | 
            +
                class FakeChannel
         | 
| 4 | 
            +
                  attr_reader :queues
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  def initialize
         | 
| 7 | 
            +
                    @queues = {}
         | 
| 8 | 
            +
                  end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  def queue(name = nil, opts = {})
         | 
| 11 | 
            +
                    @queues[name] ||= FakeQueue.new
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                class FakeExchange
         | 
| 16 | 
            +
                  attr_reader :histories
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  def initialize
         | 
| 19 | 
            +
                    @histories = []
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  def channel
         | 
| 23 | 
            +
                    @channel ||= FakeChannel.new
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  def bind(history)
         | 
| 27 | 
            +
                    histories << history
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  def publish(body, routing_key = nil)
         | 
| 31 | 
            +
                    histories.each do |h|
         | 
| 32 | 
            +
                      h.publish(body, routing_key)
         | 
| 33 | 
            +
                    end
         | 
| 34 | 
            +
                  end
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                class FakeQueue
         | 
| 38 | 
            +
                  attr_reader :history
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  def bind(exchange)
         | 
| 41 | 
            +
                    @history = MessageHistory.new
         | 
| 42 | 
            +
                    exchange.bind history
         | 
| 43 | 
            +
                    self
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                  def message_count
         | 
| 47 | 
            +
                    history.message_count
         | 
| 48 | 
            +
                  end
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                class MessageHistory
         | 
| 52 | 
            +
                  attr_reader :messages
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                  def initialize
         | 
| 55 | 
            +
                    @messages = []
         | 
| 56 | 
            +
                  end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                  def publish(body, routing_key)
         | 
| 59 | 
            +
                    messages << [body, routing_key]
         | 
| 60 | 
            +
                  end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                  def message_count
         | 
| 63 | 
            +
                    messages.size
         | 
| 64 | 
            +
                  end
         | 
| 65 | 
            +
                end
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                class Exchange
         | 
| 68 | 
            +
                  attr_reader :name
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                  def initialize(name, properties)
         | 
| 71 | 
            +
                    @name = name
         | 
| 72 | 
            +
                  end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                  def exchange
         | 
| 75 | 
            +
                    @exchange ||= FakeExchange.new
         | 
| 76 | 
            +
                  end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                  def close!
         | 
| 79 | 
            +
                    true
         | 
| 80 | 
            +
                  end
         | 
| 81 | 
            +
                end
         | 
| 82 | 
            +
              end
         | 
| 83 | 
            +
            end
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            require 'lapine/test/exchange'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Lapine
         | 
| 4 | 
            +
              module Test
         | 
| 5 | 
            +
                module RSpecHelper
         | 
| 6 | 
            +
                  def self.setup(example)
         | 
| 7 | 
            +
                    example.allow(Lapine::Exchange).to(
         | 
| 8 | 
            +
                      example.receive(:new) { |name, properties|
         | 
| 9 | 
            +
                        Lapine::Test::Exchange.new(name, properties)
         | 
| 10 | 
            +
                      }
         | 
| 11 | 
            +
                    )
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  def self.teardown
         | 
| 15 | 
            +
                    Lapine.close_connections!
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
    
        data/lib/lapine/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: lapine
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Eric Saxby
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2014-11- | 
| 12 | 
            +
            date: 2014-11-26 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: bunny
         | 
| @@ -114,6 +114,8 @@ files: | |
| 114 114 | 
             
            - lib/lapine/configuration.rb
         | 
| 115 115 | 
             
            - lib/lapine/exchange.rb
         | 
| 116 116 | 
             
            - lib/lapine/publisher.rb
         | 
| 117 | 
            +
            - lib/lapine/test/exchange.rb
         | 
| 118 | 
            +
            - lib/lapine/test/rspec_helper.rb
         | 
| 117 119 | 
             
            - lib/lapine/version.rb
         | 
| 118 120 | 
             
            - spec/lib/lapine/publisher_spec.rb
         | 
| 119 121 | 
             
            - spec/lib/lapine_spec.rb
         | 
| @@ -138,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 138 140 | 
             
                  version: '0'
         | 
| 139 141 | 
             
            requirements: []
         | 
| 140 142 | 
             
            rubyforge_project: 
         | 
| 141 | 
            -
            rubygems_version: 2. | 
| 143 | 
            +
            rubygems_version: 2.4.4
         | 
| 142 144 | 
             
            signing_key: 
         | 
| 143 145 | 
             
            specification_version: 4
         | 
| 144 146 | 
             
            summary: Talk to rabbits
         |