Sha256: 5b0d9792cf865907c7c03ca1164d0277e813b6f5ac53678ed933d51e82a41a4f

Contents?: true

Size: 1.16 KB

Versions: 5

Compression:

Stored size: 1.16 KB

Contents

module Caricature

  # Describes a verification of a method call.
  # This corresponds kind of to an assertion
  class Verification

    # Initializes a new instance of a +Verification+
    def initialize(method_name, recorder, mode=:instance)
      @method_name, @args, @any_args, @recorder, @mode = method_name, [], true, recorder, mode
    end

    # indicates whether this verification can be for any arguments
    def any_args?
      @any_args
    end

    # constrain this verification to the provided arguments
    def with(*args)
      @any_args = args.first.is_a?(Symbol) and args.first == :any
      @args = args
      self
    end

    # allow any arguments ignore the argument constraint
    def allow_any_arguments
      @any_args = true
      self
    end

    # figure out if this argument variation matches the provided args.
    def matches?(method_name, *args)
      @method_name == method_name and any_args? or @args == args
    end

    # indicate that this method verification is successful
    def successful?
      a = any_args? ? [:any] : @args
      @recorder.was_called?(@method_name, @mode, *a)
    end

  end

end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
casualjim-caricature-0.6.0 lib/caricature/verification.rb
casualjim-caricature-0.6.1 lib/caricature/verification.rb
caricature-0.6.3 lib/caricature/verification.rb
caricature-0.6.0 lib/caricature/verification.rb
caricature-0.6.1 lib/caricature/verification.rb