Sha256: 26befdb161e689613bf411dc1da0a8740cec0386836471c2f2a6bb4e1e610ce6

Contents?: true

Size: 954 Bytes

Versions: 2

Compression:

Stored size: 954 Bytes

Contents

module RSpec::RubyContentMatchers
  class HaveRegion < RSpec::RubyContentMatcher
    attr_reader :region

    def initialize(region)
      @region = region.to_s
    end

    def matches?(content) 
      super
      match_res = (content =~ /#{region}(.*)#{end_epxr}/m)
      if block_given? && $1
        ruby_content = $1.strip.extend(RSpec::RubyContent::Helpers)
        yield ruby_content        
      end
      match_res
    end          
  
    def failure_message 
      super
      "Expected there to be a #{region} region"
    end 
    
    def negative_failure_message    
      super
      "Did no expected there to be a #{region} region"
    end               
    
    protected
    
    def end_expr
      '(private|protected|public|$)'
    end
  end
  
  def have_public
    HaveRegion.new :public
  end    

  def have_protected
    HaveRegion.new :protected
  end    

  def have_private
    HaveRegion.new :private
  end    
end
      

Version data entries

2 entries across 2 versions & 1 rubygems

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