Skip to content

[fix-1921] use relative path when no fixture_path configured #1943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/rspec/rails/fixture_file_upload_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ module FixtureFileUploadSupport
private

def rails_fixture_file_wrapper
RailsFixtureFileWrapper.fixture_path = nil
resolved_fixture_path = (fixture_path || RSpec.configuration.fixture_path || '')
RailsFixtureFileWrapper.fixture_path = File.join(resolved_fixture_path, '')
RailsFixtureFileWrapper.fixture_path = File.join(resolved_fixture_path, '') unless resolved_fixture_path.strip.empty?
RailsFixtureFileWrapper.instance
end

Expand All @@ -18,7 +19,7 @@ class RailsFixtureFileWrapper
class << self
attr_reader :fixture_path

# Get the instance of wrapper
# Get instance of wrapper
def instance
@instance ||= new
end
Expand Down
20 changes: 13 additions & 7 deletions spec/rspec/rails/fixture_file_upload_support_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,33 @@
module RSpec::Rails
describe FixtureFileUploadSupport do
context 'with fixture path set in config' do
before { RSpec.configuration.fixture_path = File.dirname(__FILE__) }

it 'resolves fixture file' do
expect(fixture_file_upload_resolved.run).to be true
RSpec.configuration.fixture_path = File.dirname(__FILE__)
expect(fixture_file_upload_resolved('fixture_file_upload_support_spec.rb').run).to be true
end
end

context 'with fixture path set in spec' do
it 'resolves fixture file' do
expect(fixture_file_upload_resolved(File.dirname(__FILE__)).run).to be true
expect(fixture_file_upload_resolved('fixture_file_upload_support_spec.rb', File.dirname(__FILE__)).run).to be true
end
end

context 'with fixture path not set' do
it 'resolves fixture using relative path' do
RSpec.configuration.fixture_path = nil
expect(fixture_file_upload_resolved('spec/rspec/rails/fixture_file_upload_support_spec.rb').run).to be true
end
end

def fixture_file_upload_resolved(fixture_path = nil)
def fixture_file_upload_resolved(fixture_name, fixture_path = nil)
RSpec::Core::ExampleGroup.describe do
include RSpec::Rails::FixtureFileUploadSupport

self.fixture_path = fixture_path if fixture_path
self.fixture_path = fixture_path

it 'supports fixture file upload' do
file = fixture_file_upload(File.basename(__FILE__))
file = fixture_file_upload(fixture_name)
expect(file.read).to match(/describe FixtureFileUploadSupport/im)
end
end
Expand Down