|
| 1 | +module RSpec::Rails |
| 2 | + RSpec.describe FileFixtureUploadSupport do |
| 3 | + if ::Rails::VERSION::STRING < "7.1.0" |
| 4 | + context 'with fixture path set in config' do |
| 5 | + it 'resolves fixture file' do |
| 6 | + RSpec.configuration.fixture_path = File.dirname(__FILE__) |
| 7 | + expect_to_pass file_fixture_upload_resolved('file_fixture_upload_support_spec.rb') |
| 8 | + end |
| 9 | + |
| 10 | + it 'resolves supports `Pathname` objects' do |
| 11 | + RSpec.configuration.fixture_path = Pathname(File.dirname(__FILE__)) |
| 12 | + expect_to_pass file_fixture_upload_resolved('file_fixture_upload_support_spec.rb') |
| 13 | + end |
| 14 | + end |
| 15 | + |
| 16 | + context 'with fixture path set in spec' do |
| 17 | + it 'resolves fixture file' do |
| 18 | + expect_to_pass file_fixture_upload_resolved('file_fixture_upload_support_spec.rb', File.dirname(__FILE__)) |
| 19 | + end |
| 20 | + end |
| 21 | + |
| 22 | + context 'with fixture path not set' do |
| 23 | + it 'resolves fixture using relative path' do |
| 24 | + RSpec.configuration.fixture_path = nil |
| 25 | + expect_to_pass file_fixture_upload_resolved('spec/rspec/rails/file_fixture_upload_support_spec.rb') |
| 26 | + end |
| 27 | + end |
| 28 | + |
| 29 | + def file_fixture_upload_resolved(fixture_name, file_fixture_path = nil) |
| 30 | + RSpec::Core::ExampleGroup.describe do |
| 31 | + include RSpec::Rails::FileFixtureUploadSupport |
| 32 | + |
| 33 | + self.file_fixture_path = file_fixture_path |
| 34 | + |
| 35 | + it 'supports fixture_file_upload' do |
| 36 | + file = fixture_file_upload(fixture_name) |
| 37 | + expect(file.read).to match(/describe FileFixtureUploadSupport/im) |
| 38 | + end |
| 39 | + end |
| 40 | + end |
| 41 | + else |
| 42 | + context 'with fixture paths set in config' do |
| 43 | + it 'resolves fixture file' do |
| 44 | + RSpec.configuration.fixture_paths = [File.dirname(__FILE__)] |
| 45 | + expect_to_pass file_fixture_upload_resolved('file_fixture_upload_support_spec.rb') |
| 46 | + end |
| 47 | + |
| 48 | + it 'resolves supports `Pathname` objects' do |
| 49 | + RSpec.configuration.fixture_paths = [Pathname(File.dirname(__FILE__))] |
| 50 | + expect_to_pass file_fixture_upload_resolved('file_fixture_upload_support_spec.rb') |
| 51 | + end |
| 52 | + end |
| 53 | + |
| 54 | + context 'with fixture path set in spec' do |
| 55 | + it 'resolves fixture file' do |
| 56 | + expect_to_pass file_fixture_upload_resolved('file_fixture_upload_support_spec.rb', File.dirname(__FILE__)) |
| 57 | + end |
| 58 | + end |
| 59 | + |
| 60 | + context 'with fixture path not set' do |
| 61 | + it 'resolves fixture using relative path' do |
| 62 | + RSpec.configuration.fixture_path = nil |
| 63 | + expect_to_pass file_fixture_upload_resolved('spec/rspec/rails/file_fixture_upload_support_spec.rb') |
| 64 | + end |
| 65 | + end |
| 66 | + |
| 67 | + def file_fixture_upload_resolved(fixture_name, file_fixture_path = nil) |
| 68 | + RSpec::Core::ExampleGroup.describe do |
| 69 | + include RSpec::Rails::FileFixtureUploadSupport |
| 70 | + |
| 71 | + self.file_fixture_path = file_fixture_path |
| 72 | + |
| 73 | + it 'supports file_fixture_upload' do |
| 74 | + file = file_fixture_upload(fixture_name) |
| 75 | + expect(file.read).to match(/describe FileFixtureUploadSupport/im) |
| 76 | + end |
| 77 | + |
| 78 | + it 'supports fixture_file_upload' do |
| 79 | + file = fixture_file_upload(fixture_name) |
| 80 | + expect(file.read).to match(/describe FileFixtureUploadSupport/im) |
| 81 | + end |
| 82 | + end |
| 83 | + end |
| 84 | + end |
| 85 | + |
| 86 | + def expect_to_pass(group) |
| 87 | + result = group.run(failure_reporter) |
| 88 | + failure_reporter.exceptions.map { |e| raise e } |
| 89 | + expect(result).to be true |
| 90 | + end |
| 91 | + end |
| 92 | +end |
0 commit comments