Sha256: 9720c31308f8d3bcf1e84e0330af73b99bea16831a765eae7ca9f098fd254cb1

Contents?: true

Size: 1.06 KB

Versions: 6

Compression:

Stored size: 1.06 KB

Contents

module CoreExt
  module Testing
    # Adds simple access to sample files called file fixtures.
    # File fixtures are normal files stored in
    # <tt>CoreExt::TestCase.file_fixture_path</tt>.
    #
    # 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
    module FileFixtures
      extend CoreExt::Concern

      included do
        class_attribute :file_fixture_path, instance_writer: false
      end

      # Returns a +Pathname+ to the fixture file named +fixture_name+.
      #
      # Raises +ArgumentError+ if +fixture_name+ can't be found.
      def 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
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
core_ext-0.0.6 lib/core_ext/testing/file_fixtures.rb
core_ext-0.0.5 lib/core_ext/testing/file_fixtures.rb
core_ext-0.0.4 lib/core_ext/testing/file_fixtures.rb
core_ext-0.0.3 lib/core_ext/testing/file_fixtures.rb
core_ext-0.0.2 lib/core_ext/testing/file_fixtures.rb
core_ext-0.0.1 lib/core_ext/testing/file_fixtures.rb