Sha256: bce2eff19112c597cb1b83b110b60c1f51754953884a65a3a2cfefe33140ad59

Contents?: true

Size: 1.69 KB

Versions: 54

Compression:

Stored size: 1.69 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
      text = %Q(The request #{request_pattern.to_s} was expected to execute #{times(expected_times_executed)} but it executed #{times(times_executed)})
      text << self.class.executed_requests_message
      text
    end

    def negative_failure_message
      text = if @expected_times_executed
        %Q(The request #{request_pattern.to_s} was not expected to execute #{times(expected_times_executed)} but it executed #{times(times_executed)})
      else
        %Q(The request #{request_pattern.to_s} was expected to execute 0 times but it executed #{times(times_executed)})
      end
      text << self.class.executed_requests_message
      text
    end

    def self.executed_requests_message
      "\n\nThe following requests were made:\n\n#{RequestRegistry.instance.to_s}\n" + "="*60
    end

    private

    def times(times)
      "#{times} time#{ (times == 1) ? '' : 's'}"
    end

  end
end

Version data entries

54 entries across 54 versions & 4 rubygems

Version Path
solidus_backend-1.0.0.pre3 vendor/bundle/gems/webmock-1.8.11/lib/webmock/request_execution_verifier.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/webmock-1.8.11/lib/webmock/request_execution_verifier.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/webmock-1.8.11/lib/webmock/request_execution_verifier.rb
webmock-1.17.3 lib/webmock/request_execution_verifier.rb
webmock-1.17.2 lib/webmock/request_execution_verifier.rb
webmock-1.17.1 lib/webmock/request_execution_verifier.rb
webmock-1.17.0 lib/webmock/request_execution_verifier.rb
webmock-1.16.1 lib/webmock/request_execution_verifier.rb
webmock-1.16.0 lib/webmock/request_execution_verifier.rb
webmock-1.15.2 lib/webmock/request_execution_verifier.rb
webmock-1.15.0 lib/webmock/request_execution_verifier.rb
webmock-1.14.0 lib/webmock/request_execution_verifier.rb
webmock-1.13.0 lib/webmock/request_execution_verifier.rb
webmock-1.12.3 lib/webmock/request_execution_verifier.rb
webmock-1.12.2 lib/webmock/request_execution_verifier.rb
webmock-1.12.1 lib/webmock/request_execution_verifier.rb
webmock-1.12.0 lib/webmock/request_execution_verifier.rb
webmock-1.11.0 lib/webmock/request_execution_verifier.rb
webmock-1.10.2 lib/webmock/request_execution_verifier.rb
webmock-1.10.1 lib/webmock/request_execution_verifier.rb