Skip to content

Commit 79aa6c1

Browse files
11factorysebjacobs
authored andcommitted
Use relative path when no fixture_path configured (rspec#1943)
1 parent 55e007d commit 79aa6c1

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

lib/rspec/rails/fixture_file_upload_support.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ module FixtureFileUploadSupport
77
private
88

99
def rails_fixture_file_wrapper
10+
RailsFixtureFileWrapper.fixture_path = nil
1011
resolved_fixture_path = (fixture_path || RSpec.configuration.fixture_path || '')
11-
RailsFixtureFileWrapper.fixture_path = File.join(resolved_fixture_path, '')
12+
RailsFixtureFileWrapper.fixture_path = File.join(resolved_fixture_path, '') unless resolved_fixture_path.strip.empty?
1213
RailsFixtureFileWrapper.instance
1314
end
1415

@@ -18,7 +19,7 @@ class RailsFixtureFileWrapper
1819
class << self
1920
attr_reader :fixture_path
2021

21-
# Get the instance of wrapper
22+
# Get instance of wrapper
2223
def instance
2324
@instance ||= new
2425
end

spec/rspec/rails/fixture_file_upload_support_spec.rb

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,33 @@
33
module RSpec::Rails
44
describe FixtureFileUploadSupport do
55
context 'with fixture path set in config' do
6-
before { RSpec.configuration.fixture_path = File.dirname(__FILE__) }
7-
86
it 'resolves fixture file' do
9-
expect(fixture_file_upload_resolved.run).to be true
7+
RSpec.configuration.fixture_path = File.dirname(__FILE__)
8+
expect(fixture_file_upload_resolved('fixture_file_upload_support_spec.rb').run).to be true
109
end
1110
end
1211

1312
context 'with fixture path set in spec' do
1413
it 'resolves fixture file' do
15-
expect(fixture_file_upload_resolved(File.dirname(__FILE__)).run).to be true
14+
expect(fixture_file_upload_resolved('fixture_file_upload_support_spec.rb', File.dirname(__FILE__)).run).to be true
15+
end
16+
end
17+
18+
context 'with fixture path not set' do
19+
it 'resolves fixture using relative path' do
20+
RSpec.configuration.fixture_path = nil
21+
expect(fixture_file_upload_resolved('spec/rspec/rails/fixture_file_upload_support_spec.rb').run).to be true
1622
end
1723
end
1824

19-
def fixture_file_upload_resolved(fixture_path = nil)
25+
def fixture_file_upload_resolved(fixture_name, fixture_path = nil)
2026
RSpec::Core::ExampleGroup.describe do
2127
include RSpec::Rails::FixtureFileUploadSupport
2228

23-
self.fixture_path = fixture_path if fixture_path
29+
self.fixture_path = fixture_path
2430

2531
it 'supports fixture file upload' do
26-
file = fixture_file_upload(File.basename(__FILE__))
32+
file = fixture_file_upload(fixture_name)
2733
expect(file.read).to match(/describe FixtureFileUploadSupport/im)
2834
end
2935
end

0 commit comments

Comments
 (0)