Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/vinistock/loupe

A toy Ruby test framework with built in parallelism
https://github.com/vinistock/loupe

framework parallel ractor ruby test

Last synced: 6 days ago
JSON representation

A toy Ruby test framework with built in parallelism

Awesome Lists containing this project

README

        


loupe

# Loupe

Loupe is the toy test framework used in the talk [Parallel testing with Ractors: putting CPUs to work](https://www.youtube.com/watch?v=bvFj6_dulSo).

## Installation

Add the gem to the `Gemfile`.

```ruby
gem "loupe"
```

And then execute:

```shell
bundle install
```

Install bundler binstubs in your application.

```shell
bundle binstub loupe
```

## Usage

Currently, Loupe only supports writing tests using the test methods syntax. Tests must inherit from `Loupe::Test`, but do not need to explicitly require `test_helper`, like the example below.

```ruby
# frozen_string_literal: true

class MyTest < Loupe::Test
def before
@author = Author.create(name: "John")
@post = Post.create(author: @author)
end

def after
@author.destroy
@post.destroy
end

def test_post_is_linked_to_author
expect(@post.author.name).to_be_equal_to("John")
end
end
```

To run the test suite, invoke the executable using the binstub generated by bundler.

```shell
bin/loupe test/post_test.rb test/author_test.rb
```

Tests can run in parallel using Ractor or process mode. When using Ractors, the application's code must be Ractor compatible.

```shell
bin/loupe --ractor # [default] run tests using Ractor workers
bin/loupe --process # run tests using forked processes
bin/loupe --interactive # [default] use an interactive reporter to display test results
bin/loupe --plain # use a plain reporter to display test results
bin/loupe --color, --no-color # enable/disable output colors
bin/loupe --editor=EDITOR # which editor to use for opening files when using interactive mode. The default is the environment variable $EDITOR
```

To hook Loupe into Rake, use the provided rake task as in the example below.

```ruby
# Rakefile

require "loupe/rake_task"

# Instantiate the task and append any desired CLI options
Loupe::RakeTask.new do |options|
options << "--plain"
end

# Optionally, set the default task to be test
task default: :test
```

Then run

```shell
bundle exec rake test
```

## Credits

This project draws a lot of inspiration from other Ruby test frameworks, namely

- [Minitest](https://github.com/seattlerb/minitest)
- [rspec](https://github.com/rspec/rspec)

## Contributing

Please refer to the guidelines in [contributing](https://github.com/vinistock/loupe/blob/master/CONTRIBUTING.md).