Skip to content

Commit b64a9a4

Browse files
committed
Use fixture_paths in FixtureFileUploadSupport
1 parent f1afa0c commit b64a9a4

File tree

2 files changed

+52
-19
lines changed

2 files changed

+52
-19
lines changed

lib/rspec/rails/fixture_file_upload_support.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def rails_fixture_file_wrapper
1414
resolved_fixture_path =
1515
if respond_to?(:file_fixture_path) && !file_fixture_path.nil?
1616
file_fixture_path.to_s
17+
elsif respond_to?(:fixture_paths)
18+
(RSpec.configuration.fixture_paths&.first || '').to_s
1719
else
1820
(RSpec.configuration.fixture_path || '').to_s
1921
end
@@ -26,7 +28,11 @@ class RailsFixtureFileWrapper
2628
include ActiveSupport::Testing::FileFixtures
2729

2830
class << self
29-
attr_accessor :fixture_path
31+
if ::Rails::VERSION::STRING < "7.1.0"
32+
attr_accessor :fixture_path
33+
else
34+
attr_accessor :fixture_paths
35+
end
3036

3137
# Get instance of wrapper
3238
def instance

spec/rspec/rails/fixture_file_upload_support_spec.rb

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,54 @@
11
module RSpec::Rails
22
RSpec.describe FixtureFileUploadSupport do
3-
context 'with fixture path set in config' do
4-
it 'resolves fixture file' do
5-
RSpec.configuration.fixture_path = File.dirname(__FILE__)
6-
expect_to_pass fixture_file_upload_resolved('fixture_file_upload_support_spec.rb')
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 fixture_file_upload_resolved('fixture_file_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 fixture_file_upload_resolved('fixture_file_upload_support_spec.rb')
13+
end
714
end
815

9-
it 'resolves supports `Pathname` objects' do
10-
RSpec.configuration.fixture_path = Pathname(File.dirname(__FILE__))
11-
expect_to_pass fixture_file_upload_resolved('fixture_file_upload_support_spec.rb')
16+
context 'with fixture path set in spec' do
17+
it 'resolves fixture file' do
18+
expect_to_pass fixture_file_upload_resolved('fixture_file_upload_support_spec.rb', File.dirname(__FILE__))
19+
end
1220
end
13-
end
1421

15-
context 'with fixture path set in spec' do
16-
it 'resolves fixture file' do
17-
expect_to_pass fixture_file_upload_resolved('fixture_file_upload_support_spec.rb', File.dirname(__FILE__))
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 fixture_file_upload_resolved('spec/rspec/rails/fixture_file_upload_support_spec.rb')
26+
end
1827
end
19-
end
28+
else
29+
context 'with fixture paths set in config' do
30+
it 'resolves fixture file' do
31+
RSpec.configuration.fixture_paths = [File.dirname(__FILE__)]
32+
expect_to_pass fixture_file_upload_resolved('fixture_file_upload_support_spec.rb')
33+
end
2034

21-
context 'with fixture path not set' do
22-
it 'resolves fixture using relative path' do
23-
RSpec.configuration.fixture_path = nil
24-
expect_to_pass fixture_file_upload_resolved('spec/rspec/rails/fixture_file_upload_support_spec.rb')
35+
it 'resolves supports `Pathname` objects' do
36+
RSpec.configuration.fixture_paths = [Pathname(File.dirname(__FILE__))]
37+
expect_to_pass fixture_file_upload_resolved('fixture_file_upload_support_spec.rb')
38+
end
39+
end
40+
41+
context 'with fixture path set in spec' do
42+
it 'resolves fixture file' do
43+
expect_to_pass fixture_file_upload_resolved('fixture_file_upload_support_spec.rb', File.dirname(__FILE__))
44+
end
45+
end
46+
47+
context 'with fixture path not set' do
48+
it 'resolves fixture using relative path' do
49+
RSpec.configuration.fixture_path = nil
50+
expect_to_pass fixture_file_upload_resolved('spec/rspec/rails/fixture_file_upload_support_spec.rb')
51+
end
2552
end
2653
end
2754

@@ -31,11 +58,11 @@ def expect_to_pass(group)
3158
expect(result).to be true
3259
end
3360

34-
def fixture_file_upload_resolved(fixture_name, fixture_path = nil)
61+
def fixture_file_upload_resolved(fixture_name, file_fixture_path = nil)
3562
RSpec::Core::ExampleGroup.describe do
3663
include RSpec::Rails::FixtureFileUploadSupport
3764

38-
self.file_fixture_path = fixture_path
65+
self.file_fixture_path = file_fixture_path
3966

4067
it 'supports fixture file upload' do
4168
file = fixture_file_upload(fixture_name)

0 commit comments

Comments
 (0)