Skip to content

Commit

Permalink
switch to minitest from rspec
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmario committed Mar 8, 2013
1 parent 0989ca9 commit ee3ce3b
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 92 deletions.
3 changes: 0 additions & 3 deletions .rspec

This file was deleted.

12 changes: 2 additions & 10 deletions Gemfile.lock
Expand Up @@ -7,24 +7,16 @@ 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

DEPENDENCIES
chardet
charlock_holmes!
minitest
rake-compiler (>= 0.7.5)
rspec (>= 2.0.0)
23 changes: 5 additions & 18 deletions 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"
Expand All @@ -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
Rake::Task[:test].prerequisites << :compile
2 changes: 1 addition & 1 deletion charlock_holmes.gemspec
Expand Up @@ -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
9 changes: 0 additions & 9 deletions spec/spec_helper.rb

This file was deleted.

16 changes: 8 additions & 8 deletions spec/converter_spec.rb → 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'
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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
68 changes: 32 additions & 36 deletions spec/encoding_detector_spec.rb → 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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -82,40 +80,38 @@
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

assert supported_encodings.is_a?(Array)
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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions 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__)
14 changes: 7 additions & 7 deletions spec/string_method_spec.rb → test/string_methods_test.rb
@@ -1,24 +1,24 @@
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

detected = str.detect_encoding
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

detected = str.detect_encoding 'UTF-8'
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

Expand All @@ -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

Expand All @@ -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!

Expand Down

0 comments on commit ee3ce3b

Please sign in to comment.