refactor: use __dir__ in File.expand_path

__dir__ is nice, and available.
This commit is contained in:
Olle Jonsson 2021-10-18 18:40:01 +02:00 committed by Jordan Owens
parent 5459750259
commit 1559a20b06
60 changed files with 68 additions and 68 deletions

View File

@ -404,7 +404,7 @@ end
```ruby
set :public_folder, File.dirname(__FILE__) + '/static'
set :public_folder, __dir__ + '/static'
```
URL ഇളിൽ ഡയറക്ടറി പാത ഉണ്ടാകില്ല . A file

View File

@ -9,7 +9,7 @@ task :spec => :test
CLEAN.include "**/*.rbc"
def source_version
@source_version ||= File.read(File.expand_path("../VERSION", __FILE__)).strip
@source_version ||= File.read(File.expand_path("VERSION", __dir__)).strip
end
def prev_feature

View File

@ -1,5 +1,5 @@
# encoding: utf-8
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift File.expand_path('lib', __dir__)
begin
require 'bundler'

View File

@ -1,4 +1,4 @@
version = File.read(File.expand_path("../../VERSION", __FILE__)).strip
version = File.read(File.expand_path("../VERSION", __dir__)).strip
Gem::Specification.new do |s|
# general infos

View File

@ -2,7 +2,7 @@ require 'rack/protection'
require 'rack/test'
require 'rack'
Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }
Dir[File.expand_path('support/**/*.rb', __dir__)].each { |f| require f }
# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.

View File

@ -1,4 +1,4 @@
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift File.expand_path('lib', __dir__)
require 'open-uri'
require 'yaml'
require 'sinatra/contrib/version'

View File

@ -28,7 +28,7 @@ module Sinatra
#
# class Runner < Sinatra::Runner
# def app_file
# File.expand_path("../server.rb", __FILE__)
# File.expand_path("server.rb", __dir__)
# end
# end
#
@ -49,7 +49,7 @@ module Sinatra
# For an example, check https://github.com/apotonick/roar/blob/master/test/integration/runner.rb
class Runner
def app_file
File.expand_path("../server.rb", __FILE__)
File.expand_path("server.rb", __dir__)
end
def run

View File

@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
version = File.read(File.expand_path("../../VERSION", __FILE__)).strip
version = File.read(File.expand_path("../VERSION", __dir__)).strip
Gem::Specification.new do |s|
s.name = "sinatra-contrib"

View File

@ -4,7 +4,7 @@ describe Sinatra::ConfigFile do
def config_file(*args, &block)
mock_app do
register Sinatra::ConfigFile
set :root, File.expand_path('../config_file', __FILE__)
set :root, File.expand_path('config_file', __dir__)
instance_eval(&block) if block
config_file(*args)
end

View File

@ -4,7 +4,7 @@ describe Sinatra::ContentFor do
subject do
Sinatra.new do
helpers Sinatra::ContentFor
set :views, File.expand_path("../content_for", __FILE__)
set :views, File.expand_path("content_for", __dir__)
end.new!
end
@ -215,7 +215,7 @@ describe Sinatra::ContentFor do
mock_app do
helpers Sinatra::ContentFor
set inner, :layout_engine => outer
set :views, File.expand_path("../content_for", __FILE__)
set :views, File.expand_path("content_for", __dir__)
get('/:view') { render(inner, params[:view].to_sym) }
get('/:layout/:view') do
render inner, params[:view].to_sym, :layout => params[:layout].to_sym

View File

@ -661,10 +661,10 @@ describe Sinatra::Namespace do
specify 'can use a custom views directory' do
mock_app do
set :views, File.expand_path('../namespace', __FILE__)
set :views, File.expand_path('namespace', __dir__)
send(verb, '/') { erb :foo }
namespace('/foo') do
set :views, File.expand_path('../namespace/nested', __FILE__)
set :views, File.expand_path('namespace/nested', __dir__)
send(verb) { erb :foo }
end
end

View File

@ -4,7 +4,7 @@ require 'fileutils'
describe Sinatra::Reloader do
# Returns the temporary directory.
def tmp_dir
File.expand_path('../../tmp', __FILE__)
File.expand_path('../tmp', __dir__)
end
# Returns the path of the Sinatra application file created by
@ -48,7 +48,7 @@ describe Sinatra::Reloader do
options[:parent] ||= 'Sinatra::Base'
update_file(app_file_path) do |f|
template_path = File.expand_path('../reloader/app.rb.erb', __FILE__)
template_path = File.expand_path('reloader/app.rb.erb', __dir__)
template = Tilt.new(template_path, nil, :trim => '<>')
f.write template.render(Object.new, options)
end

View File

@ -1,4 +1,4 @@
version = File.read(File.expand_path("../VERSION", __FILE__)).strip
version = File.read(File.expand_path("VERSION", __dir__)).strip
Gem::Specification.new 'sinatra', version do |s|
s.description = "Sinatra is a DSL for quickly creating web applications in Ruby with minimal effort."

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
begin
require 'asciidoctor'

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
class BaseTest < Minitest::Test
describe 'Sinatra::Base subclasses' do

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
begin
require 'builder'

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
begin
require 'coffee-script'

