Sha256: 9aa198c6eac2400da51a49ecba5e782cb223990df4b2b674f139e338f37a2021

Contents?: true

Size: 1.29 KB

Versions: 3

Compression:

Stored size: 1.29 KB

Contents

module RSpec::RubyContentMatchers
  class HaveSubclass < RSpec::RubyContentMatcher
    attr_reader :klass, :superclass, :type

    def initialize(klass, superclass, type=nil)
      @klass      = klass.to_s.camelize       
      super @klass
      @superclass = superclass.to_s.camelize
      @type       = type.to_s.camelize if type      
    end

    def failure_message  
      super
      "Expected there to be the subclass #{klass} of #{superclass}"
    end 

    def negative_failure_message
      super
      "Did no expected there to be the subclass #{klass} of #{superclass}"
    end   

    protected 
    
    def main_expr
      'class' + SPACES + "#{klass}#{type}" + OPT_SPACES + '<' + OPT_SPACES + "#{superclass}" + ANY_GROUP      
    end

    def alt_end
      'class'
    end
    
  end

  def have_subclass(klass, superclass, type=nil)
    HaveSubclass.new(klass, superclass, type)
  end    
  alias_method :be_subclass, :have_subclass
  
  def have_observer_class(klass)
    HaveSubclass.new(klass, 'ActiveRecord::Observer', :observer)
  end     
  alias_method :be_observer, :have_observer_class
  alias_method :be_observer_class, :have_observer_class

  
  def have_migration(klass)
    HaveSubclass.new(klass, 'ActiveRecord::Migration')
  end      
  alias_method :be_migration, :have_migration  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
generator-spec-0.5.0 lib/generator_spec/matchers/content/have_subclass.rb
generator-spec-0.4.8 lib/generator_spec/matchers/content/have_subclass.rb
generator-spec-0.4.7 lib/generator_spec/matchers/content/have_subclass.rb