Parent

Class/Module Index [+]

Quicksearch

Spec::Matchers::Matcher

Attributes

actual[R]
expected[R]

Public Class Methods

new(name, *expected, &declarations) click to toggle source
# File lib/spec/matchers/matcher.rb, line 10
def initialize(name, *expected, &declarations)
  @name     = name
  @expected = expected
  @actual   = nil
  @diffable = false
  @expected_exception = nil
  @messages = {
    :description => lambda {"#{name_to_sentence}#{expected_to_sentence}"},
    :failure_message_for_should => lambda {|actual| "expected #{actual.inspect} to #{name_to_sentence}#{expected_to_sentence}"},
    :failure_message_for_should_not => lambda {|actual| "expected #{actual.inspect} not to #{name_to_sentence}#{expected_to_sentence}"}
  }
  making_declared_methods_public do
    instance_exec(*@expected, &declarations)
  end
end

Public Instance Methods

chain(method, &block) click to toggle source

See Spec::Matchers

# File lib/spec/matchers/matcher.rb, line 82
def chain(method, &block)
  self.class.class_eval do
    define_method method do |*args|
      block.call(*args)
      self
    end
  end
end
description(&block) click to toggle source

See Spec::Matchers

# File lib/spec/matchers/matcher.rb, line 67
def description(&block)
  cache_or_call_cached(:description, &block)
end
diffable() click to toggle source

See Spec::Matchers

# File lib/spec/matchers/matcher.rb, line 77
def diffable
  @diffable = true
end
diffable?() click to toggle source

Used internally by objects returns by should and should_not.

# File lib/spec/matchers/matcher.rb, line 72
def diffable?
  @diffable
end
failure_message_for_should(&block) click to toggle source

See Spec::Matchers

# File lib/spec/matchers/matcher.rb, line 57
def failure_message_for_should(&block)
  cache_or_call_cached(:failure_message_for_should, &block)
end
failure_message_for_should_not(&block) click to toggle source

See Spec::Matchers

# File lib/spec/matchers/matcher.rb, line 62
def failure_message_for_should_not(&block)
  cache_or_call_cached(:failure_message_for_should_not, &block)
end
match(&block) click to toggle source

See Spec::Matchers

# File lib/spec/matchers/matcher.rb, line 46
def match(&block)
  @match_block = block
end
match_unless_raises(exception=Exception, &block) click to toggle source

See Spec::Matchers

# File lib/spec/matchers/matcher.rb, line 51
def match_unless_raises(exception=Exception, &block)
  @expected_exception = exception
  match(&block)
end
matches?(actual) click to toggle source

Used internally by objects returns by should and should_not.

# File lib/spec/matchers/matcher.rb, line 27
def matches?(actual)
  @actual = actual
  if @expected_exception
    begin
      instance_exec(actual, &@match_block)
      true
    rescue @expected_exception
      false
    end
  else
    begin
      instance_exec(actual, &@match_block)
    rescue Spec::Expectations::ExpectationNotMetError
      false
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.