Class: MotionSpec::Matcher::BeA

Inherits:
Object
  • Object
show all
Defined in:
lib/motion-spec/matcher/be_a.rb

Instance Method Summary collapse

Constructor Details

#initialize(test_class) ⇒ BeA

Returns a new instance of BeA.



5
6
7
# File 'lib/motion-spec/matcher/be_a.rb', line 5

def initialize(test_class)
  @test_class = test_class
end

Instance Method Details

#fail!(subject, negated) ⇒ Object



15
16
17
18
# File 'lib/motion-spec/matcher/be_a.rb', line 15

def fail!(subject, negated)
  message = FailMessageRenderer.message_for_be_a(negated, subject, @test_class)
  fail FailedExpectation.new(message)
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
# File 'lib/motion-spec/matcher/be_a.rb', line 9

def matches?(subject)
  comparison_object = subject.is_a?(Class) ? subject : subject.class

  comparison_object.ancestors.include? @test_class
end