Module: FSTest::Assertions
- Defined in:
- lib/fstest.rb
Instance Method Summary collapse
-
#assert_file(relative, *contents) {|read| ... } ⇒ Object
(also: #assert_directory)
Asserts a given file exists.
-
#assert_no_file(relative) ⇒ Object
(also: #assert_no_directory)
Asserts a given file does not exist.
Instance Method Details
#assert_file(relative, *contents) {|read| ... } ⇒ Object Also known as: assert_directory
Asserts a given file exists. You need to supply an absolute path or a path relative to the configured destination:
assert_file "config/environment.rb"
You can also give extra arguments. If the argument is a regexp, it will check if the regular expression matches the given file content. If it’s a string, it compares the file with the given string:
assert_file "config/environment.rb", /initialize/
Finally, when a block is given, it yields the file content:
assert_file "app/controller/products_controller.rb" do |controller|
assert_instance_method :index, content do |index|
assert_match /Product\.all/, index
end
end
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fstest.rb', line 40 def assert_file(relative, *contents) absolute = File.(relative, base_directory) assert File.exists?(absolute), "Expected file #{relative.inspect} to exist, but does not" read = File.read(absolute) if block_given? || !contents.empty? yield read if block_given? contents.each do |content| case content when String assert_equal content, read when Regexp assert_match content, read end end end |
#assert_no_file(relative) ⇒ Object Also known as: assert_no_directory
Asserts a given file does not exist. You need to supply an absolute path or a path relative to the configured destination:
assert_no_file "config/random.rb"
63 64 65 66 |
# File 'lib/fstest.rb', line 63 def assert_no_file(relative) absolute = File.(relative, base_directory) assert !File.exists?(absolute), "Expected file #{relative.inspect} to not exist, but does" end |