Sha256: 256e7c6abd0e17c1624b8f6be4e287c7fa56ebeec3b8a47f4edcde27c674e6ff

Contents?: true

Size: 771 Bytes

Versions: 1

Compression:

Stored size: 771 Bytes

Contents

module RSpec::RubyContentMatchers
  class InheritFrom
    attr_reader :klass

    def initialize klass
      @klass = klass.to_s.camelize
    end

    def matches?(content)      
      match_res =~ /class\s+(.*?)<\s+#{klass}(.*)end/
      if block_given? && match_res
        ruby_content = $2.strip.extend(RSpec::RubyContent::Helpers)
        yield ruby_content
      else
        match_res
      end
    end          
  
    def failure_message
      "Expected the class to inherit from #{klass}"
    end 
    
    def negative_failure_message
      "Did not expect the class to inherit from #{klass}"
    end
  end
  
  def inherit_from(klass)
    InheritFrom.new(klass)
  end
  
  def be_active_record    
    InheritFrom.new('ActiveRecord::Base')    
  end
  
end  

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
generator-spec-0.4.3 lib/rspec_for_generators/matchers/content/inherit_from.rb