RSpec clone Home

A small RSpec clone based on Fix testing tools for Ruby.

Warning ⚠️

I'd like to avoid confusion in the Ruby community by emphasizing that the gem of this project is not rspec but r_spec.

The r_spec gem is a minimalist and personal reimplementation of the popular RSpec framework. My reimplementation is therefore independent of the original RSpec project.

On the job

For the purpose of the DSL reimplementation, I have kept the same RSpec module name, and following the Ruby gems naming convention, I called its gem r_spec.

However, to go further and explicitly indicate that this reimplementation is a clone, I have grouped all the code in a RSpec::Clone submodule within its r_spec-clone gem.

Why did I redo that?

An urge to simplify the RSpec DSL and reduce the complexity of the code that implements it, and nothing better to do during a stay in Tokyo.

Installation

Add this line to your application's Gemfile:

gem "r_spec"

And then execute:

bundle install

Or install it yourself as:

gem install r_spec

Update

All the code is centralized in the RSpec::Clone module, whose source code is versioned at https://github.com/cyril/r_spec-clone.rb.

To download the latest updates of the r_spec-clone gem, execute this command:

bundle update r_spec

Or update it yourself as:

gem update r_spec

Usage

Let's imagine a string_hello_world_spec.rb file that contains this code:

require "r_spec"

app = "Hello, World!"

RSpec.describe String do
  subject do
    app
  end

  before do
    subject.gsub!("World", friend)
  end

  context "when Alice is greeted" do
    let(:friend) { "Alice" }

    it { is_expected.to eq "Hello, Alice!" }
  end

  context "when Bob is greeted" do
    let(:friend) { "Bob" }

    it { is_expected.to eq "Hello, Bob!" }
  end
end

We can run it with Ruby:

ruby string_hello_world_spec.rb

The report of the execution should be:

string_hello_world_spec.rb:19
Success: expected to eq "Hello, Alice!".
string_hello_world_spec.rb:25
Success: expected to eq "Hello, Bob!".

Versioning

RSpec uses Semantic Versioning 2.0.0

License

The gem is available as open source under the terms of the MIT License.