Sha256: a8181c7a795a29a57037aa3fc1af198ee80ed715f8a8d97ecc11bfdc3c43c47e

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

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

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

    def matches?(content)      
      super
      match_res = (content =~ /include\s+#{module_name}/)
      if block_given? && match_res
        ruby_content = content.extend(RSpec::RubyContent::Helpers)
        yield ruby_content
      else
        match_res
      end
    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 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

2 entries across 2 versions & 1 rubygems

Version Path
generator-spec-0.4.5 lib/generator_spec/matchers/content/include_module.rb
generator-spec-0.4.4 lib/generator_spec/matchers/content/include_module.rb