Sha256: c74e4fd997dfa5009763a28cd91f3738e973b1d8df5a985ea88cc6ae76965ade

Contents?: true

Size: 922 Bytes

Versions: 2

Compression:

Stored size: 922 Bytes

Contents

module RSpec::RubyContentMatchers
  class HaveModule
    attr_reader :module_name, :content

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

    def matches?(content)            
      @content = content
      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
      puts "Content: #{content}" if RSpec::Generator.debug?      
      "Expected there to be the module #{module_name}"
    end 
    
    def negative_failure_message
      puts "Content: #{content}" if RSpec::Generator.debug?      
      "Did no expected there to be the module #{module_name}"
    end
               
  end
  
  def have_module(module_name)
    HaveModule.new(module_name)
  end    
end  

Version data entries

2 entries across 2 versions & 1 rubygems

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