http_stub 0.5.5 → 0.5.6
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.
- data/lib/http_stub.rb +2 -2
- data/lib/http_stub/configurer.rb +3 -3
- data/lib/http_stub/configurer/post_initialize_command_processor.rb +21 -0
- data/lib/http_stub/configurer/pre_initialize_command_processor.rb +21 -0
- data/lib/http_stub/version.rb +1 -1
- data/spec/lib/http_stub/configurer/post_initialize_command_processor_spec.rb +34 -0
- data/spec/lib/http_stub/configurer/pre_initialize_command_processor_spec.rb +47 -0
- data/spec/lib/http_stub/configurer_integration_spec.rb +22 -1
- metadata +9 -9
- data/lib/http_stub/configurer/buffered_command_processor.rb +0 -24
- data/lib/http_stub/configurer/immediate_command_processor.rb +0 -17
- data/spec/lib/http_stub/configurer/buffered_command_processor_spec.rb +0 -47
- data/spec/lib/http_stub/configurer/immediate_command_processor_spec.rb +0 -34
    
        data/lib/http_stub.rb
    CHANGED
    
    | @@ -23,6 +23,6 @@ require File.expand_path('../http_stub/server', __FILE__) | |
| 23 23 | 
             
            require File.expand_path('../http_stub/configurer/stub_request', __FILE__)
         | 
| 24 24 | 
             
            require File.expand_path('../http_stub/configurer/stub_activator_request', __FILE__)
         | 
| 25 25 | 
             
            require File.expand_path('../http_stub/configurer/command', __FILE__)
         | 
