diff --git a/script/bootstrap b/script/bootstrap index 500005c6..adba6ebf 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -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 diff --git a/script/cibuild b/script/cibuild new file mode 100755 index 00000000..0c871637 --- /dev/null +++ b/script/cibuild @@ -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 diff --git a/script/test b/script/test new file mode 100755 index 00000000..b3c4173a --- /dev/null +++ b/script/test @@ -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'`} diff --git a/spec/global/global_spec.rb b/spec/global/global_spec.rb deleted file mode 100644 index c7a096ce..00000000 --- a/spec/global/global_spec.rb +++ /dev/null @@ -1,54 +0,0 @@ -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb') - -describe "Yajl" do - context "dump" do - it "should exist as a class-method" do - expect(Yajl).to respond_to(:dump) - end - - it "should be able to encode to a string" do - expect(Yajl.dump({:a => 1234})).to eql('{"a":1234}') - end - - it "should be able to encode to an IO" do - io = StringIO.new - Yajl.dump({:a => 1234}, io) - io.rewind - expect(io.read).to eql('{"a":1234}') - end - - it "should be able to encode with a block supplied" do - Yajl.dump({:a => 1234}) do |chunk| - expect(chunk).to eql('{"a":1234}') - end - end - end - - context "load" do - it "should exist as a class-method" do - expect(Yajl).to respond_to(:load) - end - - it "should be able to parse from a string" do - expect(Yajl.load('{"a":1234}')).to eql({"a" => 1234}) - end - - it "should be able to parse from an IO" do - io = StringIO.new('{"a":1234}') - expect(Yajl.load(io)).to eql({"a" => 1234}) - end - - it "should be able to parse from a string with a block supplied" do - Yajl.load('{"a":1234}') do |h| - expect(h).to eql({"a" => 1234}) - end - end - - it "should be able to parse from an IO with a block supplied" do - io = StringIO.new('{"a":1234}') - Yajl.load(io) do |h| - expect(h).to eql({"a" => 1234}) - end - end - end -end diff --git a/test/dump_load_test.rb b/test/dump_load_test.rb new file mode 100644 index 00000000..d863fe71 --- /dev/null +++ b/test/dump_load_test.rb @@ -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 diff --git a/test/setup.rb b/test/setup.rb new file mode 100644 index 00000000..9b37e6c1 --- /dev/null +++ b/test/setup.rb @@ -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 diff --git a/yajl-ruby.gemspec b/yajl-ruby.gemspec index 50ca7a4b..192a9755 100644 --- a/yajl-ruby.gemspec +++ b/yajl-ruby.gemspec @@ -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