Skip to content

Commit ec60c83

Browse files
committed
use assert_warning
1 parent fbf92d1 commit ec60c83

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

test/unit/file_type.rb

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
require 'test/unit'
2+
require File.expand_path('../../lib/assert_warning', __FILE__)
3+
24
require 'coderay/helpers/file_type'
35

46
class FileTypeTests < Test::Unit::TestCase
@@ -9,31 +11,22 @@ def test_fetch
911
assert_raise FileType::UnknownFileType do
1012
FileType.fetch ''
1113
end
12-
14+
1315
assert_throws :not_found do
1416
FileType.fetch '.' do
1517
throw :not_found
1618
end
1719
end
18-
20+
1921
assert_equal :default, FileType.fetch('c', :default)
2022
end
2123

2224
def test_block_supersedes_default_warning
23-
stderr, fake_stderr = $stderr, Object.new
24-
begin
25-
$err = ''
26-
def fake_stderr.write x
27-
$err << x
28-
end
29-
$stderr = fake_stderr
25+
assert_warning 'Block supersedes default value argument; use either.' do
3026
FileType.fetch('c', :default) { }
31-
assert_equal "Block supersedes default value argument; use either.\n", $err
32-
ensure
33-
$stderr = stderr
3427
end
3528
end
36-
29+
3730
def test_ruby
3831
assert_equal :ruby, FileType[__FILE__]
3932
assert_equal :ruby, FileType['test.rb']
@@ -48,7 +41,7 @@ def test_ruby
4841
assert_not_equal :ruby, FileType['set.rb/set']
4942
assert_not_equal :ruby, FileType['~/projects/blabla/rb']
5043
end
51-
44+
5245
def test_c
5346
assert_equal :c, FileType['test.c']
5447
assert_equal :c, FileType['C:\\Program Files\\x\\y\\c\\test.h']
@@ -57,7 +50,7 @@ def test_c
5750
assert_not_equal :c, FileType['set.h/set']
5851
assert_not_equal :c, FileType['~/projects/blabla/c']
5952
end
60-
53+
6154
def test_cpp
6255
assert_equal :cpp, FileType['test.c++']
6356
assert_equal :cpp, FileType['test.cxx']
@@ -68,22 +61,22 @@ def test_cpp
6861
assert_not_equal :cpp, FileType['test.c']
6962
assert_not_equal :cpp, FileType['test.h']
7063
end
71-
64+
7265
def test_html
7366
assert_equal :page, FileType['test.htm']
7467
assert_equal :page, FileType['test.xhtml']
7568
assert_equal :page, FileType['test.html.xhtml']
7669
assert_equal :erb, FileType['_form.rhtml']
7770
assert_equal :erb, FileType['_form.html.erb']
7871
end
79-
72+
8073
def test_yaml
8174
assert_equal :yaml, FileType['test.yml']
8275
assert_equal :yaml, FileType['test.yaml']
8376
assert_equal :yaml, FileType['my.html.yaml']
8477
assert_not_equal :yaml, FileType['YAML']
8578
end
86-
79+
8780
def test_pathname
8881
require 'pathname'
8982
pn = Pathname.new 'test.rb'
@@ -92,7 +85,7 @@ def test_pathname
9285
assert_equal :ruby, FileType[dir + pn]
9386
assert_equal :cpp, FileType[dir + 'test.cpp']
9487
end
95-
88+
9689
def test_no_shebang
9790
dir = './test'
9891
if File.directory? dir
@@ -119,5 +112,5 @@ def test_shebang
119112
File.open(tmpfile, 'w') { |f| f.puts '#!/usr/bin/env ruby' }
120113
assert_equal :ruby, FileType[tmpfile, true]
121114
end
122-
115+
123116
end

test/unit/plugin.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'test/unit'
2+
require 'pathname'
23
require File.expand_path('../../lib/assert_warning', __FILE__)
34

45
$:.unshift File.expand_path('../../../lib', __FILE__)

0 commit comments

Comments
 (0)