diff --git a/.gitignore b/.gitignore index c22f19c..1fa0230 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ mkmf.log **/*.swp **/*.gem .idea +/rubyspec_temp/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..072bbc6 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "spec/ruby_spec"] + path = spec/ruby_spec + url = https://github.com/ruby/spec diff --git a/Gemfile b/Gemfile index b806447..762b189 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,7 @@ -source 'https://rubygems.org' +source 'https://rubygems.org' do + # Specify your gem's dependencies in faster_path.gemspec + gemspec +end -# Specify your gem's dependencies in faster_path.gemspec -gemspec +# https://github.com/ruby/spec dependencies +eval_gemfile File.expand_path('spec/ruby_spec/Gemfile', File.dirname(__FILE__)) diff --git a/README.md b/README.md index d242229..d2a007f 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ And then execute: Or install it yourself as: $ gem install faster_path - + **MAC USERS:** At the moment Mac users need to install the extension manualy. Go to the gem directory and run `cargo build --release` . There is an issue opened for this and I'm looking for people who have Macs to help on this. ## Usage @@ -136,7 +136,7 @@ Current methods implemented: | `FasterPath.extname` | `File#extname` | 11.2% | You may choose to use the methods directly, or scope change to rewrite behavior on the -standard library with the included refinements, or even call a method to monkeypatch +standard library with the included refinements, or even call a method to monkeypatch everything everywhere. **Note:** `Pathname#chop_basename` in Ruby STDLIB has a bug with blank strings, that is the @@ -184,6 +184,42 @@ Then, run `rake test` to run the tests, and `rake bench` for benchmarks. Learn and share performance tips on the [wiki](https://github.com/danielpclark/faster_path/wiki)! +### Building and running tests + +First, bundle the gem's development dependencies by running `bundle`. + +Then, build the rust code: + +```sh +rake build_src +``` + +FasterPath is tested with [The Ruby Spec Suite](https://github.com/ruby/spec) to ensure it is compatible with the +native implementation, and also has its own test suite testing its monkey-patching and refinements functionality. + +To run all the tests at once, simply run `rake`. +To run all the ruby spec tests, run `mspec`. + +To run an individual test or benchmark from FasterPath's own suite: + +```sh +# An individual test file: +ruby -I lib:test test/benches/absolute_benchmark.rb +# All tests: +rake minitest +``` + +To run an individual ruby spec test, run `mspec` with a path relative to `spec/ruby_spec`, e.g.: + +```sh +# A path to a file or a directory: +mspec core/file/basename_spec.rb +# Tests most relevant to FasterPath: +mspec core/file library/pathname +# All tests: +mspec +``` + ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/danielpclark/faster_path. diff --git a/Rakefile b/Rakefile index 7a19857..6fbd8da 100644 --- a/Rakefile +++ b/Rakefile @@ -27,12 +27,16 @@ task :build_lib => [:build_src, :clean_src] do puts "Completed build!" end -Rake::TestTask.new(:test) do |t| +Rake::TestTask.new(:minitest) do |t| t.libs << "test" t.libs << "lib" t.test_files = FileList['test/**/*_test.rb'] end +task :test => :minitest do |t| + exec 'mspec core/file library/pathname' +end + Rake::TestTask.new(:bench) do |t| t.libs = %w(lib test) t.pattern = 'test/**/*_benchmark.rb' diff --git a/lib/faster_path/optional/monkeypatches.rb b/lib/faster_path/optional/monkeypatches.rb index d0ea164..b7e831b 100644 --- a/lib/faster_path/optional/monkeypatches.rb +++ b/lib/faster_path/optional/monkeypatches.rb @@ -1,3 +1,5 @@ +require 'pathname' + module FasterPath def self.sledgehammer_everything! ::File.class_eval do diff --git a/spec/default.mspec b/spec/default.mspec new file mode 100644 index 0000000..b8e3c6d --- /dev/null +++ b/spec/default.mspec @@ -0,0 +1,8 @@ +load 'spec/ruby_spec/default.mspec' + +class MSpecScript + set :requires, ["-r#{File.expand_path('init', File.dirname(__FILE__))}"] + set :prefix, 'spec/ruby_spec' +end + +MSpec.disable_feature :encoding diff --git a/spec/init.rb b/spec/init.rb new file mode 100644 index 0000000..afe0b11 --- /dev/null +++ b/spec/init.rb @@ -0,0 +1,5 @@ +ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', File.dirname(__FILE__)) +$LOAD_PATH.unshift File.expand_path('../lib', File.dirname(__FILE__)) +require 'faster_path' +require 'faster_path/optional/monkeypatches' +FasterPath.sledgehammer_everything! diff --git a/spec/ruby_spec b/spec/ruby_spec new file mode 160000 index 0000000..8190a7c --- /dev/null +++ b/spec/ruby_spec @@ -0,0 +1 @@ +Subproject commit 8190a7c915fbcf4776b99390418fe63fc6086c02