class GeneratorSpec::Matcher::File
Taken (with permission) from beard by Yahuda Katz github.com/carlhuda/beard
Public Class Methods
Source
# 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
Public Instance Methods
Source
# File lib/generator_spec/matcher.rb, line 22 def contains(text) @contents << text end
Source
# File lib/generator_spec/matcher.rb, line 8 def description 'file attributes and content' end
Source
# File lib/generator_spec/matcher.rb, line 26 def does_not_contain(text) @negative_contents << text end
Source
# 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
Protected Instance Methods
Source
# File lib/generator_spec/matcher.rb, line 40 def check_contents(file) contents = ::File.read(file) @contents.each do |string| unless contents.include?(string) throw :failure, [file, string, contents] end end @negative_contents.each do |string| if contents.include?(string) throw :failure, [:not, file, string, contents] end end end