Sha256: 66a17d97cb996e86e83e1e0810b1805e21f1722144bc673cfcd44d0ab8ff7049

Contents?: true

Size: 1.08 KB

Versions: 75

Compression:

Stored size: 1.08 KB

Contents

module ActiveSupport
  module Testing
    # Adds simple access to sample files called file fixtures.
    # File fixtures are normal files stored in
    # <tt>ActiveSupport::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 ActiveSupport::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

75 entries across 72 versions & 9 rubygems

Version Path
activesupport-5.0.5.rc2 lib/active_support/testing/file_fixtures.rb
activesupport-5.1.3.rc2 lib/active_support/testing/file_fixtures.rb
activesupport-5.0.5.rc1 lib/active_support/testing/file_fixtures.rb
activesupport-5.1.3.rc1 lib/active_support/testing/file_fixtures.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/activesupport-5.0.2/lib/active_support/testing/file_fixtures.rb
tdiary-5.0.5 vendor/bundle/gems/activesupport-5.1.2/lib/active_support/testing/file_fixtures.rb
tdiary-5.0.5 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/testing/file_fixtures.rb
activesupport-5.1.2 lib/active_support/testing/file_fixtures.rb
activesupport-5.1.2.rc1 lib/active_support/testing/file_fixtures.rb
activesupport-5.0.4 lib/active_support/testing/file_fixtures.rb
activesupport-5.0.4.rc1 lib/active_support/testing/file_fixtures.rb
activesupport-5.1.1 lib/active_support/testing/file_fixtures.rb
activesupport-5.0.3 lib/active_support/testing/file_fixtures.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activesupport-5.0.2/lib/active_support/testing/file_fixtures.rb
activesupport-5.1.0 lib/active_support/testing/file_fixtures.rb
activesupport-5.1.0.rc2 lib/active_support/testing/file_fixtures.rb
lazy_record-0.2.1 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/testing/file_fixtures.rb
lazy_record-0.2.0 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/testing/file_fixtures.rb
lazy_record-0.1.9 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/testing/file_fixtures.rb
lazy_record-0.1.8 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/testing/file_fixtures.rb