| 26 | 
            -
            require File.expand_path('../http_stub/configurer/ | 
| 27 | 
            -
            require File.expand_path('../http_stub/configurer/ | 
| 26 | 
            +
            require File.expand_path('../http_stub/configurer/pre_initialize_command_processor', __FILE__)
         | 
| 27 | 
            +
            require File.expand_path('../http_stub/configurer/post_initialize_command_processor', __FILE__)
         | 
| 28 28 | 
             
            require File.expand_path('../http_stub/configurer', __FILE__)
         | 
    
        data/lib/http_stub/configurer.rb
    CHANGED
    
    | @@ -36,8 +36,8 @@ module HttpStub | |
| 36 36 | 
             
                  alias_method :activate_stub!, :activate!
         | 
| 37 37 |  | 
| 38 38 | 
             
                  def initialize!
         | 
| 39 | 
            -
                    processor. | 
| 40 | 
            -
                    @processor = HttpStub::Configurer:: | 
| 39 | 
            +
                    processor.replay()
         | 
| 40 | 
            +
                    @processor = HttpStub::Configurer::PostInitializeCommandProcessor.new(processor)
         | 
| 41 41 | 
             
                  end
         | 
| 42 42 |  | 
| 43 43 | 
             
                  def clear_activators!
         | 
| @@ -57,7 +57,7 @@ module HttpStub | |
| 57 57 | 
             
                  end
         | 
| 58 58 |  | 
| 59 59 | 
             
                  def processor
         | 
| 60 | 
            -
                    @processor ||= HttpStub::Configurer:: | 
| 60 | 
            +
                    @processor ||= HttpStub::Configurer::PreInitializeCommandProcessor.new
         | 
| 61 61 | 
             
                  end
         | 
| 62 62 |  | 
| 63 63 | 
             
                end
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            module HttpStub
         | 
| 2 | 
            +
              module Configurer
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                class PostInitializeCommandProcessor
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  def initialize(pre_initialize_processor)
         | 
| 7 | 
            +
                    @pre_initialize_processor = pre_initialize_processor
         | 
| 8 | 
            +
                  end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  def process(command)
         | 
| 11 | 
            +
                    command.execute()
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  def replay
         | 
| 15 | 
            +
                    @pre_initialize_processor.replay()
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            module HttpStub
         | 
| 2 | 
            +
              module Configurer
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                class PreInitializeCommandProcessor
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  def initialize
         | 
| 7 | 
            +
                    @cache = []
         | 
| 8 | 
            +
                  end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  def process(command)
         | 
| 11 | 
            +
                    @cache << command
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  def replay
         | 
| 15 | 
            +
                    @cache.each { |command| command.execute() }
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
    
        data/lib/http_stub/version.rb
    CHANGED
    
    
| @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            describe HttpStub::Configurer::PostInitializeCommandProcessor do
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              let(:command) { double(HttpStub::Configurer::Command).as_null_object }
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              let(:pre_processor) { double(HttpStub::Configurer::PreInitializeCommandProcessor) }
         | 
| 6 | 
            +
              let(:post_processor) { HttpStub::Configurer::PostInitializeCommandProcessor.new(pre_processor) }
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              describe "#process" do
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                it "should immediately execute the provided command" do
         | 
| 11 | 
            +
                  command.should_receive(:execute)
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  post_processor.process(command)
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                it "should not execute the command via the pre initialize command processor" do
         | 
| 17 | 
            +
                  pre_processor.should_not_receive(:execute)
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  post_processor.process(command)
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              describe "#replay" do
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                it "should replay any commands known by the pre initialize command processor" do
         | 
| 27 | 
            +
                  pre_processor.should_receive(:replay)
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  post_processor.replay
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            end
         | 
| @@ -0,0 +1,47 @@ | |
| 1 | 
            +
            describe HttpStub::Configurer::PreInitializeCommandProcessor do
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              let(:processor) { HttpStub::Configurer::PreInitializeCommandProcessor.new }
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              describe "#replay" do
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                describe "when a number of commands have been processed" do
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  let(:commands) do
         | 
| 10 | 
            +
                    (1..3).map { |i| double("Command#{i}").as_null_object }
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  before(:each) do
         | 
| 14 | 
            +
                    commands.each { |command| processor.process(command) }
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  it "should execute the cached commands" do
         | 
| 18 | 
            +
                    commands.each { |command| command.should_receive(:execute) }
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                    processor.replay()
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                  describe "and those commands have already been replayed" do
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    before(:each) { processor.replay() }
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                    it "should re-replay those commands" do
         | 
| 28 | 
            +
                      commands.each { |command| command.should_receive(:execute) }
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                      processor.replay()
         | 
| 31 | 
            +
                    end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                describe "when no commands have been processed" do
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                  it "should execute without error" do
         | 
| 40 | 
            +
                    lambda { processor.replay() }.should_not raise_error
         | 
| 41 | 
            +
                  end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
              end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            end
         | 
| @@ -43,7 +43,7 @@ describe HttpStub::Configurer, "when the server is running" do | |
| 43 43 |  | 
| 44 44 | 
             
                end
         | 
| 45 45 |  | 
| 46 | 
            -
                describe "and  | 
| 46 | 
            +
                describe "and a class stub is defined" do
         | 
| 47 47 |  | 
| 48 48 | 
             
                  let(:configurer) { HttpStub::Examples::ConfigurerWithClassStub.new }
         | 
| 49 49 |  | 
| @@ -54,6 +54,27 @@ describe HttpStub::Configurer, "when the server is running" do | |
| 54 54 | 
             
                    response.body.should eql("Class stub body")
         | 
| 55 55 | 
             
                  end
         | 
| 56 56 |  | 
| 57 | 
            +
                  describe "and the stub is overridden" do
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                    before(:each) do
         | 
| 60 | 
            +
                      configurer.stub_response!("/a_class_stub", method: :get, response: { body: "Other class stub body" })
         | 
| 61 | 
            +
                    end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                    describe "and the configurer is re-initialized" do
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                      before(:each) { configurer.class.initialize! }
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                      it "should re-establish the class stub as having priority" do
         | 
| 68 | 
            +
                        response = Net::HTTP.get_response("localhost", "/a_class_stub", 8001)
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                        response.code.should eql("201")
         | 
| 71 | 
            +
                        response.body.should eql("Class stub body")
         | 
| 72 | 
            +
                      end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                    end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                  end
         | 
| 77 | 
            +
             | 
| 57 78 | 
             
                end
         | 
| 58 79 |  | 
| 59 80 | 
             
                describe "and a response for a request is stubbed" do
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: http_stub
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.5. | 
| 4 | 
            +
              version: 0.5.6
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -10,7 +10,7 @@ authors: | |
| 10 10 | 
             
            autorequire: 
         | 
| 11 11 | 
             
            bindir: bin
         | 
| 12 12 | 
             
            cert_chain: []
         | 
| 13 | 
            -
            date: 2013-03- | 
| 13 | 
            +
            date: 2013-03-17 00:00:00.000000000 Z
         | 
| 14 14 | 
             
            dependencies:
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 16 16 | 
             
              name: sinatra
         | 
| @@ -194,9 +194,9 @@ executables: [] | |
| 194 194 | 
             
            extensions: []
         | 
| 195 195 | 
             
            extra_rdoc_files: []
         | 
| 196 196 | 
             
            files:
         | 
| 197 | 
            -
            - ./lib/http_stub/configurer/buffered_command_processor.rb
         | 
| 198 197 | 
             
            - ./lib/http_stub/configurer/command.rb
         | 
| 199 | 
            -
            - ./lib/http_stub/configurer/ | 
| 198 | 
            +
            - ./lib/http_stub/configurer/post_initialize_command_processor.rb
         | 
| 199 | 
            +
            - ./lib/http_stub/configurer/pre_initialize_command_processor.rb
         | 
| 200 200 | 
             
            - ./lib/http_stub/configurer/stub_activator_request.rb
         | 
| 201 201 | 
             
            - ./lib/http_stub/configurer/stub_request.rb
         | 
| 202 202 | 
             
            - ./lib/http_stub/configurer.rb
         | 
| @@ -220,9 +220,9 @@ files: | |
| 220 220 | 
             
            - ./lib/http_stub/views/stubs.haml
         | 
| 221 221 | 
             
            - ./lib/http_stub.rb
         | 
| 222 222 | 
             
            - ./spec/curl_samples.txt
         | 
| 223 | 
            -
            - ./spec/lib/http_stub/configurer/buffered_command_processor_spec.rb
         | 
| 224 223 | 
             
            - ./spec/lib/http_stub/configurer/command_integration_spec.rb
         | 
| 225 | 
            -
            - ./spec/lib/http_stub/configurer/ | 
| 224 | 
            +
            - ./spec/lib/http_stub/configurer/post_initialize_command_processor_spec.rb
         | 
| 225 | 
            +
            - ./spec/lib/http_stub/configurer/pre_initialize_command_processor_spec.rb
         | 
| 226 226 | 
             
            - ./spec/lib/http_stub/configurer/stub_activator_request_spec.rb
         | 
| 227 227 | 
             
            - ./spec/lib/http_stub/configurer/stub_request_spec.rb
         | 
| 228 228 | 
             
            - ./spec/lib/http_stub/configurer_integration_spec.rb
         | 
| @@ -262,7 +262,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 262 262 | 
             
                  version: '0'
         | 
| 263 263 | 
             
                  segments:
         | 
| 264 264 | 
             
                  - 0
         | 
| 265 | 
            -
                  hash:  | 
| 265 | 
            +
                  hash: -3141550755533395331
         | 
| 266 266 | 
             
            requirements: []
         | 
| 267 267 | 
             
            rubyforge_project: http_stub
         | 
| 268 268 | 
             
            rubygems_version: 1.8.25
         | 
| @@ -271,9 +271,9 @@ specification_version: 3 | |
| 271 271 | 
             
            summary: A HTTP Server replaying configured stub responses.
         | 
| 272 272 | 
             
            test_files:
         | 
| 273 273 | 
             
            - ./spec/curl_samples.txt
         | 
| 274 | 
            -
            - ./spec/lib/http_stub/configurer/buffered_command_processor_spec.rb
         | 
| 275 274 | 
             
            - ./spec/lib/http_stub/configurer/command_integration_spec.rb
         | 
| 276 | 
            -
            - ./spec/lib/http_stub/configurer/ | 
| 275 | 
            +
            - ./spec/lib/http_stub/configurer/post_initialize_command_processor_spec.rb
         | 
| 276 | 
            +
            - ./spec/lib/http_stub/configurer/pre_initialize_command_processor_spec.rb
         | 
| 277 277 | 
             
            - ./spec/lib/http_stub/configurer/stub_activator_request_spec.rb
         | 
| 278 278 | 
             
            - ./spec/lib/http_stub/configurer/stub_request_spec.rb
         | 
| 279 279 | 
             
            - ./spec/lib/http_stub/configurer_integration_spec.rb
         | 
| @@ -1,24 +0,0 @@ | |
| 1 | 
            -
            module HttpStub
         | 
| 2 | 
            -
              module Configurer
         | 
| 3 | 
            -
             | 
| 4 | 
            -
                class BufferedCommandProcessor
         | 
| 5 | 
            -
             | 
| 6 | 
            -
                  def initialize
         | 
| 7 | 
            -
                    @buffer = []
         | 
| 8 | 
            -
                  end
         | 
| 9 | 
            -
             | 
| 10 | 
            -
                  def process(command)
         | 
| 11 | 
            -
                    @buffer << command
         | 
| 12 | 
            -
                  end
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                  def flush
         | 
| 15 | 
            -
                    until @buffer.empty?
         | 
| 16 | 
            -
                      command = @buffer.shift
         | 
| 17 | 
            -
                      command.execute()
         | 
| 18 | 
            -
                    end
         | 
| 19 | 
            -
                  end
         | 
| 20 | 
            -
             | 
| 21 | 
            -
                end
         | 
| 22 | 
            -
             | 
| 23 | 
            -
              end
         | 
| 24 | 
            -
            end
         | 
| @@ -1,47 +0,0 @@ | |
| 1 | 
            -
            describe HttpStub::Configurer::BufferedCommandProcessor do
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              let(:processor) { HttpStub::Configurer::BufferedCommandProcessor.new }
         | 
| 4 | 
            -
             | 
| 5 | 
            -
              describe "#flush" do
         | 
| 6 | 
            -
             | 
| 7 | 
            -
                describe "when a number of commands have been processed" do
         | 
| 8 | 
            -
             | 
| 9 | 
            -
                  let(:commands) do
         | 
| 10 | 
            -
                    (1..3).map { |i| double("Command#{i}").as_null_object }
         | 
| 11 | 
            -
                  end
         | 
| 12 | 
            -
             | 
| 13 | 
            -
                  before(:each) do
         | 
| 14 | 
            -
                    commands.each { |command| processor.process(command) }
         | 
| 15 | 
            -
                  end
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                  it "should execute the buffered commands" do
         | 
| 18 | 
            -
                    commands.each { |command| command.should_receive(:execute) }
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                    processor.flush()
         | 
| 21 | 
            -
                  end
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                  describe "and those commands have already been flushed" do
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                    before(:each) { processor.flush() }
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                    it "should not re-execute those commands" do
         | 
| 28 | 
            -
                      commands.each { |command| command.should_not_receive(:execute) }
         | 
| 29 | 
            -
             | 
| 30 | 
            -
                      processor.flush()
         | 
| 31 | 
            -
                    end
         | 
| 32 | 
            -
             | 
| 33 | 
            -
                  end
         | 
| 34 | 
            -
             | 
| 35 | 
            -
                end
         | 
| 36 | 
            -
             | 
| 37 | 
            -
                describe "when no commands have been processed" do
         | 
| 38 | 
            -
             | 
| 39 | 
            -
                  it "should execute without error" do
         | 
| 40 | 
            -
                    lambda { processor.flush() }.should_not raise_error
         | 
| 41 | 
            -
                  end
         | 
| 42 | 
            -
             | 
| 43 | 
            -
                end
         | 
| 44 | 
            -
             | 
| 45 | 
            -
              end
         | 
| 46 | 
            -
             | 
| 47 | 
            -
            end
         | 
| @@ -1,34 +0,0 @@ | |
| 1 | 
            -
            describe HttpStub::Configurer::ImmediateCommandProcessor do
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              let(:command) { double("Command").as_null_object }
         | 
| 4 | 
            -
             | 
| 5 | 
            -
              let(:processor) { HttpStub::Configurer::ImmediateCommandProcessor.new }
         | 
| 6 | 
            -
             | 
| 7 | 
            -
              describe "#process" do
         | 
| 8 | 
            -
             | 
| 9 | 
            -
                it "should execute the provided command" do
         | 
| 10 | 
            -
                  command.should_receive(:execute)
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                  processor.process(command)
         | 
| 13 | 
            -
                end
         | 
| 14 | 
            -
             | 
| 15 | 
            -
              end
         | 
| 16 | 
            -
             | 
| 17 | 
            -
              describe "#flush" do
         | 
| 18 | 
            -
             | 
| 19 | 
            -
                describe "when a command has been processed" do
         | 
| 20 | 
            -
             | 
| 21 | 
            -
                  before(:each) { processor.process(command) }
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                  it "should not re-execute the command" do
         | 
| 24 | 
            -
                    command.should_not_receive(:execute)
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                    processor.flush
         | 
| 27 | 
            -
                  end
         | 
| 28 | 
            -
             | 
| 29 | 
            -
                end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
              end
         | 
| 33 | 
            -
             | 
| 34 | 
            -
            end
         |