Sha256: 97bd23bb2609ccd449ad2116bce43af235dc9431c98f681b5c2ad7de93f4110b

Contents?: true

Size: 1.51 KB

Versions: 13

Compression:

Stored size: 1.51 KB

Contents

module WebMock
  class RequestExecutionVerifier

    attr_accessor :request_pattern, :expected_times_executed, :times_executed

    def initialize(request_pattern = nil, expected_times_executed = nil)
      @request_pattern = request_pattern
      @expected_times_executed = expected_times_executed
    end

    def matches?
      @times_executed =
      RequestRegistry.instance.times_executed(@request_pattern)
      @times_executed == (@expected_times_executed || 1)
    end

    def does_not_match?
      @times_executed =
      RequestRegistry.instance.times_executed(@request_pattern)
      if @expected_times_executed
        @times_executed != @expected_times_executed
      else
        @times_executed == 0
      end
    end


    def failure_message
      expected_times_executed = @expected_times_executed || 1
      %Q(The request #{request_pattern.to_s} was expected to execute #{expected_times_executed} time#{ (expected_times_executed == 1) ? '' : 's'} but it executed #{times_executed} time#{ (times_executed == 1) ? '' : 's'})
    end

    def negative_failure_message
      if @expected_times_executed
        %Q(The request #{request_pattern.to_s} was not expected to execute #{expected_times_executed} time#{ (expected_times_executed == 1) ? '' : 's'} but it executed #{times_executed} time#{ (times_executed == 1) ? '' : 's'})
      else
        %Q(The request #{request_pattern.to_s} was expected to execute 0 times but it executed #{times_executed} time#{ (times_executed == 1) ? '' : 's'})
      end
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
webmock-1.5.0 lib/webmock/request_execution_verifier.rb
webmock-1.4.0 lib/webmock/request_execution_verifier.rb
webmock-1.3.5 lib/webmock/request_execution_verifier.rb
webmock-1.3.4 lib/webmock/request_execution_verifier.rb
webmock-1.3.3 lib/webmock/request_execution_verifier.rb
webmock-1.3.2 lib/webmock/request_execution_verifier.rb
webmock-1.3.1 lib/webmock/request_execution_verifier.rb
webmock-1.3.0 lib/webmock/request_execution_verifier.rb
webmock-1.2.2 lib/webmock/request_execution_verifier.rb
webmock-1.2.1 lib/webmock/request_execution_verifier.rb
webmock-1.2.0 lib/webmock/request_execution_verifier.rb
webmock-1.1.0 lib/webmock/request_execution_verifier.rb
webmock-1.0.0 lib/webmock/request_execution_verifier.rb