Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start porting stuff to minitest #184

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
8 changes: 7 additions & 1 deletion script/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
set -e

cd "$(dirname "$0")/.."
exec bundle install --binstubs --path vendor/gems "$@"
if bundle check 1>/dev/null 2>&1; then
echo "Gem environment up-to-date"
else
exec bundle install --binstubs --path vendor/gems "$@"
fi

exec bundle exec rake clean compile
20 changes: 20 additions & 0 deletions script/cibuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh
# Usage: script/cibuild
# CI build script.
set -e

# change into root dir and setup path
cd $(dirname "$0")/..

PATH="$(pwd)/bin:$(pwd)/script:$PATH"

# Write commit we're building at
git log -n 1 || true
echo

echo "Bootstraping"
script/bootstrap
echo

echo "Starting test suite"
script/test
11 changes: 11 additions & 0 deletions script/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
set -e
cd "$(dirname "$0")/.."

ruby --version 1>&2

# run minitest suite
exec ruby -I. \
-r "$(pwd)/test/setup" \
-e "ARGV.each { |f| require(f) }" \
-- ${*:-`find test -name '*_test.rb'`}
54 changes: 0 additions & 54 deletions spec/global/global_spec.rb

This file was deleted.

58 changes: 58 additions & 0 deletions test/dump_load_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require File.expand_path("../setup", __FILE__)

class DumpLoadAPITest < Minitest::Test
JSON_STR = "{\"a\":1234}".freeze
OBJ = {"a" => 1234}

def test_dump_class_method_exists
assert Yajl.respond_to?(:dump)
end

def test_dump_class_method_serializes_to_string
assert_equal JSON_STR, Yajl.dump(OBJ)
end

def test_encode_to_an_io
io = StringIO.new

Yajl.dump(OBJ, io)

io.rewind

assert_equal JSON_STR, io.read
end

def test_encode_with_block_supplied
Yajl.dump(a: 1234) do |chunk|
assert_equal JSON_STR, chunk
end
end

def test_load_class_method_exists
assert Yajl.respond_to?(:load)
end

def test_parse_from_a_string
assert_equal OBJ, Yajl.load(JSON_STR)
end

def test_parse_from_an_io
io = StringIO.new(JSON_STR)

assert_equal OBJ, Yajl.load(io)
end

def test_parse_with_block_specified
Yajl.load(JSON_STR) do |obj|
assert_equal OBJ, obj
end
end

def test_parse_from_io_with_block_specified
io = StringIO.new(JSON_STR)

Yajl.load(io) do |obj|
assert_equal OBJ, obj
end
end
end
21 changes: 21 additions & 0 deletions test/setup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Basic test environment.
#
# This should set up the load path for testing only. Don't require any support libs
# or gitrpc stuff in here.

# bring in minitest
require "minitest/autorun"

require "rubygems" if !defined?(Gem)
require "bundler/setup"

require "yajl"

# put lib and test dirs directly on load path
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
$LOAD_PATH.unshift File.expand_path("..", __FILE__)

# This is ridiculous...
if !defined? MiniTest::Test
MiniTest::Test = MiniTest::Unit::TestCase
end
9 changes: 5 additions & 4 deletions yajl-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ Gem::Specification.new do |s|
s.required_ruby_version = ">= 2.6.0"

# tests
s.add_development_dependency 'rake-compiler'
s.add_development_dependency 'rspec'
s.add_development_dependency "rake-compiler"
s.add_development_dependency "rspec"
s.add_development_dependency "minitest"
# benchmarks
s.add_development_dependency 'activesupport'
s.add_development_dependency 'json'
s.add_development_dependency "activesupport"
s.add_development_dependency "json"
s.add_development_dependency "benchmark-memory"
end