Use Minitest::Test
`Test::Unit` is deprecated, and we can switch to `Minitest::Test` with almost no side effects. This commit does all of the work required to make Minitest tests run with Gollum's existing test helpers.
This commit is contained in:
+30
-12
@@ -1,11 +1,11 @@
|
||||
require 'rubygems'
|
||||
require 'rack/test'
|
||||
require 'test/unit'
|
||||
require 'shoulda'
|
||||
require 'mocha/setup'
|
||||
require 'fileutils'
|
||||
require 'minitest/autorun'
|
||||
require 'minitest/reporters'
|
||||
require 'minitest/spec'
|
||||
require 'mocha/setup'
|
||||
require 'fileutils'
|
||||
require 'tmpdir'
|
||||
|
||||
# Silence locale validation warning
|
||||
@@ -62,14 +62,29 @@ def normal(text)
|
||||
text
|
||||
end
|
||||
|
||||
# test/spec/mini 3
|
||||
# http://gist.github.com/25455
|
||||
# chris@ozmm.org
|
||||
# file:lib/test/spec/mini.rb
|
||||
# The following configuration originates from this gist:
|
||||
|
||||
# http://gist.github.com/25455
|
||||
#
|
||||
# But it has been modified since it was first committed. It allows you to
|
||||
# write tests with an RSpec-like DSL:
|
||||
#
|
||||
# context "my test context" do
|
||||
# setup do
|
||||
# # My test setup
|
||||
# end
|
||||
#
|
||||
# teardown do
|
||||
# # My test teardown
|
||||
# end
|
||||
#
|
||||
# test "some functionality" do
|
||||
# assert true
|
||||
# end
|
||||
# end
|
||||
def context(*args, &block)
|
||||
return super unless (name = args.first) && block
|
||||
require 'test/unit'
|
||||
klass = Class.new(defined?(ActiveSupport::TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase) do
|
||||
klass = Class.new(Minitest::Test) do
|
||||
def self.test(name, &block)
|
||||
define_method("test_#{name.gsub(/\W/, '_')}", &block) if block
|
||||
end
|
||||
@@ -85,10 +100,13 @@ def context(*args, &block)
|
||||
define_method(:teardown, &block)
|
||||
end
|
||||
end
|
||||
|
||||
(
|
||||
class << klass;
|
||||
self
|
||||
end).send(:define_method, :name) { name.gsub(/\W/, '_') }
|
||||
class << klass;
|
||||
self
|
||||
end
|
||||
).send(:define_method, :name) { name.gsub(/\W/, '_') }
|
||||
|
||||
$contexts << klass
|
||||
klass.class_eval &block
|
||||
end
|
||||
|
||||
+12
-12
@@ -51,11 +51,11 @@ context "Precious::Views::Editing" do
|
||||
|
||||
get '/gollum/history/A'
|
||||
|
||||
assert_no_match /Edit/, last_response.body, "'Edit' link is not blocked in history template"
|
||||
refute_match /Edit/, last_response.body, "'Edit' link is not blocked in history template"
|
||||
|
||||
get '/gollum/compare/A/fc66539528eb96f21b2bbdbf557788fe8a1196ac..b26b791cb7917c4f37dd9cb4d1e0efb24ac4d26f'
|
||||
|
||||
assert_no_match /Edit Page/, last_response.body, "'Edit Page' link is not blocked in compare template"
|
||||
refute_match /Edit Page/, last_response.body, "'Edit Page' link is not blocked in compare template"
|
||||
assert_match /Revert Changes/, last_response.body, "'Revert Changes' link is blocked in compare template"
|
||||
end
|
||||
|
||||
@@ -63,27 +63,27 @@ context "Precious::Views::Editing" do
|
||||
Precious::App.set(:wiki_options, { allow_editing: false })
|
||||
get '/A'
|
||||
|
||||
assert_no_match /Delete this Page/, last_response.body, "'Delete this Page' link not blocked in page template"
|
||||
assert_no_match /New/, last_response.body, "'New' button not blocked in page template"
|
||||
assert_no_match /Upload\b/, last_response.body, "'Upload' link not blocked in page template"
|
||||
assert_no_match /Rename/, last_response.body, "'Rename' link not blocked in page template"
|
||||
assert_no_match /Edit/, last_response.body, "'Edit' link not blocked in page template"
|
||||
refute_match /Delete this Page/, last_response.body, "'Delete this Page' link not blocked in page template"
|
||||
refute_match /New/, last_response.body, "'New' button not blocked in page template"
|
||||
refute_match /Upload\b/, last_response.body, "'Upload' link not blocked in page template"
|
||||
refute_match /Rename/, last_response.body, "'Rename' link not blocked in page template"
|
||||
refute_match /Edit/, last_response.body, "'Edit' link not blocked in page template"
|
||||
|
||||
get '/gollum/overview'
|
||||
|
||||
assert_no_match /New/, last_response.body, "'New' link not blocked in pages template"
|
||||
refute_match /New/, last_response.body, "'New' link not blocked in pages template"
|
||||
|
||||
get '/gollum/history/A'
|
||||
|
||||
assert_no_match /Edit/, last_response.body, "'Edit' link not blocked in history template"
|
||||
refute_match /Edit/, last_response.body, "'Edit' link not blocked in history template"
|
||||
|
||||
get '/gollum/compare/A/fc66539528eb96f21b2bbdbf557788fe8a1196ac..b26b791cb7917c4f37dd9cb4d1e0efb24ac4d26f'
|
||||
|
||||
assert_no_match /Edit Page/, last_response.body, "'Edit Page' link not blocked in compare template"
|
||||
assert_no_match /Revert Changes/, last_response.body, "'Revert Changes' link not blocked in compare template"
|
||||
refute_match /Edit Page/, last_response.body, "'Edit Page' link not blocked in compare template"
|
||||
refute_match /Revert Changes/, last_response.body, "'Revert Changes' link not blocked in compare template"
|
||||
end
|
||||
|
||||
def app
|
||||
Precious::App
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
+49
-49
@@ -14,7 +14,7 @@ context "Frontend" do
|
||||
teardown do
|
||||
FileUtils.rm_rf(@path)
|
||||
end
|
||||
|
||||
|
||||
test "utf-8 kcode" do
|
||||
assert_equal 'μ†ℱ'.scan(/./), ["μ", "†", "ℱ"]
|
||||
end
|
||||
@@ -104,21 +104,21 @@ EOF
|
||||
page_2 = @wiki.page(page_1.name)
|
||||
assert_equal 'abc', page_2.raw_data
|
||||
assert_equal 'def', page_2.version.message
|
||||
assert_not_equal page_1.version.sha, page_2.version.sha
|
||||
refute_equal page_1.version.sha, page_2.version.sha
|
||||
end
|
||||
|
||||
|
||||
test "edit page fails when page is outdated (edit collision)" do
|
||||
page = @wiki.page('A')
|
||||
old_sha = page.sha
|
||||
post "/gollum/edit/A", :content => 'abc', :page => 'A',
|
||||
:format => page.format, :message => 'def', :etag => old_sha
|
||||
assert last_response.ok?
|
||||
|
||||
|
||||
@wiki.clear_cache
|
||||
page = @wiki.page('A')
|
||||
new_sha = page.sha
|
||||
assert_not_equal old_sha, new_sha
|
||||
|
||||
refute_equal old_sha, new_sha
|
||||
|
||||
post "/gollum/edit/A", :content => 'def', :page => 'A',
|
||||
:format => page.format, :message => 'def', :etag => old_sha
|
||||
assert_equal last_response.status, 412
|
||||
@@ -134,7 +134,7 @@ EOF
|
||||
page_2 = @wiki.page(page_1.name)
|
||||
assert_equal 'abc', page_2.raw_data
|
||||
assert_equal '[no message]', page_2.version.message
|
||||
assert_not_equal page_1.version.sha, page_2.version.sha
|
||||
refute_equal page_1.version.sha, page_2.version.sha
|
||||
end
|
||||
|
||||
test "edit page with slash" do
|
||||
@@ -165,12 +165,12 @@ EOF
|
||||
assert_equal 'header', header_2.raw_data
|
||||
assert_equal 'footer', foot_2.raw_data
|
||||
assert_equal 'def', foot_2.version.message
|
||||
assert_not_equal foot_1.version.sha, foot_2.version.sha
|
||||
assert_not_equal header_1.version.sha, header_2.version.sha
|
||||
refute_equal foot_1.version.sha, foot_2.version.sha
|
||||
refute_equal header_1.version.sha, header_2.version.sha
|
||||
|
||||
assert_equal 'sidebar', side_2.raw_data
|
||||
assert_equal 'def', side_2.version.message
|
||||
assert_not_equal side_1.version.sha, side_2.version.sha
|
||||
refute_equal side_1.version.sha, side_2.version.sha
|
||||
assert_equal commits, @wiki.repo.commits('master').size
|
||||
end
|
||||
|
||||
@@ -187,7 +187,7 @@ EOF
|
||||
page_2 = @wiki.page('C')
|
||||
assert_equal "INITIAL\n\nSPAM2\n", page_2.raw_data
|
||||
assert_equal 'def', page_2.last_version.message
|
||||
assert_not_equal page_1.version.sha, page_2.version.sha
|
||||
refute_equal page_1.version.sha, page_2.version.sha
|
||||
end
|
||||
|
||||
test "rename preserves format" do
|
||||
@@ -222,7 +222,7 @@ EOF
|
||||
|
||||
test "renames page in subdirectory" do
|
||||
page_1 = @wiki.page("G/H")
|
||||
assert_not_equal page_1, nil
|
||||
refute_equal page_1, nil
|
||||
post "/gollum/rename/G/H", :rename => "/I/C", :message => 'def'
|
||||
|
||||
follow_redirect!
|
||||
@@ -234,12 +234,12 @@ EOF
|
||||
page_2 = @wiki.page('I/C')
|
||||
assert_equal "INITIAL\n\nSPAM2\n", page_2.raw_data
|
||||
assert_equal 'def', page_2.last_version.message
|
||||
assert_not_equal page_1.version.sha, page_2.version.sha
|
||||
refute_equal page_1.version.sha, page_2.version.sha
|
||||
end
|
||||
|
||||
test "renames page relative in subdirectory" do
|
||||
page_1 = @wiki.page("G/H")
|
||||
assert_not_equal page_1, nil
|
||||
refute_equal page_1, nil
|
||||
post "/gollum/rename/G/H", :rename => "K/C", :message => 'def'
|
||||
|
||||
follow_redirect!
|
||||
@@ -251,7 +251,7 @@ EOF
|
||||
page_2 = @wiki.page('G/K/C')
|
||||
assert_equal "INITIAL\n\nSPAM2\n", page_2.raw_data
|
||||
assert_equal 'def', page_2.last_version.message
|
||||
assert_not_equal page_1.version.sha, page_2.version.sha
|
||||
refute_equal page_1.version.sha, page_2.version.sha
|
||||
end
|
||||
|
||||
test "creates page" do
|
||||
@@ -320,7 +320,7 @@ EOF
|
||||
name = "#{dir}/bar"
|
||||
get "/gollum/create/#{name}"
|
||||
assert_match(/\/#{dir}/, last_response.body)
|
||||
assert_no_match(/[^\/]#{dir}/, last_response.body)
|
||||
refute_match(/[^\/]#{dir}/, last_response.body)
|
||||
end
|
||||
|
||||
test "create with template succeed if template exists" do
|
||||
@@ -351,7 +351,7 @@ EOF
|
||||
post '/gollum/edit/', :content => 'edit_msg',
|
||||
:page => page, :path => path, :message => ''
|
||||
page_e = @wiki.page(::File.join(path,page))
|
||||
assert_equal nil, page_e
|
||||
assert_nil page_e
|
||||
end
|
||||
|
||||
test "edit allows changing format" do
|
||||
@@ -407,23 +407,23 @@ EOF
|
||||
|
||||
@wiki.clear_cache
|
||||
page = @wiki.page(name)
|
||||
assert_not_equal 'abc', page.raw_data
|
||||
refute_equal 'abc', page.raw_data
|
||||
end
|
||||
|
||||
|
||||
test "uploading is not allowed unless explicitly enabled" do
|
||||
temp_upload_file = Tempfile.new(['upload', '.file']) << 'abc'
|
||||
temp_upload_file.close
|
||||
post "/gollum/upload_file", :file => Rack::Test::UploadedFile.new(::File.open(temp_upload_file))
|
||||
assert_equal 405, last_response.status
|
||||
end
|
||||
|
||||
|
||||
test "upload a file with mode dir" do
|
||||
temp_upload_file = Tempfile.new(['upload', '.file']) << 'abc'
|
||||
temp_upload_file.close
|
||||
Precious::App.set(:wiki_options, {allow_uploads: true})
|
||||
|
||||
|
||||
post "/gollum/upload_file", :file => Rack::Test::UploadedFile.new(::File.open(temp_upload_file))
|
||||
|
||||
|
||||
assert_equal 302, last_response.status # redirect is expected
|
||||
@wiki.clear_cache
|
||||
file = @wiki.file("uploads/#{::File.basename(temp_upload_file.path)}")
|
||||
@@ -436,7 +436,7 @@ EOF
|
||||
temp_upload_file.close
|
||||
Precious::App.set(:wiki_options, {allow_uploads: true, per_page_uploads: true})
|
||||
post "/gollum/upload_file", {:file => Rack::Test::UploadedFile.new(::File.open(temp_upload_file))}, {'HTTP_REFERER' => 'http://localhost:4567/Home.md', 'HTTP_HOST' => 'localhost:4567'}
|
||||
|
||||
|
||||
assert_equal 302, last_response.status # redirect is expected
|
||||
@wiki.clear_cache
|
||||
# Find the file in a page-specific subdir (here: Home), based on referer
|
||||
@@ -444,13 +444,13 @@ EOF
|
||||
assert_equal 'abc', file.raw_data
|
||||
Precious::App.set(:wiki_options, {allow_uploads: false, per_page_uploads: false})
|
||||
end
|
||||
|
||||
|
||||
test "upload a file with https referer" do
|
||||
temp_upload_file = Tempfile.new(['https_upload', '.file']) << 'abc'
|
||||
temp_upload_file.close
|
||||
Precious::App.set(:wiki_options, {allow_uploads: true, per_page_uploads: true})
|
||||
post "/gollum/upload_file", {:file => Rack::Test::UploadedFile.new(::File.open(temp_upload_file))}, {'HTTP_REFERER' => 'https://localhost:4567/Home.md', 'HTTP_HOST' => 'localhost:4567'}
|
||||
|
||||
|
||||
assert_equal 302, last_response.status # redirect is expected
|
||||
@wiki.clear_cache
|
||||
# Find the file in a page-specific subdir (here: Home), based on referer
|
||||
@@ -458,8 +458,8 @@ EOF
|
||||
assert_equal 'abc', file.raw_data
|
||||
Precious::App.set(:wiki_options, {allow_uploads: false, per_page_uploads: false})
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
test "guard against uploading an existing file" do
|
||||
temp_upload_file = Tempfile.new(['upload', '.file']) << 'abc'
|
||||
temp_upload_file.close
|
||||
@@ -471,7 +471,7 @@ EOF
|
||||
assert_equal 409, last_response.status
|
||||
Precious::App.set(:wiki_options, {allow_uploads: false})
|
||||
end
|
||||
|
||||
|
||||
test "delete a page" do
|
||||
name = "deleteme"
|
||||
post "/gollum/create", :content => 'abc', :page => name,
|
||||
@@ -483,7 +483,7 @@ EOF
|
||||
|
||||
@wiki.clear_cache
|
||||
page = @wiki.page(name)
|
||||
assert_equal nil, page
|
||||
assert_nil page
|
||||
end
|
||||
|
||||
test "previews content" do
|
||||
@@ -507,7 +507,7 @@ EOF
|
||||
|
||||
@wiki.clear_cache
|
||||
page2 = @wiki.page('B')
|
||||
assert_not_equal page1.version.sha, page2.version.sha
|
||||
refute_equal page1.version.sha, page2.version.sha
|
||||
assert_equal "INITIAL", page2.raw_data.strip
|
||||
assert_equal "Revert commit 7c45b5f", page2.version.message
|
||||
end
|
||||
@@ -521,7 +521,7 @@ EOF
|
||||
|
||||
@wiki.clear_cache
|
||||
page2 = @wiki.page('A')
|
||||
assert_not_equal page1.version.sha, page2.version.sha
|
||||
refute_equal page1.version.sha, page2.version.sha
|
||||
assert_equal "INITIAL", page2.raw_data.strip
|
||||
end
|
||||
|
||||
@@ -535,7 +535,7 @@ EOF
|
||||
page2 = @wiki.page('A')
|
||||
assert_equal page1.version.sha, page2.version.sha
|
||||
end
|
||||
|
||||
|
||||
=begin
|
||||
# redirects are now handled by class MapGollum in bin/gollum
|
||||
# they should be set in config.ru
|
||||
@@ -583,7 +583,7 @@ EOF
|
||||
{ :name => 'user1', :email => 'user1' });
|
||||
|
||||
get page
|
||||
assert_no_match /custom.js/, last_response.body
|
||||
refute_match /custom.js/, last_response.body
|
||||
end
|
||||
|
||||
test "add custom.js if setting" do
|
||||
@@ -601,7 +601,7 @@ EOF
|
||||
|
||||
test "don't allow changing custom js or css" do
|
||||
Precious::App.set(:wiki_options, { :js => true, :css => true })
|
||||
|
||||
|
||||
['create', 'edit'].each do |route|
|
||||
['.css', '.js'].each do |ext|
|
||||
get "/gollum/#{route}/custom#{ext}"
|
||||
@@ -634,7 +634,7 @@ EOF
|
||||
:page => 'Multibyte', :format => :markdown, :message => 'mesg'
|
||||
|
||||
page = @wiki.page('Multibyte')
|
||||
|
||||
|
||||
post "/gollum/edit/Multibyte",
|
||||
:content => 'りんご', :header => 'みかん', :footer => 'バナナ', :sidebar => 'スイカ',
|
||||
:page => 'Multibyte', :format => :markdown, :message => 'mesg', :etag => page.sha
|
||||
@@ -652,7 +652,7 @@ EOF
|
||||
get "A"
|
||||
|
||||
assert last_response.ok?
|
||||
assert_no_match /meta name="robots" content="noindex, nofollow"/, last_response.body
|
||||
refute_match /meta name="robots" content="noindex, nofollow"/, last_response.body
|
||||
|
||||
get "A/fc66539528eb96f21b2bbdbf557788fe8a1196ac"
|
||||
|
||||
@@ -831,10 +831,10 @@ context "Frontend with lotr" do
|
||||
test "show revision of specific file" do
|
||||
old_sha = "df26e61e707116f81ebc6b935ec6d1676b7e96c4"
|
||||
update_sha = "f803c64d11407b23797325e3843f3f378b78f611"
|
||||
|
||||
|
||||
get "Data.csv/#{old_sha}"
|
||||
assert last_response.ok?
|
||||
assert_no_match /Samwise,Gamgee/, last_response.body
|
||||
refute_match /Samwise,Gamgee/, last_response.body
|
||||
|
||||
get "Data.csv/#{update_sha}"
|
||||
assert last_response.ok?
|
||||
@@ -879,7 +879,7 @@ context "Frontend with page-file-dir" do
|
||||
name = "#{dir}/baz"
|
||||
get "/gollum/create/#{name}"
|
||||
assert_match(/\/#{dir}/, last_response.body)
|
||||
assert_no_match(/[^\/]#{dir}/, last_response.body)
|
||||
refute_match(/[^\/]#{dir}/, last_response.body)
|
||||
end
|
||||
|
||||
test "use custom.css from page-file-dir path if page-file-dir is set" do
|
||||
@@ -920,7 +920,7 @@ end
|
||||
|
||||
context "Frontend with empty repo" do
|
||||
include Rack::Test::Methods
|
||||
|
||||
|
||||
setup do
|
||||
@path = cloned_testpath("examples/empty.git")
|
||||
@wiki = Gollum::Wiki.new(@path)
|
||||
@@ -931,11 +931,11 @@ context "Frontend with empty repo" do
|
||||
teardown do
|
||||
FileUtils.rm_rf(@path)
|
||||
end
|
||||
|
||||
|
||||
def app
|
||||
Precious::App
|
||||
end
|
||||
|
||||
|
||||
test 'previews content on the first page of an empty wiki' do
|
||||
post '/gollum/preview', :content => 'abc', :format => 'markdown'
|
||||
assert last_response.ok?
|
||||
@@ -947,12 +947,12 @@ context "Frontend with empty repo" do
|
||||
assert_equal '/gollum/create/Home', last_request.fullpath
|
||||
assert last_response.ok?
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
context 'Frontend with base path' do
|
||||
include Rack::Test::Methods
|
||||
|
||||
|
||||
setup do
|
||||
@path = cloned_testpath("examples/lotr.git")
|
||||
@wiki = Gollum::Wiki.new(@path)
|
||||
@@ -964,24 +964,24 @@ context 'Frontend with base path' do
|
||||
teardown do
|
||||
FileUtils.rm_rf(@path)
|
||||
end
|
||||
|
||||
|
||||
test 'page with base path' do
|
||||
get '/wiki/Home'
|
||||
assert last_response.ok?
|
||||
end
|
||||
|
||||
|
||||
test 'base path mathjax assets' do
|
||||
get '/wiki/Home'
|
||||
assert last_response.ok?
|
||||
assert last_response.body.include?('<script defer src="/wiki/gollum/assets/mathjax/MathJax.js?config=')
|
||||
end
|
||||
|
||||
|
||||
test 'compare view' do
|
||||
get '/wiki/gollum/compare/Bilbo-Baggins.md?versions[]=f25eccd98e9b667f9e22946f3e2f945378b8a72d&versions[]=5bc1aaec6149e854078f1d0f8b71933bbc6c2e43'
|
||||
follow_redirect!
|
||||
assert last_response.ok?
|
||||
assert_equal '/wiki/gollum/compare/Bilbo-Baggins.md/5bc1aaec6149e854078f1d0f8b71933bbc6c2e43...f25eccd98e9b667f9e22946f3e2f945378b8a72d', last_request.fullpath
|
||||
|
||||
|
||||
get '/wiki/gollum/compare/Bilbo-Baggins.md?versions[]=f25eccd98e9b667f9e22946f3e2f945378b8a72d'
|
||||
follow_redirect!
|
||||
assert last_response.ok?
|
||||
@@ -992,7 +992,7 @@ context 'Frontend with base path' do
|
||||
assert last_response.ok?
|
||||
assert_equal '/wiki/gollum/history/Bilbo-Baggins.md', last_request.fullpath
|
||||
end
|
||||
|
||||
|
||||
def app
|
||||
Precious::MapGollum.new(@base_path)
|
||||
end
|
||||
|
||||
@@ -35,7 +35,7 @@ context "Precious::Views::Page" do
|
||||
@view.instance_variable_set :@content, page.formatted_data
|
||||
@view.instance_variable_set :@h1_title, false
|
||||
|
||||
assert_include @view.breadcrumb, "数学 📘"
|
||||
assert_includes @view.breadcrumb, "数学 📘"
|
||||
end
|
||||
|
||||
test 'page <title> is the page header from content, if present' do
|
||||
|
||||
@@ -37,7 +37,11 @@ class TestTemplateCascade < Minitest::Unit::TestCase
|
||||
get '/Home'
|
||||
assert_equal '/Home', last_request.fullpath
|
||||
assert last_response.ok?
|
||||
assert_no_match /PAGE_OVERRIDE/, last_response.body
|
||||
assert_no_match /NAVBAR_OVERRIDE/, last_response.body
|
||||
refute_match /PAGE_OVERRIDE/, last_response.body
|
||||
refute_match /NAVBAR_OVERRIDE/, last_response.body
|
||||
end
|
||||
|
||||
def teardown
|
||||
FileUtils.rm_rf(@path)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user