jbender/motion-spec

View on GitHub
lib/motion-spec/matcher/be_a.rb

Summary

Maintainability
A
0 mins
Test Coverage
# -*- encoding : utf-8 -*-
module MotionSpec
  module Matcher
    class BeA
      def initialize(test_class)
        @test_class = test_class
      end

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

        comparison_object.ancestors.include? @test_class
      end

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