Module: Rails4Backports::Testing::FileFixtures

Defined in:
lib/rails_4_backports/file_fixtures.rb

Overview

Adds simple access to sample files called file fixtures. File fixtures are normal files stored in ActiveSupport::TestCase.file_fixture_path.

File fixtures are represented as Pathname objects. This makes it easy to extract specific information:

file_fixture("example.txt").read # get the file's content
file_fixture("example.mp3").size # get the file size

Class Method Summary collapse

Class Method Details

.file_fixture(fixture_name) ⇒ Object

Returns a Pathname to the fixture file named fixture_name.

Raises ArgumentError if fixture_name can’t be found.



26
27
28
29
30
31
32
33
34
35
# File 'lib/rails_4_backports/file_fixtures.rb', line 26

def self.file_fixture(fixture_name)
  path = Pathname.new(File.join(file_fixture_path, fixture_name))

  if path.exist?
    path
  else
    msg = "the directory '%s' does not contain a file named '%s'"
    raise ArgumentError, msg % [file_fixture_path, fixture_name]
  end
end

.file_fixture_pathObject



19
20
21
# File 'lib/rails_4_backports/file_fixtures.rb', line 19

def self.file_fixture_path
  @path
end

.file_fixture_path=(path) ⇒ Object



15
16
17
# File 'lib/rails_4_backports/file_fixtures.rb', line 15

def self.file_fixture_path=(path)
  @path = path
end