Sha256: d3ff9d5e6a07ba0b3573230b1fcc9dda38d989f75038c6281e345d2272b2df33

Contents?: true

Size: 864 Bytes

Versions: 2

Compression:

Stored size: 864 Bytes

Contents

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

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

    def matches?(content)            
      super
      match_res =~ /module\s+#{module_name}\s+(.*)end/m
      if block_given? && match_res
        ruby_content = $2.strip.extend(RSpec::RubyContent::Helpers)
        yield ruby_content
      else
        match_res
      end
    end          
  
    def failure_message
      super
      "Expected there to be the module #{module_name}"
    end 
    
    def negative_failure_message
      super
      "Did no expected there to be the module #{module_name}"
    end
               
  end
  
  def have_module(module_name)
    HaveModule.new(module_name)
  end       
  alias_method :be_module, :have_module  
end  

Version data entries

2 entries across 2 versions & 1 rubygems

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