minispec-metadata-3.5.0/0000755000004100000410000000000014473714567015156 5ustar www-datawww-dataminispec-metadata-3.5.0/README.md0000644000004100000410000000700314473714567016435 0ustar www-datawww-dataMinispec::Metadata ================== https://github.com/ordinaryzelig/minispec-metadata ## Usage ```ruby # readme.spec.rb require 'minitest/autorun' require 'minispec-metadata' describe 'Usage', some: 'metadata' do before do # Example usefulness: # Capybara.current_driver = metadata[:driver] end it 'defines a metadata method', more: 'metadata' do _(metadata).must_equal( some: 'metadata', more: 'metadata', ) end it 'gives priority to closest metadata', some: 'different metadata' do _(metadata).must_equal( some: 'different metadata', ) end it 'provides a method to get the description of the spec' do _(desc).must_equal 'provides a method to get the description of the spec' end describe MinispecMetadata, 'additional description' do it 'provides a method to get the descriptions' do _(self.class.descs).must_equal [MinispecMetadata, 'additional description'] end it 'provides a method to get only the additional description' do _(self.class.additional_desc).must_equal ['additional description'] end it 'is not needed to get the described object' do # This is built in to Minitest, you don't need this gem to do this. _(self.class.desc).must_equal MinispecMetadata end it 'treats additional descriptions as metadata too', meta: 'data' do _(metadata).must_equal( :some => 'metadata', 'additional description' => true, :meta => 'data', ) end end # Thanks to @mfpiccolo for this. it 'allows array of symbols like RSpec', :these, :work, :too do _(metadata[:these]).must_equal true _(metadata[:work]).must_equal true _(metadata[:too]).must_equal true end end ``` Another great use is to do a version of [Ryan Bates' VCR trick](http://railscasts.com/episodes/291-testing-with-vcr?view=asciicast). ```ruby describe 'VCR trick' do it 'allows you to name your cassettes the same as the spec' do VCR.use_cassette desc do end end end ``` ### Tags (Only for Ruby >= 2 and Minitest >= 5) Use the `--tag TAG` or `-tTAG` option to focus on certain tests according to metadata (will match both string/symbol as key/value). E.g. Run only the slow tests below with option `--tag js`: ```ruby describe 'integration tests' do it 'runs super slow JS stuff', :js do # Will run. end it 'runs fast stuff' do # Will not run. end end ``` You can use `--tag` more than once to include more tags to be run (any matching tags will run). If an exclusive tag, e.g. `~slow`, is used alone, all tests except those tagged slow will be run. If an exclusive tag is used in addition to any inclusive tags, then the exclusive tag will just filter those included. Note that when using `rake`, you need to wrap Minitest's options like this: `rake test TESTOPTS='--tag js'`. ## Installation Add this line to your application's Gemfile: gem 'minispec-metadata' And then execute: $ bundle Or install it yourself: $ gem install minispec-metadata ### Rails There are things you *MUST* do to get Minitest::Spec to work with rails that this gem cannot do for you. There are a handful of gems that will help you including my [minispec-rails gem](https://github.com/ordinaryzelig/minispec-rails). Whatever path you decide to take, do this AFTER you've taken those steps: `require 'minispec-metadata/rails'` (Thanks to @fredngo for help with testing with Rails.) ## Compatibility Tested with Minitest 5, Ruby version 3, Rails version 5.1. minispec-metadata-3.5.0/gemfiles/0000755000004100000410000000000014473714567016751 5ustar www-datawww-dataminispec-metadata-3.5.0/gemfiles/minitest-4.gemfile0000644000004100000410000000011214473714567022272 0ustar www-datawww-datasource 'https://rubygems.org' gem 'minitest', '< 5' gemspec path: '../' minispec-metadata-3.5.0/spec/0000755000004100000410000000000014473714567016110 5ustar www-datawww-dataminispec-metadata-3.5.0/spec/describe.spec.rb0000644000004100000410000000631314473714567021151 0ustar www-datawww-datarequire_relative 'helper' describe MinispecMetadata::Describe, super_meta: 'data' do describe 'as 2nd arg after description', second: '2nd' do it 'is accessible with metadata method' do _(metadata.fetch(:second)).must_equal '2nd' end end describe 'as 3rd arg after additional description', 'more description', third: '3rd' do it 'is accessible with metadata method' do _(metadata.fetch(:third)).must_equal '3rd' end end describe 'when just a symbol is passed', :axiom, :vcr do it 'uses symbols as true values' do _(metadata.fetch(:axiom)).must_equal true _(metadata.fetch(:vcr)).must_equal true end end describe 'duplicate', first: '1st' do it 'correctly scopes metadata to current description' do _(metadata).must_equal(first: '1st', super_meta: 'data') _(metadata.key?(:second)).must_equal false end end describe 'duplicate', second: '2nd' do it 'correctly scopes metadata to current description' do _(metadata).must_equal(second: '2nd', super_meta: 'data') _(metadata.key?(:first)).must_equal false end end describe 'nested', sub: 'desc' do it 'inherits from surrounding description', lowest: 'totem' do _(metadata).must_equal( super_meta: 'data', sub: 'desc', lowest: 'totem', ) end it 'gives nearest metadata priority', sub: 'zero', super_meta: 'priority' do _(metadata).must_equal( sub: 'zero', super_meta: 'priority', ) end end desc_class = describe 'return value' do it 'equals description class' do _(desc_class).must_equal self.class end end end # Only allows 1 additional description. describe MinispecMetadata::Describe, 'additional description' do it 'provides a method to get the descriptions' do _(self.class.descs).must_equal [MinispecMetadata::Describe, 'additional description'] end it 'provides a method to get only the additional description' do _(self.class.additional_desc).must_equal ['additional description'] end describe 'nested describe with no additional description' do it 'does not inherit additional description from parent' do _(self.class.additional_desc).must_be_empty end end end describe 'stuff', 'more stuff', {even_more: 'stuff'}, :holy_cow_that_is_a_lot_of_stuff, :minitest_5 do it 'preserves additional description but still allows any value for metadata', :more? => 'yeah' do _(self.class.descs).must_equal ['stuff', 'more stuff', {even_more: 'stuff'}, :holy_cow_that_is_a_lot_of_stuff, :minitest_5] _(metadata).must_equal( 'more stuff' => true, :even_more => 'stuff', :holy_cow_that_is_a_lot_of_stuff => true, :more? => 'yeah', :minitest_5 => true, ) end end describe MinispecMetadata::Describe, 'additional description', :respect do it 'respects additional description' do _(self.class.name).must_equal 'MinispecMetadata::Describe::additional description::respect' _(metadata).must_equal( 'additional description' => true, :respect => true, ) end end minispec-metadata-3.5.0/spec/readme.spec.rb0000644000004100000410000000037314473714567020626 0ustar www-datawww-datarequire_relative 'helper' readme = File.readlines(File.dirname(__FILE__) + '/../README.md').map(&:chomp) specs = readme.select do |line, idx| true if (line == '# readme.spec.rb')..(line == '```') end[0...-1] .join("\n") instance_eval specs minispec-metadata-3.5.0/spec/helper.rb0000644000004100000410000000025514473714567017716 0ustar www-datawww-datarequire 'bundler/setup' require 'awesome_print' require 'minitest/autorun' require 'minitest/pride' require 'minispec-metadata' class Minitest::Test parallelize_me! end minispec-metadata-3.5.0/spec/tags.spec.rb0000644000004100000410000000456714473714567020340 0ustar www-datawww-datarequire_relative 'helper' module MinispecMetadata describe Tag do it 'captures the metadata key' do tag = Tag.new('~sure') _(tag.key).must_equal( 'sure') _(tag.value?).must_equal false end it 'captures metadata key/value' do tag = Tag.new('key:value') _(tag.key).must_equal( 'key') _(tag.value).must_equal( 'value') end it 'captures inclusivity' do tag = Tag.new('sure') _(tag).must_be :inclusive? end it 'captures exclusivity' do tag = Tag.new('~sure') _(tag).must_be :exclusive? end it 'captures exclusivity' do tag = Tag.new('~sure') _(tag).must_be :exclusive? end end TAGS_TEST = describe Tags do def self.passing_test(*args) it(*args) do pass end end passing_test '1', :minitest_5 passing_test '2', 'minitest_5', :slow passing_test '3', :minitest_4 passing_test '4', :minitest_4, 'slow' passing_test '5', :slow, specific: 'value' passing_test '6', 'specific' => :value, unmatched: :value passing_test '7', 'specific' => 'value' end # Test the #runnable_methods of tags_test above with different sets of Tags. describe '#runnable_methods' do def stub_tags(tag_strings, &block) tags = tag_strings.map { |tag_string| Tag.new(tag_string) } MinispecMetadata.stub :tags, tags, &block end def strip_prefix(name) name.sub %r/^test_\d{4}_/, '' end def self.assert_runnable_methods_with_tags(tag_strings, expected_runnable_methods) it "returns runnable_methods with tag_strings #{tag_strings.inspect}" do stub_tags tag_strings do _(TAGS_TEST .runnable_methods .map(&method(:strip_prefix)) .sort) .must_equal expected_runnable_methods end end end assert_runnable_methods_with_tags ['minitest_5'], %w[ 1 2 ] assert_runnable_methods_with_tags ['~minitest_4'], %w[ 1 2 5 6 7 ] assert_runnable_methods_with_tags ['specific:value'], %w[ 5 6 7 ] assert_runnable_methods_with_tags ['~unmatched:value'], %w[ 1 2 3 4 5 7 ] assert_runnable_methods_with_tags ['minitest_5', 'minitest_4', 'specific:value', '~unmatched:value', '~slow'], %w[ 1 3 7 ] end end minispec-metadata-3.5.0/spec/regression.spec.rb0000644000004100000410000000064414473714567021552 0ustar www-datawww-datarequire_relative 'helper' # Confirmed to not work with v2.0.0. # Thanks to @jrochkind. describe "top level describe" do describe "an inner describe" do before do _(desc).wont_be_nil end it "an example inside inner describe" do _(desc).must_equal 'an example inside inner describe' end end it "another top level example" do _(desc).must_equal 'another top level example' end end minispec-metadata-3.5.0/spec/it.spec.rb0000644000004100000410000000341014473714567020000 0ustar www-datawww-datarequire_relative 'helper' describe MinispecMetadata::It do it 'stores metadata for current spec', meta: 'data' do _(metadata.fetch(:meta)).must_equal 'data' end specify 'it works with #specify', 1 => 2 do _(metadata.fetch(1)).must_equal 2 end it 'returns empty hash when no metadata set' do _(metadata).must_equal({}) end name = it 'returns name' do _(name).must_match %r/test_/ end describe 'before/after hooks' do before do _(metadata.fetch(:before)).must_equal 'accessible' end it 'is accessible in hooks', before: 'accessible', after: 'also accessible' do pass end after do _(metadata.fetch(:after)).must_equal 'also accessible' end end describe 'with description metadata', description_meta: 'data' do it 'inherits metadata from description' do _(metadata.fetch(:description_meta)).must_equal 'data' end it "uses symbols as true values", :verity, :words_are_hard do _(metadata).must_equal( description_meta: 'data', verity: true, words_are_hard: true, ) end describe 'in a nested describe', 'with no metadata' do it 'works', works: true do _(metadata).must_equal( :description_meta => 'data', 'with no metadata' => true, :works => true, ) end end describe 'in a nested describe', with_metadata: true do it 'works', works: true do _(metadata).must_equal(works: true, with_metadata: true, description_meta: 'data') end end end end describe MinispecMetadata::It, '#desc' do it 'provides a method to get the name of the spec' do _(desc).must_equal 'provides a method to get the name of the spec' end end minispec-metadata-3.5.0/spec/minispec_metadata.spec.rb0000644000004100000410000000135514473714567023041 0ustar www-datawww-datarequire_relative 'helper' describe MinispecMetadata do describe '#extract_metadata' do it 'extracts from a hash' do metadata = MinispecMetadata.extract_metadata [{asdf: true}] _(metadata).must_equal asdf: true end it 'extracts from symbols, returns hash keys with true values' do metadata = MinispecMetadata.extract_metadata [:asdf, :fdsa] _(metadata).must_equal asdf: true, fdsa: true end it 'extracts a mix' do metadata = MinispecMetadata.extract_metadata [:asdf, {fdsa: true}] _(metadata).must_equal asdf: true, fdsa: true end it 'does not remove metadata from args' do args = [:asdf, 'description'] _(args).must_equal [:asdf, 'description'] end end end minispec-metadata-3.5.0/CHANGELOG.md0000644000004100000410000000202414473714567016765 0ustar www-datawww-data## 3.5.0 * Use Minitest \_() syntax to get rid of deprecation warnings. (@The-Alchemist) ## 3.4 * Removed support for Ruby <2, Minitest <5. * Convert remaining use of MiniTest to Minitest. (@manuelvanrijn) ## >3.2.1 <3.4 Lazily (not) documented here. ## 3.2.1 * Remove backwards compatibility for `__dir__`. (Thanks @brennovich for noticiing.) ## 3.2.0 * Add support for tags for command line filtering. ## 3.1.0 * Do not desctructively extract metadata from additional_desc. * Use ALL additional_desc as metadata. ## 3.0.0 * Total rewrite. * Fix bug with `it` clashing with `describe` when they were on the same level. (@jrochkind) * Remove `spec_description`. Just use `self.class.desc` * Rename `spec_descriptions` to `descs` (to try to stay close to Minitest naming) and moved it to the spec class level. * Rename `spec_additional_description` to `additional_desc` (that's what Minitest calls it) and moved it to the spec class level. * Rename `MiniSpec` to `Minispec`. The gem is named like it should be camel-cased this way. minispec-metadata-3.5.0/.gitignore0000644000004100000410000000023214473714567017143 0ustar www-datawww-data*.gem *.rbc .bundle .config .yardoc Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp minispec-metadata-3.5.0/Rakefile0000644000004100000410000000022614473714567016623 0ustar www-datawww-datarequire "bundler/gem_tasks" require 'rake/testtask' task :default => [:test] Rake::TestTask.new :test do |t| t.pattern = 'spec/**/*.spec.rb' end minispec-metadata-3.5.0/lib/0000755000004100000410000000000014473714567015724 5ustar www-datawww-dataminispec-metadata-3.5.0/lib/minitest/0000755000004100000410000000000014473714567017560 5ustar www-datawww-dataminispec-metadata-3.5.0/lib/minitest/minispec_metadata_plugin.rb0000644000004100000410000000123214473714567025130 0ustar www-datawww-data# This file gets auto required/executed by Minitest >= v5. # Any other version won't find this file automatically. require 'minispec-metadata' module Minitest def self.plugin_minispec_metadata_options(opts, options) opts.on '-t', '--tag TAG'do |tag_string| options[:tag_strings] ||= [] options[:tag_strings] << tag_string end end def self.plugin_minispec_metadata_init(options) if RUBY_VERSION.to_i >= 2 options.fetch(:tag_strings, []).each do |tag_string| MinispecMetadata.add_tag_string tag_string end else warn 'tags requires Ruby 2. If you really want it, please open an issue.' end end end minispec-metadata-3.5.0/lib/minispec-metadata.rb0000644000004100000410000000072014473714567021635 0ustar www-datawww-datarequire 'minitest/spec' require 'minispec-metadata/version' require 'minispec-metadata/it' require 'minispec-metadata/describe' require 'minispec-metadata/tags' module MinispecMetadata module_function def extract_metadata(args) metadata = {} args.each do |arg| case arg when Hash metadata.merge! arg else metadata.merge!(arg => true) end end metadata end end MiniSpecMetadata = MinispecMetadata minispec-metadata-3.5.0/lib/minispec-metadata/0000755000004100000410000000000014473714567021311 5ustar www-datawww-dataminispec-metadata-3.5.0/lib/minispec-metadata/tags.rb0000644000004100000410000000342214473714567022575 0ustar www-datawww-datamodule MinispecMetadata module_function def tags @tags ||= [] end def add_tag_string(tag_string) tags << Tag.new(tag_string) end end module MinispecMetadata module Tags def runnable_methods methods = super.dup if MinispecMetadata.tags.select(&:inclusive?).any? methods.select! do |runnable_method| runnable_method_matches_any_inclusive_tag?(runnable_method) end end methods.reject do |runnable_method| runnable_method_matches_any_exclusive_tag?(runnable_method) end end def runnable_method_matches_any_inclusive_tag?(runnable_method) tags = MinispecMetadata.tags.select(&:inclusive?) runnable_method_matches_any_tags?(runnable_method, tags) end def runnable_method_matches_any_exclusive_tag?(runnable_method) tags = MinispecMetadata.tags.select(&:exclusive?) runnable_method_matches_any_tags?(runnable_method, tags) end private def runnable_method_matches_any_tags?(runnable_method, tags) tags.any? do |tag| metadata = metadata_for_test_name(runnable_method) value = metadata[tag.key] || metadata[tag.key.to_sym] matches = if tag.value? value.to_s == tag.value else !!value end matches end end end class Tag def initialize(tag_string) @tag_string = tag_string end def exclusive? @tag_string.start_with? '~' end def inclusive? !exclusive? end def key @key ||= @tag_string[/\w+/] end def value @value ||= @tag_string.split(':').last if value? end def value? !!@tag_string[/:/] end end end Minitest::Test.singleton_class.send :prepend, MinispecMetadata::Tags minispec-metadata-3.5.0/lib/minispec-metadata/version.rb0000644000004100000410000000006014473714567023317 0ustar www-datawww-datamodule MinispecMetadata VERSION = "3.5.0" end minispec-metadata-3.5.0/lib/minispec-metadata/rails.rb0000644000004100000410000000021414473714567022745 0ustar www-datawww-datarequire 'minispec-metadata' ActiveSupport.on_load(:active_support_test_case) do ActiveSupport::TestCase.include MinispecMetadata::It end minispec-metadata-3.5.0/lib/minispec-metadata/it.rb0000644000004100000410000000171514473714567022256 0ustar www-datawww-datamodule MinispecMetadata module It def self.included(spec_class) spec_class.extend ClassMethods end module ClassMethods def it(description = 'anonymous', *metadata, &block) name = super description, &block metadata = MinispecMetadata.extract_metadata(metadata) self.it_descriptions[name] = description self.metadata_by_test_name[name] = metadata name end alias_method :specify, :it def metadata_by_test_name @metadata_by_test_name ||= {} end def it_descriptions @it_descriptions ||= {} end def metadata_for_test_name(test_name) describe_metadata.merge( metadata_by_test_name.fetch(test_name) ) end end def metadata self.class.metadata_for_test_name(name) end def desc self.class.it_descriptions.fetch(name) end end end Minitest::Spec.send :include, MinispecMetadata::It minispec-metadata-3.5.0/lib/minispec-metadata/describe.rb0000644000004100000410000000203114473714567023412 0ustar www-datawww-datamodule MinispecMetadata module Describe def describe(desc, *additional_desc, &block) metadata = MinispecMetadata.extract_metadata additional_desc additional_allowed = additional_desc cls = super(desc, *additional_allowed.compact, &block) cls.extend ClassMethods cls.additional_desc = additional_desc cls.describe_metadata = metadata || {} cls end module ClassMethods attr_reader :additional_desc def describe_metadata @describe_metadata ||= {} if superclass.respond_to?(:describe_metadata) superclass.describe_metadata.merge(@describe_metadata) else @describe_metadata end end def descs [desc, *additional_desc].compact end def additional_desc=(additional_desc) @additional_desc = additional_desc.freeze end def describe_metadata=(metadata) @describe_metadata = metadata.freeze end end end end Object.send :include, MinispecMetadata::Describe minispec-metadata-3.5.0/Gemfile0000644000004100000410000000014614473714567016452 0ustar www-datawww-datasource 'https://rubygems.org' # Specify your gem's dependencies in minispec-metadata.gemspec gemspec minispec-metadata-3.5.0/.ruby-version0000644000004100000410000000001314473714567017615 0ustar www-datawww-dataruby-3.1.2 minispec-metadata-3.5.0/minispec-metadata.gemspec0000644000004100000410000000173114473714567022112 0ustar www-datawww-data# -*- encoding: utf-8 -*- lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'minispec-metadata/version' Gem::Specification.new do |gem| gem.name = "minispec-metadata" gem.version = MinispecMetadata::VERSION gem.authors = ["Jared Ning"] gem.email = ["jared@redningja.com"] gem.description = %q{Minitest::Spec metadata} gem.summary = %q{Pass metadata to Minitest::Spec descriptions and specs like in RSpec.} gem.homepage = "https://github.com/ordinaryzelig/minispec-metadata" gem.license = 'MIT' gem.files = `git ls-files`.split($/) gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ["lib"] gem.add_dependency 'minitest' gem.add_development_dependency 'amazing_print', '~>1.5.0' gem.add_development_dependency 'rake', '~>13.0.6' end minispec-metadata-3.5.0/LICENSE.txt0000644000004100000410000000205214473714567017000 0ustar www-datawww-dataCopyright (c) 2012 Jared Ning MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.