View File

@ -1,5 +1,5 @@
# I like coding: UTF-8
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
class CompileTest < Minitest::Test
def self.parses pattern, example, expected_params, mtype = :sinatra, mopts = {}

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
begin
require 'creole'

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
class DelegatorTest < Minitest::Test
class Mirror

View File

@ -1,5 +1,5 @@
# encoding: UTF-8
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
require 'erb'
class BaseTest < Minitest::Test

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
class ERBTest < Minitest::Test
def engine

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
class ExtensionsTest < Minitest::Test
module FooExtensions

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
class BeforeFilterTest < Minitest::Test
it "executes filters in the order defined" do

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
begin
require 'haml'

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
require 'date'
require 'json'

View File

@ -47,7 +47,7 @@ get '/send' do
end
get '/send_file' do
file = File.expand_path '../../views/a/in_a.str', __FILE__
file = File.expand_path '../views/a/in_a.str', __dir__
send_file file
end

View File

@ -1,4 +1,4 @@
require File.expand_path('../integration_helper', __FILE__)
require File.expand_path('integration_helper', __dir__)
module IntegrationAsyncHelper
def it(message, &block)

View File

@ -1,5 +1,5 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('../integration_async_helper', __FILE__)
require File.expand_path('helper', __dir__)
require File.expand_path('integration_async_helper', __dir__)
# These tests are like integration_test, but they test asynchronous streaming.
class IntegrationAsyncTest < Minitest::Test

View File

@ -22,7 +22,7 @@ module IntegrationHelper
end
def app_file
File.expand_path('../integration/app.rb', __FILE__)
File.expand_path('integration/app.rb', __dir__)
end
def environment
@ -62,7 +62,7 @@ module IntegrationHelper
cmd << File.expand_path(file, dir).inspect
end
cmd << "-w" unless net_http_server?
cmd << "-I" << File.expand_path('../../lib', __FILE__).inspect
cmd << "-I" << File.expand_path('../lib', __dir__).inspect
cmd << app_file.inspect << '-s' << server << '-o' << '127.0.0.1' << '-p' << port
cmd << "-e" << environment.to_s << '2>&1'
cmd.join " "
@ -112,7 +112,7 @@ module IntegrationHelper
# Create a new container, set load paths and env
# SINGLETHREAD means create a new runtime
vm = org.jruby.embed.ScriptingContainer.new(org.jruby.embed.LocalContextScope::SINGLETHREAD)
vm.load_paths = [File.expand_path('../../lib', __FILE__)]
vm.load_paths = [File.expand_path('../lib', __dir__)]
vm.environment = ENV.merge('APP_ENV' => environment.to_s)
# This ensures processing of RUBYOPT which activates Bundler

View File

@ -1,5 +1,5 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('../integration_helper', __FILE__)
require File.expand_path('helper', __dir__)
require File.expand_path('integration_helper', __dir__)
# These tests start a real server and talk to it over TCP.
# Every test runs with every detected server.

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
begin
require 'liquid'

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
class FooError < RuntimeError
end

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
begin
require 'markaby'

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
MarkdownTest = proc do
def markdown_app(&block)

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
begin
require 'wikicloth'

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
class MiddlewareTest < Minitest::Test
setup do

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
begin
require 'nokogiri'

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
begin
require 'rabl'

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
require 'rack'
class RackTest < Minitest::Test

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
begin
require 'radius'

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
begin
require 'rdoc'

View File

@ -1,5 +1,5 @@
# Tests to check if all the README examples work.
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
class ReadmeTest < Minitest::Test
example do

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
require 'stringio'
class RequestTest < Minitest::Test

View File

@ -1,6 +1,6 @@
# encoding: utf-8
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
class ResponseTest < Minitest::Test
setup { @response = Sinatra::Response.new([], 200, { 'Content-Type' => 'text/html' }) }

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
class ThirdPartyError < RuntimeError
def http_status; 400 end

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
module RouteAddedTest
@routes, @procs = [], []

View File

@ -1,5 +1,5 @@
# I like coding: UTF-8
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
# Helper method for easy route pattern matching testing
def route_def(pattern)

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
begin
require 'sass'

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
begin
require 'sass'

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
require 'stringio'
module Rack::Handler

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
class SettingsTest < Minitest::Test
setup do

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
class SinatraTest < Minitest::Test
it 'creates a new Sinatra::Base subclass on new' do

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
begin
require 'slim'

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
class StaticTest < Minitest::Test
setup do

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
class StreamingTest < Minitest::Test
Stream = Sinatra::Helpers::Stream

View File

@ -1,5 +1,5 @@
# encoding: UTF-8
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
File.delete(__dir__ + '/views/layout.test') rescue nil
class TestTemplate < Tilt::Template

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
begin
require 'redcloth'

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
begin
require 'wlang'

View File

@ -1,4 +1,4 @@
require File.expand_path('../helper', __FILE__)
require File.expand_path('helper', __dir__)
begin
require 'yajl'