aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/testing/file_fixtures_test.rb
blob: 9f28252c31e84ed40333bdb14b16e36dee201f86 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require "abstract_unit"

require "pathname"

class FileFixturesTest < ActiveSupport::TestCase
  self.file_fixture_path = File.expand_path("../file_fixtures", __dir__)

  test "#file_fixture returns Pathname to file fixture" do
    path = file_fixture("sample.txt")
    assert_kind_of Pathname, path
    assert_match %r{.*/test/file_fixtures/sample\.txt$}, path.to_s
  end

  test "raises an exception when the fixture file does not exist" do
    e = assert_raises(ArgumentError) do
      file_fixture("nope")
    end
    assert_match(/^the directory '[^']+test\/file_fixtures' does not contain a file named 'nope'$/, e.message)
  end
end

class FileFixturesPathnameDirectoryTest < ActiveSupport::TestCase
  self.file_fixture_path = Pathname.new(File.expand_path("../file_fixtures", __dir__))

  test "#file_fixture_path returns Pathname to file fixture" do
    path = file_fixture("sample.txt")
    assert_kind_of Pathname, path
    assert_match %r{.*/test/file_fixtures/sample\.txt$}, path.to_s
  end
end