minispec-metadata-3.3.1/0000755000004100000410000000000013607400454015136 5ustar www-datawww-dataminispec-metadata-3.3.1/.travis.yml0000644000004100000410000000021413607400454017244 0ustar www-datawww-datalanguage: ruby rvm: - 2.0.0 - 2.1.2 - 2.2.2 - 2.4.1 script: bundle exec rake gemfile: - Gemfile - gemfiles/minitest-4.gemfile minispec-metadata-3.3.1/README.md0000644000004100000410000000735013607400454016422 0ustar www-datawww-dataMinispec::Metadata ================== [![Build Status](https://secure.travis-ci.org/ordinaryzelig/minispec-metadata.png?branch=master)](http://travis-ci.org/ordinaryzelig/minispec-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 4 and up, Ruby version 2 and up, Rails version 5.1 and up. Might work with older versions but I haven't tested them. See .travis for more info. minispec-metadata-3.3.1/gemfiles/0000755000004100000410000000000013607400454016731 5ustar www-datawww-dataminispec-metadata-3.3.1/gemfiles/minitest-4.gemfile0000644000004100000410000000011213607400454022252 0ustar www-datawww-datasource 'https://rubygems.org' gem 'minitest', '< 5' gemspec path: '../' minispec-metadata-3.3.1/spec/0000755000004100000410000000000013607400454016070 5ustar www-datawww-dataminispec-metadata-3.3.1/spec/describe.spec.rb0000644000004100000410000000654413607400454021137 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 if Minitest::Versions::MAJOR >= 5 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 end describe MinispecMetadata::Describe, 'additional description', :respect do it 'respects additional description' do if Minitest::Versions::MAJOR <= 4 self.class.name.must_equal 'MinispecMetadata::Describe::additional description' else self.class.name.must_equal 'MinispecMetadata::Describe::additional description::respect' end metadata.must_equal( 'additional description' => true, :respect => true, ) end end minispec-metadata-3.3.1/spec/readme.spec.rb0000644000004100000410000000037313607400454020606 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.3.1/spec/helper.rb0000644000004100000410000000026713607400454017701 0ustar www-datawww-datarequire 'bundler/setup' require 'awesome_print' require 'minitest/autorun' require 'minitest/pride' require 'minispec-metadata' class MiniTest::Unit::TestCase parallelize_me! end minispec-metadata-3.3.1/spec/tags.spec.rb0000644000004100000410000000504513607400454020310 0ustar www-datawww-datarequire_relative 'helper' #require_relative 'test_tags_verifier' if ENV['TEST_TAGS'] && MinispecMetadata.supports_tags? if MinispecMetadata.supports_tags? 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 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 /^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 end minispec-metadata-3.3.1/spec/regression.spec.rb0000644000004100000410000000063313607400454021530 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.3.1/spec/it.spec.rb0000644000004100000410000000334513607400454017767 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 /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.3.1/spec/minispec_metadata.spec.rb0000644000004100000410000000143113607400454023014 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'] metadata = MinispecMetadata.extract_metadata args args.must_equal [:asdf, 'description'] end end end minispec-metadata-3.3.1/CHANGELOG.md0000644000004100000410000000142313607400454016747 0ustar www-datawww-data## 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.3.1/.gitignore0000644000004100000410000000023213607400454017123 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.3.1/Rakefile0000644000004100000410000000022613607400454016603 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.3.1/lib/0000755000004100000410000000000013607400454015704 5ustar www-datawww-dataminispec-metadata-3.3.1/lib/minitest/0000755000004100000410000000000013607400454017540 5ustar www-datawww-dataminispec-metadata-3.3.1/lib/minitest/versions.rb0000644000004100000410000000017113607400454021734 0ustar www-datawww-datamodule Minitest module Versions MAJOR, MINOR, PATCH = Minitest::Unit::VERSION.split('.').map(&:to_i) end end minispec-metadata-3.3.1/lib/minitest/minispec_metadata_plugin.rb0000644000004100000410000000123213607400454025110 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.3.1/lib/backwards.rb0000644000004100000410000000031313607400454020167 0ustar www-datawww-data# For a bit of backward compatibility. # Thanks to @jhsu for discovering the discrepancy. if Minitest::Versions::MAJOR <= 4 class MiniTest::Unit::TestCase def name __name__ end end end minispec-metadata-3.3.1/lib/minispec-metadata.rb0000644000004100000410000000101213607400454021610 0ustar www-datawww-datarequire 'minitest/spec' require 'minitest/versions' require_relative 'backwards' 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.3.1/lib/minispec-metadata/0000755000004100000410000000000013607400454021271 5ustar www-datawww-dataminispec-metadata-3.3.1/lib/minispec-metadata/tags.rb0000644000004100000410000000414513607400454022560 0ustar www-datawww-datamodule MinispecMetadata module_function def tags @tags ||= [] end def add_tag_string(tag_string) tags << Tag.new(tag_string) end def supports_tags? minitest_version_supports_tags? && ruby_version_supports_tags? end # Because of plugin system. def minitest_version_supports_tags? Minitest::Versions::MAJOR >= 5 end # Because of #prepend. def ruby_version_supports_tags? RUBY_VERSION.to_i >= 2 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 if MinispecMetadata.supports_tags? Minitest::Test.singleton_class.send :prepend, MinispecMetadata::Tags end minispec-metadata-3.3.1/lib/minispec-metadata/version.rb0000644000004100000410000000006013607400454023277 0ustar www-datawww-datamodule MinispecMetadata VERSION = "3.3.1" end minispec-metadata-3.3.1/lib/minispec-metadata/rails.rb0000644000004100000410000000021413607400454022725 0ustar www-datawww-datarequire 'minispec-metadata' ActiveSupport.on_load(:active_support_test_case) do ActiveSupport::TestCase.include MinispecMetadata::It end minispec-metadata-3.3.1/lib/minispec-metadata/it.rb0000644000004100000410000000171513607400454022236 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.3.1/lib/minispec-metadata/describe.rb0000644000004100000410000000247113607400454023402 0ustar www-datawww-datamodule MinispecMetadata module Describe def describe(desc, *additional_desc, &block) metadata = MinispecMetadata.extract_metadata additional_desc # Minitest 5 allows unlimited additional_desc. # Minitest 4 allows max 1 additional_desc. # So we need to pass up only the number of allowed additional_desc. additional_allowed = if Minitest::Versions::MAJOR <= 4 additional_desc.first(1) else additional_desc end 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.3.1/Gemfile0000644000004100000410000000014613607400454016432 0ustar www-datawww-datasource 'https://rubygems.org' # Specify your gem's dependencies in minispec-metadata.gemspec gemspec minispec-metadata-3.3.1/.ruby-version0000644000004100000410000000001313607400454017575 0ustar www-datawww-dataruby-2.4.0 minispec-metadata-3.3.1/minispec-metadata.gemspec0000644000004100000410000000170213607400454022070 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 'awesome_print' gem.add_development_dependency 'rake' end minispec-metadata-3.3.1/LICENSE.txt0000644000004100000410000000205213607400454016760 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.