Sha256: 5f6a8561fdc2fdfe4f41da218408d67577f6d8c14de17c6f8a61b65cbc96f98e

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

module RSpec::RubyContentMatchers
  class IncludeModule < RSpec::RubyContentMatcher
    attr_reader :module_name, :type

    def initialize module_name, type=nil
      @module_name = module_name.to_s.camelize
      @type = type || :include
    end

    def matches?(content)      
      @content = content
      (content =~ /#{type}\s+#{module_name}/)
    end          
  
    def failure_message
      super
      "Expected there to be an inclusion of module #{module_name}"
    end 
    
    def negative_failure_message
      super
      "Did not expect there to be an inclusion of module #{module_name}"
    end
               
  end
  
  def include_module(module_name)
    IncludeModule.new(module_name)
  end    

  def extend_module(module_name)
    IncludeModule.new(module_name, :extend)
  end    

  def be_dm_resource
    IncludeModule.new 'DataMapper::Resource'
  end    
  
  def be_document(type, options=nil)
    doc_type = options == :embedded ? 'EmbeddedDocument' : 'Document'
    doc_orm = case type 
    when :mongo_mapper
      'MongoMapper'
    when :mongoid
      'Mongoid'
    else
      raise ArgumentError, "Unknown document type #{type.inspect}"
    end    
    IncludeModule.new "#{doc_orm}::#{doc_type}"
  end
end  

Version data entries

3 entries across 3 versions & 1 rubygems

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