Sha256: f4529711815e892304bc1aa2eea69302cbee02249b22974d3b86cfcc57a8cb9e

Contents?: true

Size: 1.97 KB

Versions: 19

Compression:

Stored size: 1.97 KB

Contents

module WebMock
  module API
    extend self

    def stub_request(method, uri)
      WebMock::StubRegistry.instance.
        register_request_stub(WebMock::RequestStub.new(method, uri))
    end

    alias_method :stub_http_request, :stub_request

    def a_request(method, uri)
      WebMock::RequestPattern.new(method, uri)
    end

    class << self
      alias :request :a_request
    end


    def assert_requested(*args, &block)
      if not args[0].is_a?(WebMock::RequestStub)
        args = convert_uri_method_and_options_to_request_and_options(*args, &block)
      end
      assert_request_requested(*args, &block)
    end

    def assert_not_requested(*args, &block)
      if not args[0].is_a?(WebMock::RequestStub)
        args = convert_uri_method_and_options_to_request_and_options(*args, &block)
      end
      assert_request_not_requested(*args, &block)
    end

    def hash_including(expected)
      if defined?(::RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher)
        RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new(expected)
      elsif defined?(::Spec::Mocks::ArgumentMatchers::HashIncludingMatcher)
        Spec::Mocks::ArgumentMatchers::HashIncludingMatcher.new(expected)
      else
        WebMock::Matchers::HashIncludingMatcher.new(expected)
      end
    end

    private

    def convert_uri_method_and_options_to_request_and_options(*args, &block)
      request = WebMock::RequestPattern.new(*args).with(&block)
      [request, args[2] || {}]
    end

    def assert_request_requested(request, options = {})
      verifier = WebMock::RequestExecutionVerifier.new(request, options.delete(:times) || 1)
      WebMock::AssertionFailure.failure(verifier.failure_message) unless verifier.matches?
    end

    def assert_request_not_requested(request, options = {})
      verifier = WebMock::RequestExecutionVerifier.new(request, options.delete(:times))
      WebMock::AssertionFailure.failure(verifier.negative_failure_message) unless verifier.does_not_match?
    end

  end
end

Version data entries

19 entries across 19 versions & 3 rubygems

Version Path
solidus_backend-1.0.0.pre3 vendor/bundle/gems/webmock-1.8.11/lib/webmock/api.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/webmock-1.8.11/lib/webmock/api.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/webmock-1.8.11/lib/webmock/api.rb
webmock-1.9.3 lib/webmock/api.rb
webmock-1.9.2 lib/webmock/api.rb
webmock-1.9.1 lib/webmock/api.rb
simple-client-0.0.3 vendor/bundle/ruby/1.9.1/gems/webmock-1.8.8/lib/webmock/api.rb
webmock-1.9.0 lib/webmock/api.rb
webmock-1.8.11 lib/webmock/api.rb
webmock-1.8.10 lib/webmock/api.rb
webmock-1.8.9 lib/webmock/api.rb
simple-client-0.0.2 vendor/bundle/ruby/1.8/gems/webmock-1.8.8/lib/webmock/api.rb
webmock-1.8.8 lib/webmock/api.rb
webmock-1.8.7 lib/webmock/api.rb
webmock-1.8.6 lib/webmock/api.rb
webmock-1.8.5 lib/webmock/api.rb
webmock-1.8.4 lib/webmock/api.rb
webmock-1.8.3 lib/webmock/api.rb
webmock-1.8.2 lib/webmock/api.rb