Sha256: 0ebc32d04620eac23c6399dac191709b3a01d950314717a7c478e617cc98a404

Contents?: true

Size: 1.14 KB

Versions: 185

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

require "active_support/concern"

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

185 entries across 177 versions & 25 rubygems

Version Path
activesupport-7.1.0.beta1 lib/active_support/testing/file_fixtures.rb
activesupport-7.0.8 lib/active_support/testing/file_fixtures.rb
activesupport-7.0.7.2 lib/active_support/testing/file_fixtures.rb
activesupport-6.1.7.6 lib/active_support/testing/file_fixtures.rb
activesupport-7.0.7.1 lib/active_support/testing/file_fixtures.rb
activesupport-6.1.7.5 lib/active_support/testing/file_fixtures.rb
activesupport-7.0.7 lib/active_support/testing/file_fixtures.rb
mlh-rubocop-config-1.0.2 vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.6/lib/active_support/testing/file_fixtures.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.5/lib/active_support/testing/file_fixtures.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.6/lib/active_support/testing/file_fixtures.rb
activesupport-7.0.6 lib/active_support/testing/file_fixtures.rb
activesupport-7.0.5.1 lib/active_support/testing/file_fixtures.rb
activesupport-6.1.7.4 lib/active_support/testing/file_fixtures.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activesupport-6.1.6.1/lib/active_support/testing/file_fixtures.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activesupport-7.0.2.3/lib/active_support/testing/file_fixtures.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activesupport-7.0.3.1/lib/active_support/testing/file_fixtures.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/testing/file_fixtures.rb
fablicop-1.10.2 vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.5/lib/active_support/testing/file_fixtures.rb
activesupport-7.0.5 lib/active_support/testing/file_fixtures.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/activesupport-7.0.4.3/lib/active_support/testing/file_fixtures.rb