class GeneratorSpec::Matcher::File

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

Public Class Methods

new(name, &block) click to toggle source
# File lib/generator_spec/matcher.rb, line 7
def initialize(name, &block)
  @contents = []
  @name = name

  if block_given?
    instance_eval(&block)
  end
end

Public Instance Methods

contains(text) click to toggle source
# File lib/generator_spec/matcher.rb, line 16
def contains(text)
  @contents << text
end
matches?(root) click to toggle source
# 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

Protected Instance Methods

check_contents(file) click to toggle source
# File lib/generator_spec/matcher.rb, line 30
def check_contents(file)
  contents = ::File.read(file)

  @contents.each do |string|
    unless contents.include?(string)
      throw :failure, [file, string, contents]
    end
  end
end