Skip to content

Commit

Permalink
refactor: Prefer __dir__ over File.dirname(__FILE__)
Browse files Browse the repository at this point in the history
  • Loading branch information
olleolleolle committed Dec 1, 2022
1 parent 20c9cb4 commit 64b059d
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Code Improvements:
* refactor: Use Dir.glob only once in gemspec's "files" directive @olleolleolle
* Configure RSpec's zero-monkey patching mode @olleolleolle
* Added support for JRuby 9.4 @mikel
* Prefer `__dir__` @olleolleolle

This comment has been minimized.

Copy link
@Nakilon

Nakilon Dec 4, 2022

FYI the dir is influenced by pwd


Bug Fixes:

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if !ENV["APPRAISAL_INITIALIZED"] && !ENV["CI"]
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __FILE__)
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', __dir__)
end
require 'rubygems'
require 'bundler/setup'
Expand Down
2 changes: 1 addition & 1 deletion lib/mail/multibyte/unicode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ class << self

# Returns the directory in which the data files are stored
def self.dirname
File.dirname(__FILE__) + '/../values/'
__dir__ + '/../values/'
end

# Returns the filename for the data file for this version
Expand Down
2 changes: 1 addition & 1 deletion rakelib/corpus.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require 'benchmark'
namespace :corpus do

task :load_mail do
require File.expand_path('../../spec/environment', __FILE__)
require File.expand_path('../spec/environment', __dir__)
require 'mail'
end

Expand Down
2 changes: 1 addition & 1 deletion spec/environment.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)

begin
require 'byebug'
Expand Down
2 changes: 1 addition & 1 deletion spec/mail/network/delivery_methods/file_delivery_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
end

describe "general usage" do
tmpdir = File.expand_path('../../../../tmp/mail', __FILE__)
tmpdir = File.expand_path('../../../tmp/mail', __dir__)

it "should send an email to a file" do
Mail.defaults do
Expand Down
2 changes: 1 addition & 1 deletion spec/mail/network_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class MyRetriever; def initialize(settings); end; end

it "should be able to change the delivery_method and pass in settings" do
mail = Mail.new
tmpdir = File.expand_path('../../../tmp/mail', __FILE__)
tmpdir = File.expand_path('../../tmp/mail', __dir__)
mail.delivery_method :file, :location => tmpdir
expect(mail.delivery_method.class).to eq Mail::FileDelivery
expect(mail.delivery_method.settings).to eql({:location => tmpdir,
Expand Down
8 changes: 4 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# encoding: utf-8
# frozen_string_literal: true
require File.expand_path('../environment', __FILE__)
require File.expand_path('environment', __dir__)

unless defined?(MAIL_ROOT)
$stderr.puts("Running Specs under Ruby Version #{RUBY_VERSION}")
MAIL_ROOT = File.join(File.dirname(__FILE__), '../')
MAIL_ROOT = File.join(__dir__, '../')
end

unless defined?(SPEC_ROOT)
SPEC_ROOT = File.join(File.dirname(__FILE__))
SPEC_ROOT = __dir__
end

unless defined?(MAIL_SPEC_SUITE_RUNNING)
Expand All @@ -17,7 +17,7 @@
end

require 'rspec'
require File.join(File.dirname(__FILE__), 'matchers', 'break_down_to')
require File.join(__dir__, 'matchers', 'break_down_to')

require 'mail'

Expand Down

0 comments on commit 64b059d

Please sign in to comment.