diff --git a/.rspec b/.rspec deleted file mode 100644 index 04f5700..0000000 --- a/.rspec +++ /dev/null @@ -1,3 +0,0 @@ ---color ---format=documentation ---fail-fast \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 8101f26..55de974 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,18 +7,10 @@ GEM remote: http://rubygems.org/ specs: chardet (0.9.0) - diff-lcs (1.1.2) + minitest (4.6.2) rake (0.9.2) rake-compiler (0.7.9) rake - rspec (2.6.0) - rspec-core (~> 2.6.0) - rspec-expectations (~> 2.6.0) - rspec-mocks (~> 2.6.0) - rspec-core (2.6.4) - rspec-expectations (2.6.0) - diff-lcs (~> 1.1.2) - rspec-mocks (2.6.0) PLATFORMS ruby @@ -26,5 +18,5 @@ PLATFORMS DEPENDENCIES chardet charlock_holmes! + minitest rake-compiler (>= 0.7.5) - rspec (>= 2.0.0) diff --git a/Rakefile b/Rakefile index 0d0cfa8..e943d79 100644 --- a/Rakefile +++ b/Rakefile @@ -1,23 +1,10 @@ -# rspec -begin - require 'rspec' - require 'rspec/core/rake_task' +require 'rake/testtask' - desc "Run all examples with RCov" - RSpec::Core::RakeTask.new 'spec:rcov' do |t| - t.rcov = true - end - RSpec::Core::RakeTask.new 'spec' do |t| - t.verbose = true - end - - task :default => :spec -rescue LoadError - puts "rspec, or one of its dependencies, is not available. Install it with: sudo gem install rspec" +Rake::TestTask.new do |t| + t.pattern = "test/**/*_test.rb" end -# rake-compiler -require 'rake' unless defined? Rake +task :default => :test gem 'rake-compiler', '>= 0.7.5' require "rake/extensiontask" @@ -26,4 +13,4 @@ Rake::ExtensionTask.new 'charlock_holmes' do |ext| ext.lib_dir = File.join 'lib', 'charlock_holmes' end -Rake::Task[:spec].prerequisites << :compile \ No newline at end of file +Rake::Task[:test].prerequisites << :compile \ No newline at end of file diff --git a/charlock_holmes.gemspec b/charlock_holmes.gemspec index 1a3e4c4..5d93c66 100644 --- a/charlock_holmes.gemspec +++ b/charlock_holmes.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| # tests s.add_development_dependency 'rake-compiler', ">= 0.7.5" - s.add_development_dependency 'rspec', ">= 2.0.0" + s.add_development_dependency 'minitest' # benchmarks s.add_development_dependency 'chardet' end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb deleted file mode 100644 index 39e470b..0000000 --- a/spec/spec_helper.rb +++ /dev/null @@ -1,9 +0,0 @@ -$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) - -require 'charlock_holmes' -require 'rspec' - -RSpec.configure do |config| - config.expect_with :stdlib - config.alias_example_to :test -end \ No newline at end of file diff --git a/spec/converter_spec.rb b/test/converter_test.rb similarity index 75% rename from spec/converter_spec.rb rename to test/converter_test.rb index cf48a6e..5a9c9fe 100644 --- a/spec/converter_spec.rb +++ b/test/converter_test.rb @@ -1,9 +1,7 @@ -# encoding: utf-8 +require File.expand_path("../helper", __FILE__) -require 'spec_helper' - -describe CharlockHolmes::Converter do - test 'is able to convert regular ascii content from ISO-8859-1 to UTF-16, and back again' do +class ConverterTest < MiniTest::Unit::TestCase + def test_convert_ascii_from_iso859_1_to_utf16_and_back input = 'test' output = CharlockHolmes::Converter.convert input, 'ISO-8859-1', 'UTF-16' @@ -15,7 +13,7 @@ assert input == output end - test 'is able to convert UTF-8 content from UTF-8 to UTF-16, and back again' do + def test_convert_utf8_to_utf16_and_back input = 'λ, λ, λ' output = CharlockHolmes::Converter.convert input, 'UTF-8', 'UTF-16' @@ -27,7 +25,7 @@ assert input == output end - test 'all params must be strings' do + def test_params_must_be_strings assert_raises TypeError do CharlockHolmes::Converter.convert nil, 'UTF-8', 'UTF-16' end @@ -40,8 +38,10 @@ CharlockHolmes::Converter.convert 'lol', 'UTF-8', nil end - assert_nothing_raised do + begin CharlockHolmes::Converter.convert 'lol', 'UTF-8', 'UTF-16' + rescue Exception => e + assert_nil e, "#{e.class.name} raised, expected nothing" end end end \ No newline at end of file diff --git a/spec/encoding_detector_spec.rb b/test/encoding_detector_test.rb similarity index 62% rename from spec/encoding_detector_spec.rb rename to test/encoding_detector_test.rb index cf919ed..6d79526 100644 --- a/spec/encoding_detector_spec.rb +++ b/test/encoding_detector_test.rb @@ -1,25 +1,23 @@ -# encoding: utf-8 +require File.expand_path("../helper", __FILE__) -require 'spec_helper' - -describe CharlockHolmes::EncodingDetector do - before :all do +class EncodingDetectorTest < MiniTest::Unit::TestCase + def setup @detector = CharlockHolmes::EncodingDetector.new end - test 'has a class-level detect method' do + def test_has_class_level_detect_method CharlockHolmes::EncodingDetector.respond_to? :detect detected = CharlockHolmes::EncodingDetector.detect 'test' assert_equal 'ISO-8859-1', detected[:encoding] end - test 'has a class-level detect method that accepts an encoding hint' do + def test_class_level_detect_accepts_encoding_hint CharlockHolmes::EncodingDetector.respond_to? :detect detected = CharlockHolmes::EncodingDetector.detect 'test', 'UTF-8' assert_equal 'ISO-8859-1', detected[:encoding] end - test 'has a class-level detect_all method' do + def test_has_class_level_detect_all_method CharlockHolmes::EncodingDetector.respond_to? :detect_all detected_list = CharlockHolmes::EncodingDetector.detect_all 'test' assert detected_list.is_a? Array @@ -28,7 +26,7 @@ assert_equal ['ISO-8859-1', 'ISO-8859-2', 'UTF-8'], encoding_list end - test 'has a class-level detect_all method that accepts an encoding hint' do + def test_class_level_detect_all_method_accepts_encoding_hint CharlockHolmes::EncodingDetector.respond_to? :detect_all detected_list = CharlockHolmes::EncodingDetector.detect_all 'test', 'UTF-8' assert detected_list.is_a? Array @@ -37,19 +35,19 @@ assert_equal ['ISO-8859-1', 'ISO-8859-2', 'UTF-8'], encoding_list end - test 'has a detect method' do + def test_has_detect_method @detector.respond_to? :detect detected = @detector.detect 'test' assert_equal 'ISO-8859-1', detected[:encoding] end - test 'has a detect method that accepts an encoding hint' do + def test_detect_accepts_encoding_hint @detector.respond_to? :detect detected = @detector.detect 'test', 'UTF-8' assert_equal 'ISO-8859-1', detected[:encoding] end - test 'has a detect_all method' do + def test_has_detect_all_method @detector.respond_to? :detect_all detected_list = @detector.detect_all 'test' assert detected_list.is_a? Array @@ -58,7 +56,7 @@ assert_equal ['ISO-8859-1', 'ISO-8859-2', 'UTF-8'], encoding_list end - test 'has a detect_all method that accepts an encoding hint' do + def test_detect_all_accepts_encoding_hint @detector.respond_to? :detect_all detected_list = @detector.detect_all 'test', 'UTF-8' assert detected_list.is_a? Array @@ -67,7 +65,7 @@ assert_equal ['ISO-8859-1', 'ISO-8859-2', 'UTF-8'], encoding_list end - test 'has a strip_tags flag' do + def test_strip_tags_flag detector = CharlockHolmes::EncodingDetector.new detector.strip_tags = true assert detector.strip_tags @@ -82,7 +80,7 @@ assert_equal 'UTF-8', detection[:encoding] end - test 'has a list of supported encodings' do + def test_has_list_of_supported_encodings CharlockHolmes::EncodingDetector.respond_to? :supported_encodings supported_encodings = CharlockHolmes::EncodingDetector.supported_encodings @@ -90,32 +88,30 @@ assert supported_encodings.include? 'UTF-8' end - context 'encoding detection' do - MAPPING = [ - ['repl2.cljs', 'ISO-8859-1', :text], - ['core.rkt', 'UTF-8', :text], - ['cl-messagepack.lisp', 'ISO-8859-1', :text], - ['TwigExtensionsDate.es.yml', 'UTF-8', :text], - ['AnsiGraph.psm1', 'UTF-16LE', :text], - ['laholator.py', 'UTF-8', :text], - ['hello_world', nil, :binary] - ] - + MAPPING = [ + ['repl2.cljs', 'ISO-8859-1', :text], + ['core.rkt', 'UTF-8', :text], + ['cl-messagepack.lisp', 'ISO-8859-1', :text], + ['TwigExtensionsDate.es.yml', 'UTF-8', :text], + ['AnsiGraph.psm1', 'UTF-16LE', :text], + ['laholator.py', 'UTF-8', :text], + ['hello_world', nil, :binary] + ] + + def test_detection_works_as_expected MAPPING.each do |mapping| file, encoding, type = mapping - test "#{file} should be detected as #{encoding || 'binary'}" do - path = File.expand_path "../fixtures/#{file}", __FILE__ - content = File.read path - guessed = @detector.detect content + path = File.expand_path "../fixtures/#{file}", __FILE__ + content = File.read path + guessed = @detector.detect content - assert_equal encoding, guessed[:encoding] - assert_equal type, guessed[:type] + assert_equal encoding, guessed[:encoding] + assert_equal type, guessed[:type] - if content.respond_to?(:force_encoding) && guessed[:type] == :text - content.force_encoding guessed[:encoding] - assert content.valid_encoding? - end + if content.respond_to?(:force_encoding) && guessed[:type] == :text + content.force_encoding guessed[:encoding] + assert content.valid_encoding? end end end diff --git a/spec/fixtures/AnsiGraph.psm1 b/test/fixtures/AnsiGraph.psm1 similarity index 100% rename from spec/fixtures/AnsiGraph.psm1 rename to test/fixtures/AnsiGraph.psm1 diff --git a/spec/fixtures/TwigExtensionsDate.es.yml b/test/fixtures/TwigExtensionsDate.es.yml similarity index 100% rename from spec/fixtures/TwigExtensionsDate.es.yml rename to test/fixtures/TwigExtensionsDate.es.yml diff --git a/spec/fixtures/cl-messagepack.lisp b/test/fixtures/cl-messagepack.lisp similarity index 100% rename from spec/fixtures/cl-messagepack.lisp rename to test/fixtures/cl-messagepack.lisp diff --git a/spec/fixtures/core.rkt b/test/fixtures/core.rkt similarity index 100% rename from spec/fixtures/core.rkt rename to test/fixtures/core.rkt diff --git a/spec/fixtures/hello_world b/test/fixtures/hello_world similarity index 100% rename from spec/fixtures/hello_world rename to test/fixtures/hello_world diff --git a/spec/fixtures/laholator.py b/test/fixtures/laholator.py similarity index 100% rename from spec/fixtures/laholator.py rename to test/fixtures/laholator.py diff --git a/spec/fixtures/repl2.cljs b/test/fixtures/repl2.cljs similarity index 100% rename from spec/fixtures/repl2.cljs rename to test/fixtures/repl2.cljs diff --git a/test/helper.rb b/test/helper.rb new file mode 100644 index 0000000..e3e3583 --- /dev/null +++ b/test/helper.rb @@ -0,0 +1,14 @@ +# Basic test environment. + +# blah fuck this +require 'rubygems' if !defined?(Gem) +require 'bundler/setup' + +require 'charlock_holmes' + +# bring in minitest +require 'minitest/autorun' + +# put lib and test dirs directly on load path +$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) +$LOAD_PATH.unshift File.expand_path('..', __FILE__) \ No newline at end of file diff --git a/spec/string_method_spec.rb b/test/string_methods_test.rb similarity index 76% rename from spec/string_method_spec.rb rename to test/string_methods_test.rb index 582e7c4..aea09db 100644 --- a/spec/string_method_spec.rb +++ b/test/string_methods_test.rb @@ -1,8 +1,8 @@ -require 'spec_helper' +require File.expand_path("../helper", __FILE__) require 'charlock_holmes/string' -describe String do - test 'has a detect_encoding method' do +class StringMethodsTest < MiniTest::Unit::TestCase + def test_adds_detect_encoding_method str = 'test' str.respond_to? :detect_encoding @@ -10,7 +10,7 @@ assert_equal 'ISO-8859-1', detected[:encoding] end - test 'has a detect_encoding method that accepts an encoding hint' do + def test_detect_encoding_accepts_encoding_hint_param str = 'test' str.respond_to? :detect_encoding @@ -18,7 +18,7 @@ assert_equal 'ISO-8859-1', detected[:encoding] end - test 'has a detect_encodings method' do + def test_adds_detect_encodings_method str = 'test' str.respond_to? :detect_encodings @@ -29,7 +29,7 @@ assert_equal ['ISO-8859-1', 'ISO-8859-2', 'UTF-8'], encoding_list end - test 'has a detect_encodings method that accepts an encoding hint' do + def test_detect_encodings_accepts_encoding_hint_param str = 'test' str.respond_to? :detect_encodings @@ -41,7 +41,7 @@ end if RUBY_VERSION =~ /1.9/ - test 'has a detect_encoding! method' do + def test_adds_detect_encoding_bang_method str = 'test' str.respond_to? :detect_encoding!