Class: GeneratorSpec::Matcher::File

Inherits:
Object
  • Object
show all
Defined in:
lib/generator_spec/matcher.rb

Overview

Taken (with permission) from beard by Yahuda Katz github.com/carlhuda/beard

Direct Known Subclasses

Migration

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ File

Returns a new instance of File.



7
8
9
10
11
12
13
14
# File 'lib/generator_spec/matcher.rb', line 7

def initialize(name, &block)
  @contents = []
  @name = name

  if block_given?
    instance_eval(&block)
  end
end

Instance Method Details

#contains(text) ⇒ Object



16
17
18
# File 'lib/generator_spec/matcher.rb', line 16

def contains(text)
  @contents << text
end

#matches?(root) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
# File 'lib/generator_spec/matcher.rb', line 20

def matches?(root)
  unless root.join(@name).exist?
    throw :failure, root.join(@name)
  end

  check_contents(root.join(@name))
end