Class: RSpec::RubyContentMatchers::HaveRegion

Inherits:
RSpec::RubyContentMatcher show all
Defined in:
lib/generator_spec/matchers/content/have_region.rb

Instance Attribute Summary collapse

Attributes inherited from RSpec::RubyContentMatcher

#content

Instance Method Summary collapse

Methods inherited from RSpec::RubyContentMatcher

#debug_content

Constructor Details

#initialize(region) ⇒ HaveRegion

Returns a new instance of HaveRegion.



5
6
7
# File 'lib/generator_spec/matchers/content/have_region.rb', line 5

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

Instance Attribute Details

#regionObject (readonly)

Returns the value of attribute region.



3
4
5
# File 'lib/generator_spec/matchers/content/have_region.rb', line 3

def region
  @region
end

Instance Method Details

#failure_messageObject



19
20
21
22
# File 'lib/generator_spec/matchers/content/have_region.rb', line 19

def failure_message 
  super
  "Expected there to be a #{region} region"
end

#matches?(content) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
# File 'lib/generator_spec/matchers/content/have_region.rb', line 9

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

#negative_failure_messageObject



24
25
26
27
# File 'lib/generator_spec/matchers/content/have_region.rb', line 24

def negative_failure_message    
  super
  "Did no expected there to be a #{region} region"
end