Parent

RSpec::Matchers::Matcher

Attributes

actual[R]
expected[R]
rescued_exception[R]

Public Class Methods

new(name, *expected, &declarations) click to toggle source
# File lib/rspec/matchers/matcher.rb, line 9
def initialize(name, *expected, &declarations)
  @name     = name
  @expected = expected
  @actual   = nil
  @diffable = false
  @expected_exception, @rescued_exception = nil, nil
  @match_for_should_not_block = 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 RSpec::Matchers

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

See RSpec::Matchers

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

See RSpec::Matchers

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

Used internally by objects returns by should and should_not.

# File lib/rspec/matchers/matcher.rb, line 95
def diffable?
  @diffable
end
does_not_match?(actual) click to toggle source

Used internally by should_not

# File lib/rspec/matchers/matcher.rb, line 47
def does_not_match?(actual)
  @actual = actual
  @match_for_should_not_block ?
    instance_exec(actual, &@match_for_should_not_block) :
    !matches?(actual)
end
failure_message_for_should(&block) click to toggle source

See RSpec::Matchers

# File lib/rspec/matchers/matcher.rb, line 80
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 RSpec::Matchers

# File lib/rspec/matchers/matcher.rb, line 85
def failure_message_for_should_not(&block)
  cache_or_call_cached(:failure_message_for_should_not, &block)
end
include(*args) click to toggle source
# File lib/rspec/matchers/matcher.rb, line 54
def include(*args)
  singleton_class.__send__(:include, *args)
end
match(&block) click to toggle source

See RSpec::Matchers

# File lib/rspec/matchers/matcher.rb, line 63
def match(&block)
  @match_block = block
end
Also aliased as: match_for_should
match_for_should(&block) click to toggle source
Alias for: match
match_for_should_not(&block) click to toggle source

See RSpec::Matchers

# File lib/rspec/matchers/matcher.rb, line 69
def match_for_should_not(&block)
  @match_for_should_not_block = block
end
match_unless_raises(exception=Exception, &block) click to toggle source

See RSpec::Matchers

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

Used internally by should and should_not.

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.