Repository is archived
No release in over 3 years
Low commit activity in last 3 years
minitest-shared_description adds support for shared specs and shared spec subclasses to Minitest. Minitest supports shared specs by default using plain ruby modules, but does not support shared spec subclasses. In addition to making it possible to share subclasses, minitest-shared_desciption also provides a slightly nicer interface for sharing specs.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

minitest-shared_description¶ ↑

Note: While this library works fine, it was only used by Sequel’s tests, and it is not longer used by Sequel, and no longer maintained. You can probably replace what this library does using regular modules with ‘extend Minitest::Spec::DSL` (shared examples without spec subclasses) or `instance_exec(&shared_block)` (shared examples with spec subclasses). See github.com/jeremyevans/sequel/commit/e192b52b06d62e08685d1451529f74d980ff80f6 for an example of how to replace the use of this library.

minitest-shared_description adds support for shared specs and shared spec subclasses to Minitest. Minitest supports shared specs by default using plain ruby modules, but does not support shared spec subclasses. In addition to making it possible to share subclasses, minitest-shared_desciption also provides a slightly nicer interface for sharing specs.

Installation¶ ↑

gem install minitest-shared_description

Source Code¶ ↑

Source code is available on GitHub at github.com/jeremyevans/minitest-shared_description

Usage¶ ↑

require 'minitest/shared_description'

SharedExamples = shared_description do
  # You can do regular specs
  it "should do something" do
    # something
  end

  # You can also have spec subclasses
  describe "nested specs" do
    # Called inside the before/after of the class that includes SharedExamples
    before {}
    after {}

    # Called inside the before/after of the class that includes SharedExamples
    # and the before/after in this class
    it "should do something else" do
      # something
    end
  end
end

describe "something" do
  include SharedExamples
end

You can also have shared descriptions that are included in other shared descriptions:

SharedExample1 = shared_description do
  describe "nested specs 1" do
    before {}
    after {}
    it "should do something" do end
  end
end

SharedExample2 = shared_description do
  describe "nested specs 2" do
    before {}
    after {}
    it "should do something else" do end
  end
end

SharedExamples = shared_description do
  # Include shared description in shared description block
  include SharedExample1

  describe "nested shared description use" do
    # Include shared description in shared description class
    include SharedExample2
  end
end

Compatibility with minitest-rails¶ ↑

For Rails projects that make use of the minitest-rails gem, extend ActiveSupport::TestCase with the TestMethods module in test_helper.rb.

class ActiveSupport::TestCase
  extend Minitest::Spec::SharedDescription::TestMethods
end

License¶ ↑

MIT

Author¶ ↑

Jeremy Evans <code@jeremyevans.net>