Sha256: 2323a83d525784aefe2965e5e2b4c705a09483a02b421074bfe2b89e3d6504a9

Contents?: true

Size: 858 Bytes

Versions: 4

Compression:

Stored size: 858 Bytes

Contents

module ShellMock
  class RunVerifier
    def initialize
      more_than(0)
    end

    def times(n)
      match_runs_when { |runs| runs == n }

      self
    end

    def fewer_than(n)
      match_runs_when { |runs| runs < n }

      self
    end
    alias less_than fewer_than

    def more_than(n)
      match_runs_when { |runs| runs > n }

      self
    end

    def once
      times(1)
    end

    def never
      times(0)
    end

    def matches?(command_stub)
      @command_stub = command_stub

      condition.call(command_stub.runs)
    end

    def failure_message
      "#{command_stub.command} was expected."
    end

    def failure_message_when_negated
      "#{command_stub.command} was not expected."
    end

    private

    attr_reader :command_stub, :condition

    def match_runs_when(&blk)
      @condition = blk
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
shell_mock-0.7.2 lib/shell_mock/run_verifier.rb
shell_mock-0.7.1 lib/shell_mock/run_verifier.rb
shell_mock-0.7.0 lib/shell_mock/run_verifier.rb
shell_mock-0.6.0 lib/shell_mock/run_verifier.rb