Sha256: 174f2d923a6913f1c30667542884cdc3f538a35febaedf9d88204ab850db8ba6

Contents?: true

Size: 1.51 KB

Versions: 8

Compression:

Stored size: 1.51 KB

Contents

module WebMock
  class RequestExecutionVerifier

    attr_accessor :request_profile, :expected_times_executed, :times_executed

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

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

    def does_not_match?
      @times_executed =
      RequestRegistry.instance.times_executed(@request_profile)
      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_profile.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_profile.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_profile.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

8 entries across 8 versions & 1 rubygems

Version Path
webmock-0.9.1 lib/webmock/request_execution_verifier.rb
webmock-0.9.0 lib/webmock/request_execution_verifier.rb
webmock-0.8.2 lib/webmock/request_execution_verifier.rb
webmock-0.8.1 lib/webmock/request_execution_verifier.rb
webmock-0.8.0 lib/webmock/request_execution_verifier.rb
webmock-0.7.3 lib/webmock/request_execution_verifier.rb
webmock-0.7.2 lib/webmock/request_execution_verifier.rb
webmock-0.7.1 lib/webmock/request_execution_verifier.rb