Skip to content

Commit ba7aeb3

Browse files
author
Laurent Cobos
committed
[fix-1921] use relative path when no fixture_path
1 parent d4830a9 commit ba7aeb3

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/rspec/rails/fixture_file_upload_support.rb

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

99
def rails_fixture_file_wrapper
1010
resolved_fixture_path = (fixture_path || RSpec.configuration.fixture_path || '')
11-
RailsFixtureFileWrapper.fixture_path = File.join(resolved_fixture_path, '')
11+
RailsFixtureFileWrapper.fixture_path = File.join(resolved_fixture_path, '') unless resolved_fixture_path.strip.empty?
1212
RailsFixtureFileWrapper.instance
1313
end
1414

@@ -18,7 +18,7 @@ class RailsFixtureFileWrapper
1818
class << self
1919
attr_reader :fixture_path
2020

21-
# Get the instance of wrapper
21+
# Get instance of wrapper
2222
def instance
2323
@instance ||= new
2424
end

spec/rspec/rails/fixture_file_upload_support_spec.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,32 @@ module RSpec::Rails
66
before { RSpec.configuration.fixture_path = File.dirname(__FILE__) }
77

88
it 'resolves fixture file' do
9-
expect(fixture_file_upload_resolved.run).to be true
9+
expect(fixture_file_upload_resolved('fixture_file_upload_support_spec.rb').run).to be true
1010
end
1111
end
1212

1313
context 'with fixture path set in spec' do
1414
it 'resolves fixture file' do
15-
expect(fixture_file_upload_resolved(File.dirname(__FILE__)).run).to be true
15+
expect(fixture_file_upload_resolved('fixture_file_upload_support_spec.rb', File.dirname(__FILE__)).run).to be true
1616
end
1717
end
1818

19-
def fixture_file_upload_resolved(fixture_path = nil)
19+
context 'with fixture path not set' do
20+
before { RSpec.configuration.fixture_path = nil }
21+
22+
it 'resolves fixture with relative path' do
23+
expect(fixture_file_upload_resolved('fixture_file_upload_support_spec.rb').run).to be true
24+
end
25+
end
26+
27+
def fixture_file_upload_resolved(fixture_name, fixture_path = nil)
2028
RSpec::Core::ExampleGroup.describe do
2129
include RSpec::Rails::FixtureFileUploadSupport
2230

2331
self.fixture_path = fixture_path if fixture_path
2432

2533
it 'supports fixture file upload' do
26-
file = fixture_file_upload(File.basename(__FILE__))
34+
file = fixture_file_upload(fixture_name)
2735
expect(file.read).to match(/describe FixtureFileUploadSupport/im)
2836
end
2937
end

0 commit comments

Comments
 (0)