Module: ActiveSupport::Testing::FileFixtures
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Included In:
::ActionCable::Channel::TestCase,
::ActionCable::Connection::TestCase,
::ActionCable::TestCase,
::ActionController::TestCase,
::ActionDispatch::IntegrationTest,
::ActionDispatch::SystemTestCase,
::ActionMailbox::TestCase,
::ActionMailer::TestCase,
::ActionView::TestCase,
::ActiveJob::TestCase,
::ActiveStorage::FixtureSet,
::ActiveSupport::TestCase,
::Rails::Generators::TestCase
| |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
::ActiveSupport::Concern
|
|
| Defined in: | activesupport/lib/active_support/testing/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
::ActiveSupport::Concern - Extended
| class_methods | Define class methods from given block. |
| included | Evaluate given block in context of base class, so that you can write class macros here. |
| prepended | Evaluate given block in context of base class, so that you can write class macros here. |
| append_features, prepend_features | |
Instance Method Summary
-
#file_fixture(fixture_name)
Returns a
::Pathnameto the fixture file namedfixture_name.
DSL Calls
included
[ GitHub ]19 20 21
# File 'activesupport/lib/active_support/testing/file_fixtures.rb', line 19
included do class_attribute :file_fixture_path, instance_writer: false end
Instance Method Details
#file_fixture(fixture_name)
Returns a ::Pathname to the fixture file named fixture_name.
Raises ArgumentError if fixture_name can’t be found.
# File 'activesupport/lib/active_support/testing/file_fixtures.rb', line 26
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