Skip to content

Commit

Permalink
Add a test file for zeitwerk functionality
Browse files Browse the repository at this point in the history
Unfortunately this behaviour is only reproducible in classic sinatra app
and this is the only way I can think of making it work. The problem is
that this breaks another scenario in settings_test where we're expecting
that Sinatra::Application.app_file is nil.
  • Loading branch information
DawidJanczak committed Nov 13, 2022
1 parent 52e935a commit 9abff65
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ gem 'redcarpet', platforms: [:ruby]
gem 'simplecov', require: false
gem 'slim', '~> 4'
gem 'yajl-ruby', platforms: [:ruby]
gem 'zeitwerk'

gem 'json', platforms: %i[jruby mri]

Expand Down
14 changes: 14 additions & 0 deletions test/zeitwerk_app_file_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require File.expand_path('helper', __dir__)
# This needs to come first so that sinatra require goes through zeitwerk loader
require 'zeitwerk'
require 'sinatra'

# We have to use a global variable here in order for the spec to be able to access it.
# A constant would work too, but undefining that is a bit more involved.
$zeitwerk_test_app_file = settings.app_file

class ZeitwerkAppFileTest < Minitest::Test
it 'sets app_file to the first caller ignoring Zeitwerk' do
assert_equal __FILE__, $zeitwerk_test_app_file
end
end

0 comments on commit 9abff65

Please sign in to comment.