diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2014-05-03 13:34:55 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2014-05-03 13:34:55 -0700 |
commit | 966c206b924860bc6f3d95f7d0cf209a7d60e361 (patch) | |
tree | 3eeab572f789283b64a2dfe1119a70c90203c505 | |
parent | 0bbce98dedfb1d5e77aebd844f034250cf0150c0 (diff) | |
download | libyajl2-gem-966c206b924860bc6f3d95f7d0cf209a7d60e361.tar.gz |
levelling up test infrastruture
-rw-r--r-- | .reek.yml | 3 | ||||
-rw-r--r-- | .rubocop.yml | 38 | ||||
-rw-r--r-- | .travis.yml | 8 | ||||
-rw-r--r-- | Gemfile | 9 | ||||
-rw-r--r-- | Rakefile | 79 | ||||
-rwxr-xr-x | bootstrap.sh | 48 | ||||
-rw-r--r-- | ext/libyajl2/extconf.rb | 5 | ||||
-rw-r--r-- | libyajl2.gemspec | 5 | ||||
-rw-r--r-- | spec/ffi_spec.rb | 5 | ||||
-rw-r--r-- | spec/spec_helper.rb | 6 |
10 files changed, 185 insertions, 21 deletions
diff --git a/.reek.yml b/.reek.yml new file mode 100644 index 0000000..ad13021 --- /dev/null +++ b/.reek.yml @@ -0,0 +1,3 @@ +--- +UncommunicativeModuleName: + enabled: false diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..3d62982 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,38 @@ +AndOr: + Enabled: false +ClassLength: + Enabled: false +CommentAnnotation: + Enabled: false +Documentation: + Enabled: false +DoubleNegation: + Enabled: false +Encoding: + Enabled: false +Eval: + Enabled: false +FormatString: + Enabled: false +HashSyntax: + Enabled: false +LineLength: + Enabled: false +MethodLength: + Enabled: false +PercentLiteralDelimiters: + Enabled: false +RegexpLiteral: + Enabled: false +SignalException: + Enabled: false +SingleSpaceBeforeFirstArg: + Enabled: false +SpaceInsideBrackets: + Enabled: false +SpaceInsideParens: + Enabled: false +StringLiterals: + Enabled: false +TrailingComma: + EnforcedStyleForMultiline: comma diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..9e760d2 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +language: ruby +rvm: +- 1.8.7 +- 1.9.3 +- 2.0.0 +- 2.1.1 +script: +- bundle exec rake travis --trace @@ -1,3 +1,12 @@ source 'https://rubygems.org' gemspec + +group :development_extras do + gem 'rubocop', '= 0.21.0' + gem 'reek', '= 1.3.7' + gem 'test-kitchen', '~> 1.2' + gem 'kitchen-digitalocean' + gem 'kitchen-ec2' + gem 'kitchen-vagrant' +end @@ -4,9 +4,7 @@ require 'rake' require 'rubygems/package_task' require 'rspec/core/rake_task' -task :default => :spec - -GEM_NAME="libyajl2" +GEM_NAME = "libyajl2" gemspec = eval(File.read('libyajl2.gemspec')) @@ -14,7 +12,9 @@ Gem::PackageTask.new(gemspec) do |pkg| pkg.need_tar = true end -RSpec::Core::RakeTask.new(:spec) +# +# build tasks +# desc "repackage and install #{GEM_NAME}-#{Libyajl2::VERSION}.gem" task :install => :repackage do @@ -39,3 +39,74 @@ task :clean do sh "git clean -fdx" end +# +# test tasks +# + +RSpec::Core::RakeTask.new(:spec) + +namespace :integration do + begin + require 'kitchen' + rescue LoadError + task :vagrant do + puts "kitchen gem is not available" + end + task :cloud do + puts "kitchen gem is not available" + end + else + desc 'Run Test Kitchen with Vagrant' + task :vagrant do + Kitchen.logger = Kitchen.default_file_logger + Kitchen::Config.new.instances.each do |instance| + instance.test(:always) + end + end + + desc 'Run Test Kitchen with cloud plugins' + task :cloud do + if ENV['TRAVIS_PULL_REQUEST'] != 'true' + ENV['KITCHEN_YAML'] = '.kitchen.cloud.yml' + sh "kitchen test --concurrency 4" + end + end + end +end + +namespace :style do + desc 'Run Ruby style checks' + begin + require 'rubocop/rake_task' + rescue LoadError + task :rubocop do + puts "rubocop gem is not available" + end + else + Rubocop::RakeTask.new(:rubocop) do |t| + t.fail_on_error = false + end + end + + desc 'Run Ruby smell checks' + begin + require 'reek/rake/task' + rescue LoadError + task :reek do + puts "reek gem is not available" + end + else + Reek::Rake::Task.new(:reek) do |t| + t.fail_on_error = false + t.config_files = '.reek.yml' + end + end +end + +desc 'Run all style checks' +task :style => ['style:rubocop', 'style:reek'] + +desc 'Run all tests on Travis' +task :travis => ['style', 'spec', 'integration:cloud'] + +task :default => ['style', 'spec', 'integration:vagrant'] diff --git a/bootstrap.sh b/bootstrap.sh index 5c3edd3..870324d 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,11 +1,47 @@ #!/bin/sh -apt-get -y install ruby ruby1.9.1-dev -apt-get -y install git -apt-get -y install cmake build-essential -gem install bundler -pwd +set -e +set -x + +if test -f "/etc/lsb-release" && grep -q DISTRIB_ID /etc/lsb-release; then + platform=`grep DISTRIB_ID /etc/lsb-release | cut -d "=" -f 2 | tr '[A-Z]' '[a-z]'` + platform_version=`grep DISTRIB_RELEASE /etc/lsb-release | cut -d "=" -f 2` +fi + +compile_rubygems() { + cd /tmp + wget http://production.cf.rubygems.org/rubygems/rubygems-1.6.2.tgz -O - | tar zxf - + cd rubygems-1.6.2 && ruby setup.rb --no-format-executable + # i think this assumes running under bash + cd - +} + +case $platform in + "ubuntu") + export DEBIAN_FRONTEND=noninteractive + apt-get -y -y install bc + ubuntu_before_12_04=`echo "$platform_version >= 12.04" | bc` + if [ $ubuntu_before_12_04 ]; then + apt-get -q -y install ruby1.8 ruby1.8-dev rubygems1.8 libopenssl-ruby1.8 + apt-get -q -y install git-core cmake build-essential wget + update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.8 500 + update-alternatives --install /usr/bin/gem gem /usr/bin/gem1.8 500 + update-alternatives --config ruby + update-alternatives --config gem + compile_rubygems + else + apt-get -q -y install ruby-1.9 ruby1.9.1-dev + apt-get -q -y install git cmake build-essential + fi + ;; + *) + echo "i don't know how to setup base o/s on this platform, hope it works!" + ;; +esac + +gem install bundler --no-rdoc --no-ri + cd /tmp/kitchen/data -bundle install +bundle install --without development_extras rake compile rake spec diff --git a/ext/libyajl2/extconf.rb b/ext/libyajl2/extconf.rb index 7c3148f..094f297 100644 --- a/ext/libyajl2/extconf.rb +++ b/ext/libyajl2/extconf.rb @@ -10,7 +10,7 @@ module Libyajl2Build PREFIX = File.expand_path("../../../lib/libyajl2/vendored-libyajl2", __FILE__).freeze def self.windows? - !!(RUBY_PLATFORM =~ /mswin|mingw|windows/) + !!(RUBY_PLATFORM =~ /mswin|mingw|windows/) end def self.libyajl2_vendor_dir @@ -27,7 +27,7 @@ module Libyajl2Build def self.configure_cmd # NB: this is not a gnu configure command - args = %W[ + %W[ sh #{configure} -p @@ -61,7 +61,6 @@ module Libyajl2Build run_build_commands or raise BuildError, "Failed to build libyajl2 library." end end - end Libyajl2Build.run diff --git a/libyajl2.gemspec b/libyajl2.gemspec index 5ff1abb..22c7daf 100644 --- a/libyajl2.gemspec +++ b/libyajl2.gemspec @@ -14,14 +14,15 @@ Gem::Specification.new do |spec| spec.licenses = ["Apache 2.0"] spec.files = `git ls-files -z`.split("\x0") + - `cd ext/libyajl2/vendor/yajl && git ls-files -z`.split("\x0").map {|p| p.sub!(/^/, 'ext/libyajl2/vendor/yajl/') } + `cd ext/libyajl2/vendor/yajl && git ls-files -z`.split("\x0").map { |p| p.sub!(/^/, 'ext/libyajl2/vendor/yajl/') } spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] spec.extensions = Dir["ext/**/extconf.rb"] - spec.add_development_dependency "bundler", "~> 1.5" + # required for 'rake spec' + spec.add_development_dependency "bundler" spec.add_development_dependency "rake" spec.add_development_dependency "rspec", "~> 2.14" spec.add_development_dependency "ffi", "~> 1.9" diff --git a/spec/ffi_spec.rb b/spec/ffi_spec.rb index 057e0bc..f4a3a6e 100644 --- a/spec/ffi_spec.rb +++ b/spec/ffi_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' require 'ffi' -module Libyajl_Test_FFI +module LibyajlTestFFI extend ::FFI::Library libname = ::FFI.map_library_name("yajl") @@ -15,7 +15,6 @@ end describe "when loading the library with FFI" do it "we can get back an FFI::Pointer from yajl_gen_alloc" do - expect(Libyajl_Test_FFI.yajl_gen_alloc(nil)).to be_an_instance_of(FFI::Pointer) + expect(LibyajlTestFFI.yajl_gen_alloc(nil)).to be_an_instance_of(FFI::Pointer) end end - diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ef0e092..63a138c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,4 @@ -$: << File.expand_path(File.join(File.dirname( __FILE__ ), "../lib")) +$LOAD_PATH << File.expand_path(File.join(File.dirname( __FILE__ ), "../lib")) require 'libyajl2' @@ -6,8 +6,8 @@ RSpec.configure do |c| c.order = 'random' - c.expect_with :rspec do |c| - c.syntax = :expect + c.expect_with :rspec do |c2| + c2.syntax = :expect end end |