Module: FileSpec::Matchers
- Extended by:
- RSpec::Matchers::DSL
- Defined in:
- lib/file_spec.rb
Overview
A collection of RSpec matchers for making file assertions
Instance Method Summary collapse
-
#be_a_directory ⇒ Object
Determine if a directory exists.
-
#be_a_file ⇒ Object
Determine if a file exists.
-
#be_executable ⇒ Object
Test if a file is executable.
-
#have_content ⇒ Object
Determine if a file has matching content.
-
#have_entries ⇒ Object
Find the files in a directory.
Instance Method Details
#be_a_directory ⇒ Object
Determine if a directory exists
146 147 148 |
# File 'lib/file_spec.rb', line 146 matcher :be_a_directory do match { |actual| File.directory?(actual) } end |
#be_a_file ⇒ Object
Determine if a file exists
136 137 138 |
# File 'lib/file_spec.rb', line 136 matcher :be_a_file do match { |actual| File.file?(actual) } end |
#be_executable ⇒ Object
Test if a file is executable
156 157 158 |
# File 'lib/file_spec.rb', line 156 matcher :be_executable do match { |actual| File.executable?(actual) } end |
#have_content ⇒ Object
Determine if a file has matching content
120 121 122 123 124 125 126 127 128 |
# File 'lib/file_spec.rb', line 120 matcher :have_content do |expected| match do |actual| @actual = File.read(actual) values_match?(expected, @actual) end diffable if expected.is_a?(String) description { "have content: #{description_of(expected)}" } end |
#have_entries ⇒ Object
Find the files in a directory
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/file_spec.rb', line 165 matcher :have_entries do |expected| match do |actual| root = Pathname.new(actual) @expected = expected.sort @actual = root.glob("**/*", File::FNM_DOTMATCH) .select(&:file?) .map { |path| path.relative_path_from(root).to_s } .sort values_match?(@expected, @actual) end description { "contain files: #{description_of(@expected)}" } end |