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