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.



12
13
14
15
16
17
18
19
20
# File 'lib/generator_spec/matcher.rb', line 12

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

  if block_given?
    instance_eval(&block)
  end
end

Instance Method Details

#contains(text) ⇒ Object



22
23
24
# File 'lib/generator_spec/matcher.rb', line 22

def contains(text)
  @contents << text
end

#descriptionObject



8
9
10
# File 'lib/generator_spec/matcher.rb', line 8

def description
  'file attributes and content'
end

#does_not_contain(text) ⇒ Object



26
27
28
# File 'lib/generator_spec/matcher.rb', line 26

def does_not_contain(text)
  @negative_contents << text
end

#matches?(root) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
# File 'lib/generator_spec/matcher.rb', line 30

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

  check_contents(root.join(@name))
end