Skip to content

Commit

Permalink
Test with The Ruby Spec Suite
Browse files Browse the repository at this point in the history
Adds The Ruby Spec Suite as a submodule and configures for running with
the FasterPath monkey patches.
  • Loading branch information
glebm committed Jun 25, 2016
1 parent 3784e3e commit 7c98f5e
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ mkmf.log
**/*.swp
**/*.gem
.idea
/rubyspec_temp/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "spec/ruby_spec"]
path = spec/ruby_spec
url = https://github.com/ruby/spec
9 changes: 6 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -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__))
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions lib/faster_path/optional/monkeypatches.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'pathname'

module FasterPath
def self.sledgehammer_everything!
::File.class_eval do
Expand Down
8 changes: 8 additions & 0 deletions spec/default.mspec
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions spec/init.rb
Original file line number Diff line number Diff line change
@@ -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!
1 change: 1 addition & 0 deletions spec/ruby_spec
Submodule ruby_spec added at 8190a7

0 comments on commit 7c98f5e

Please sign in to comment.