Tweak test formatting; fix order-dependent failure

The order-dependent failure has been been commented in code.

After manually bisecting the test suite, I was able to determine that
the template cascade tests were leaving the `@@template_priority_path`
set to an overridden value in tests run afterward.
This commit is contained in:
benjamin wil
2021-12-31 16:27:58 -08:00
parent 675fff02ac
commit 7a019567ec
2 changed files with 30 additions and 14 deletions
+6 -2
View File
@@ -11,9 +11,13 @@ module Precious
end
def first_path_available(name)
priority = File.join(template_priority_path, "#{name}.#{template_extension}")
default = File.join(template_path, "#{name}.#{template_extension}")
File.exists?(priority) ? priority : default
priority =
if template_priority_path
File.join(template_priority_path, "#{name}.#{template_extension}")
end
priority && File.exists?(priority) ? priority : default
end
# Method should track lib/mustache/settings.rb from Mustache project.
+24 -12
View File
@@ -1,47 +1,59 @@
# ~*~ encoding: utf-8 ~*~
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
class TestTemplateCascade < Minitest::Unit::TestCase
context "Precious::Views::TemplateCascade" do
include Rack::Test::Methods
def setup
setup do
@path = cloned_testpath('examples/lotr.git')
Precious::App.set(:gollum_path, @path)
Precious::App.set(:wiki_options, {template_dir: testpath('examples/template_cascade')})
Precious::App.set(
:wiki_options,
{template_dir: testpath('examples/template_cascade')}
)
@wiki = Gollum::Wiki.new(@path)
end
def teardown
teardown do
FileUtils.rm_rf(@path)
Precious::App.set(:wiki_options, {template_dir: nil})
# The following line has been added to avoid order-dependent test failures.
# We saw issues where the class variable `@@template_priority_path` was not
# being reset between test cases.
Precious::Views::TemplateCascade.class_variable_set(
:@@template_priority_path,
nil
)
end
def app
Precious::App
Precious::App.new
end
def test_overridden_page_template_is_used
test "overridden_page_template_is_used" do
get '/Home'
assert last_response.body.include?('PAGE_OVERRIDE')
end
def test_overridden_navbar_partial_is_used
test "test_overridden_navbar_partial_is_used" do
get '/Home'
assert last_response.body.include?('NAVBAR_OVERRIDE')
end
def test_overridden_templates_are_ignore_without_template_dir_set
test "test_overridden_templates_are_ignore_without_template_dir_set" do
Precious::App.set(:wiki_options, {template_dir: nil})
get '/Home'
assert_equal '/Home', last_request.fullpath
assert last_response.ok?
refute_match /PAGE_OVERRIDE/, last_response.body
refute_match /NAVBAR_OVERRIDE/, last_response.body
end
def teardown
FileUtils.rm_rf(@path)
end
end