From 0e545c6824c99d179b41c2e73c3903a5df4f68df Mon Sep 17 00:00:00 2001 From: Thomas Sawyer Date: Sun, 22 Nov 2026 20:12:56 -0500 Subject: [PATCH] Bring the notations back into Assay Fluidity, RSpecial, Assay MiniTest and Assay TestUnit were spun off as separate gems in 0.4. They return as assay/fluidity, assay/rspec, assay/minitest and assay/testunit, each loaded on its own, with their demos. The Minitest and Test::Unit adapters are rewritten for current versions of those frameworks. Fixes found on the way: with the fluent assert loaded no assay could fail; negation was ignored in the fluent fallback; will_not was never defined; assert_in_epsilon raised NameError in the Test::Unit notation; the ordering assays had the wrong message; like? used the =~ that Ruby 3.2 removed from Object. Replaces the old packaging with a gemspec, Rakefile and GitHub Actions. Co-Authored-By: Claude Fable 5.2 --- .gemspec | 307 ----------- .github/workflows/ci.yml | 30 ++ .gitignore | 8 +- .index | 74 --- .travis.yml | 9 - .yardopts | 2 +- Assembly | 40 -- Gemfile | 2 +- HISTORY.md | 45 ++ MANIFEST | 117 ----- README.md | 219 ++++---- Rakefile | 31 ++ assay.gemspec | 39 ++ demo/applique/helper.rb | 2 + demo/{ => core}/00_introduction.md | 0 .../01_assay_classes/00_introduction.md | 0 .../01_assay_classes/01_nil_assay.md | 0 .../01_assay_classes/02_boolean_assay.md | 0 .../01_assay_classes/03_false_assay.md | 0 .../01_assay_classes/03_true_assay.md | 0 .../01_assay_classes/04_like_assay.md | 0 .../01_assay_classes/05_equal_assay.md | 0 .../01_assay_classes/06_unequal_assay.md | 0 .../01_assay_classes/07_equality_assay.md | 0 .../01_assay_classes/08_identity_assay.md | 0 .../01_assay_classes/09_case_assay.md | 0 .../01_assay_classes/10_match_assay.md | 0 .../01_assay_classes/11_nomatch_assay.md | 0 .../01_assay_classes/12_compare_assay.md | 0 .../01_assay_classes/13_less_assay.md | 0 .../01_assay_classes/14_more_assay.md | 0 .../01_assay_classes/15_less_equal_assay.md | 0 .../01_assay_classes/16_more_equal_assay.md | 0 .../01_assay_classes/17_close_assay.md | 0 .../01_assay_classes/17_within_assay.md | 0 .../01_assay_classes/18_kind_assay.md | 4 +- .../01_assay_classes/19_instance_assay.md | 4 +- .../01_assay_classes/20_include_assay.md | 0 .../01_assay_classes/21_empty_assay.md | 0 .../01_assay_classes/22_respond_assay.md | 0 .../01_assay_classes/23_execution_assay.md | 0 .../01_assay_classes/23_return_assay.md | 0 .../01_assay_classes/24_rescue_assay.md | 0 .../01_assay_classes/25_raise_assay.md | 0 .../01_assay_classes/26_throw_assay.md | 0 .../01_assay_classes/27_path_assay.md | 0 .../01_assay_classes/28_directory_assay.md | 0 .../01_assay_classes/29_file_assay.md | 0 .../01_assay_classes/30_output_assay.md | 0 .../01_assay_classes/31_stdout_assay.md | 0 .../01_assay_classes/32_stderr_assay.md | 0 demo/{ => core}/02_lookup.md | 0 demo/{ => core}/03_assertor.md | 0 demo/{ => core}/04_assay.md | 12 +- demo/fluidity/00_intro.md | 7 + demo/fluidity/01_should.md | 52 ++ demo/fluidity/02_must.md | 58 ++ demo/fluidity/03_assert.md | 71 +++ demo/fluidity/04_other.md | 35 ++ demo/minitest/01_minitest_extensions.rdoc | 217 ++++++++ demo/minitest/02_minitest_assertions.rdoc | 250 +++++++++ demo/rspec/00_introduction.md | 16 + demo/rspec/01_should.md | 24 + demo/rspec/02_matchers.md | 176 +++++++ demo/rspec/03_have.md | 51 ++ demo/rspec/04_expect.md | 42 ++ demo/rspec/applique/setup.rb | 2 + demo/testunit/01_testunit_assertions.md | 266 ++++++++++ etc/qed.rb | 13 - lib/assay.rb | 28 +- lib/assay.yml | 1 - lib/assay/adapter/minitest.rb | 53 +- lib/assay/adapter/testunit.rb | 69 ++- lib/assay/assertable.rb | 6 +- lib/assay/close_assay.rb | 4 +- lib/assay/core_ext/kernel.rb | 12 +- lib/assay/fluidity.rb | 6 + lib/assay/fluidity/assert.rb | 27 + lib/assay/fluidity/grammar.rb | 140 +++++ lib/assay/fluidity/is.rb | 18 + lib/assay/fluidity/must.rb | 38 ++ lib/assay/fluidity/should.rb | 32 ++ lib/assay/fluidity/will.rb | 36 ++ lib/assay/less_assay.rb | 8 +- lib/assay/less_equal_assay.rb | 8 +- lib/assay/minitest.rb | 24 + lib/assay/minitest/assertions.rb | 495 +++++++++++++++++ lib/assay/minitest/extensions.rb | 496 ++++++++++++++++++ lib/assay/more_assay.rb | 8 +- lib/assay/more_equal_assay.rb | 8 +- lib/assay/rspec.rb | 13 + lib/assay/rspec/expect.rb | 151 ++++++ lib/assay/rspec/have.rb | 201 +++++++ lib/assay/rspec/matchers.rb | 272 ++++++++++ lib/assay/rspec/operatics.rb | 57 ++ lib/assay/rspec/should.rb | 49 ++ lib/assay/testunit.rb | 9 + lib/assay/testunit/assertions.rb | 484 +++++++++++++++++ lib/assay/version.rb | 3 + test/adapter/minitest_example.rb | 11 + test/adapter/testunit_example.rb | 10 + test/adapters.rb | 26 + test/case_instance_assay.rb | 10 +- test/case_kind_assay.rb | 2 +- test/case_raise_assay.rb | 8 +- try/qed/01_example.rdoc | 23 - try/testunit/example.rb | 13 - var/authors | 2 - var/copyrights | 2 - var/created | 1 - var/description | 3 - var/name | 1 - var/organizations | 2 - var/repositories | 3 - var/requirements | 8 - var/resources | 8 - var/summary | 1 - var/title | 1 - var/version | 1 - work/benchmarks/mem_method.rb | 18 - work/benchmarks/mem_object.rb | 18 - work/benchmarks/method_vs_object.rb | 23 - work/consider/approx.rb | 35 -- work/consider/operator.rb | 18 - work/consider/return_failure.rb | 136 ----- work/consider/sends.rb | 53 -- work/defunct/assertable_module/assertable.rb | 37 -- .../assertable_module/assertable/compare.rb | 22 - .../assertable_module/assertable/delta.rb | 23 - .../assertable_module/assertable/equality.rb | 27 - .../assertable_module/assertable/execution.rb | 27 - .../assertable_module/assertable/false.rb | 21 - .../assertable_module/assertable/identity.rb | 24 - .../assertable_module/assertable/instance.rb | 23 - .../assertable_module/assertable/kind.rb | 23 - .../assertable_module/assertable/match.rb | 23 - .../assertable_module/assertable/nil.rb | 22 - .../assertable_module/assertable/raises.rb | 25 - .../assertable_module/assertable/response.rb | 21 - .../assertable_module/assertable/returns.rb | 27 - .../assertable_module/assertable/same.rb | 27 - .../assertable_module/assertable/true.rb | 22 - .../assertable_module/assertions/compare.rb | 43 -- .../assertable_module/assertions/equal.rb | 51 -- .../assertable_module/assertions/execution.rb | 49 -- .../assertable_module/assertions/false.rb | 37 -- .../assertable_module/assertions/identity.rb | 40 -- .../assertable_module/assertions/in_delta.rb | 39 -- .../assertions/instance_of.rb | 39 -- .../assertable_module/assertions/kind_of.rb | 47 -- .../assertable_module/assertions/match.rb | 44 -- .../assertable_module/assertions/nil.rb | 40 -- .../assertable_module/assertions/operator.rb | 18 - .../assertable_module/assertions/raises.rb | 89 ---- .../assertions/respond_to.rb | 45 -- .../assertable_module/assertions/returns.rb | 83 --- .../assertable_module/assertions/same.rb | 43 -- .../assertable_module/assertions/sends.rb | 74 --- .../assertable_module/assertions/throws.rb | 108 ---- .../assertable_module/assertions/true.rb | 38 -- work/defunct/assertable_module/compare.rb | 43 -- .../nomenclature.rb | 83 --- .../nomenclature/assert.rb | 48 -- .../nomenclature/expect.rb | 42 -- .../nomenclature/must.rb | 36 -- .../nomenclature/shall.rb | 36 -- .../nomenclature/should.rb | 36 -- .../nomenclature/verify.rb | 40 -- .../nomenclature/will.rb | 42 -- work/defunct/object-assays/assay.rb | 71 --- work/defunct/object-assays/definitions.rb | 78 --- work/defunct/oldschool_extensions/is.rb | 35 -- work/defunct/oldschool_matchers/be.rb | 31 -- work/defunct/oldschool_matchers/is.rb | 31 -- .../assertive/legacy.rb | 349 ------------ .../static_assertion_methods/matchers/be.rb | 311 ----------- .../matchers/class.rb | 36 -- .../matchers/rspec.rb | 1 - .../static_assertion_methods/objective/is.rb | 350 ------------ .../objective/must.rb | 330 ------------ work/defunct/tobe.rb | 56 -- 181 files changed, 4270 insertions(+), 4554 deletions(-) delete mode 100644 .gemspec create mode 100644 .github/workflows/ci.yml delete mode 100644 .index delete mode 100644 .travis.yml delete mode 100644 Assembly delete mode 100644 MANIFEST create mode 100644 Rakefile create mode 100644 assay.gemspec rename demo/{ => core}/00_introduction.md (100%) rename demo/{ => core}/01_assay_classes/00_introduction.md (100%) rename demo/{ => core}/01_assay_classes/01_nil_assay.md (100%) rename demo/{ => core}/01_assay_classes/02_boolean_assay.md (100%) rename demo/{ => core}/01_assay_classes/03_false_assay.md (100%) rename demo/{ => core}/01_assay_classes/03_true_assay.md (100%) rename demo/{ => core}/01_assay_classes/04_like_assay.md (100%) rename demo/{ => core}/01_assay_classes/05_equal_assay.md (100%) rename demo/{ => core}/01_assay_classes/06_unequal_assay.md (100%) rename demo/{ => core}/01_assay_classes/07_equality_assay.md (100%) rename demo/{ => core}/01_assay_classes/08_identity_assay.md (100%) rename demo/{ => core}/01_assay_classes/09_case_assay.md (100%) rename demo/{ => core}/01_assay_classes/10_match_assay.md (100%) rename demo/{ => core}/01_assay_classes/11_nomatch_assay.md (100%) rename demo/{ => core}/01_assay_classes/12_compare_assay.md (100%) rename demo/{ => core}/01_assay_classes/13_less_assay.md (100%) rename demo/{ => core}/01_assay_classes/14_more_assay.md (100%) rename demo/{ => core}/01_assay_classes/15_less_equal_assay.md (100%) rename demo/{ => core}/01_assay_classes/16_more_equal_assay.md (100%) rename demo/{ => core}/01_assay_classes/17_close_assay.md (100%) rename demo/{ => core}/01_assay_classes/17_within_assay.md (100%) rename demo/{ => core}/01_assay_classes/18_kind_assay.md (77%) rename demo/{ => core}/01_assay_classes/19_instance_assay.md (77%) rename demo/{ => core}/01_assay_classes/20_include_assay.md (100%) rename demo/{ => core}/01_assay_classes/21_empty_assay.md (100%) rename demo/{ => core}/01_assay_classes/22_respond_assay.md (100%) rename demo/{ => core}/01_assay_classes/23_execution_assay.md (100%) rename demo/{ => core}/01_assay_classes/23_return_assay.md (100%) rename demo/{ => core}/01_assay_classes/24_rescue_assay.md (100%) rename demo/{ => core}/01_assay_classes/25_raise_assay.md (100%) rename demo/{ => core}/01_assay_classes/26_throw_assay.md (100%) rename demo/{ => core}/01_assay_classes/27_path_assay.md (100%) rename demo/{ => core}/01_assay_classes/28_directory_assay.md (100%) rename demo/{ => core}/01_assay_classes/29_file_assay.md (100%) rename demo/{ => core}/01_assay_classes/30_output_assay.md (100%) rename demo/{ => core}/01_assay_classes/31_stdout_assay.md (100%) rename demo/{ => core}/01_assay_classes/32_stderr_assay.md (100%) rename demo/{ => core}/02_lookup.md (100%) rename demo/{ => core}/03_assertor.md (100%) rename demo/{ => core}/04_assay.md (75%) create mode 100644 demo/fluidity/00_intro.md create mode 100644 demo/fluidity/01_should.md create mode 100644 demo/fluidity/02_must.md create mode 100644 demo/fluidity/03_assert.md create mode 100644 demo/fluidity/04_other.md create mode 100644 demo/minitest/01_minitest_extensions.rdoc create mode 100644 demo/minitest/02_minitest_assertions.rdoc create mode 100644 demo/rspec/00_introduction.md create mode 100644 demo/rspec/01_should.md create mode 100644 demo/rspec/02_matchers.md create mode 100644 demo/rspec/03_have.md create mode 100644 demo/rspec/04_expect.md create mode 100644 demo/rspec/applique/setup.rb create mode 100644 demo/testunit/01_testunit_assertions.md delete mode 100644 etc/qed.rb delete mode 120000 lib/assay.yml create mode 100644 lib/assay/fluidity.rb create mode 100644 lib/assay/fluidity/assert.rb create mode 100644 lib/assay/fluidity/grammar.rb create mode 100644 lib/assay/fluidity/is.rb create mode 100644 lib/assay/fluidity/must.rb create mode 100644 lib/assay/fluidity/should.rb create mode 100644 lib/assay/fluidity/will.rb create mode 100644 lib/assay/minitest.rb create mode 100644 lib/assay/minitest/assertions.rb create mode 100644 lib/assay/minitest/extensions.rb create mode 100644 lib/assay/rspec.rb create mode 100644 lib/assay/rspec/expect.rb create mode 100644 lib/assay/rspec/have.rb create mode 100644 lib/assay/rspec/matchers.rb create mode 100644 lib/assay/rspec/operatics.rb create mode 100644 lib/assay/rspec/should.rb create mode 100644 lib/assay/testunit.rb create mode 100644 lib/assay/testunit/assertions.rb create mode 100644 lib/assay/version.rb create mode 100644 test/adapter/minitest_example.rb create mode 100644 test/adapter/testunit_example.rb create mode 100644 test/adapters.rb delete mode 100644 try/qed/01_example.rdoc delete mode 100644 try/testunit/example.rb delete mode 100644 var/authors delete mode 100644 var/copyrights delete mode 100644 var/created delete mode 100644 var/description delete mode 100644 var/name delete mode 100644 var/organizations delete mode 100644 var/repositories delete mode 100644 var/requirements delete mode 100644 var/resources delete mode 100644 var/summary delete mode 100644 var/title delete mode 100644 var/version delete mode 100644 work/benchmarks/mem_method.rb delete mode 100644 work/benchmarks/mem_object.rb delete mode 100644 work/benchmarks/method_vs_object.rb delete mode 100644 work/consider/approx.rb delete mode 100644 work/consider/operator.rb delete mode 100644 work/consider/return_failure.rb delete mode 100644 work/consider/sends.rb delete mode 100644 work/defunct/assertable_module/assertable.rb delete mode 100644 work/defunct/assertable_module/assertable/compare.rb delete mode 100644 work/defunct/assertable_module/assertable/delta.rb delete mode 100644 work/defunct/assertable_module/assertable/equality.rb delete mode 100644 work/defunct/assertable_module/assertable/execution.rb delete mode 100644 work/defunct/assertable_module/assertable/false.rb delete mode 100644 work/defunct/assertable_module/assertable/identity.rb delete mode 100644 work/defunct/assertable_module/assertable/instance.rb delete mode 100644 work/defunct/assertable_module/assertable/kind.rb delete mode 100644 work/defunct/assertable_module/assertable/match.rb delete mode 100644 work/defunct/assertable_module/assertable/nil.rb delete mode 100644 work/defunct/assertable_module/assertable/raises.rb delete mode 100644 work/defunct/assertable_module/assertable/response.rb delete mode 100644 work/defunct/assertable_module/assertable/returns.rb delete mode 100644 work/defunct/assertable_module/assertable/same.rb delete mode 100644 work/defunct/assertable_module/assertable/true.rb delete mode 100644 work/defunct/assertable_module/assertions/compare.rb delete mode 100644 work/defunct/assertable_module/assertions/equal.rb delete mode 100644 work/defunct/assertable_module/assertions/execution.rb delete mode 100644 work/defunct/assertable_module/assertions/false.rb delete mode 100644 work/defunct/assertable_module/assertions/identity.rb delete mode 100644 work/defunct/assertable_module/assertions/in_delta.rb delete mode 100644 work/defunct/assertable_module/assertions/instance_of.rb delete mode 100644 work/defunct/assertable_module/assertions/kind_of.rb delete mode 100644 work/defunct/assertable_module/assertions/match.rb delete mode 100644 work/defunct/assertable_module/assertions/nil.rb delete mode 100644 work/defunct/assertable_module/assertions/operator.rb delete mode 100644 work/defunct/assertable_module/assertions/raises.rb delete mode 100644 work/defunct/assertable_module/assertions/respond_to.rb delete mode 100644 work/defunct/assertable_module/assertions/returns.rb delete mode 100644 work/defunct/assertable_module/assertions/same.rb delete mode 100644 work/defunct/assertable_module/assertions/sends.rb delete mode 100644 work/defunct/assertable_module/assertions/throws.rb delete mode 100644 work/defunct/assertable_module/assertions/true.rb delete mode 100644 work/defunct/assertable_module/compare.rb delete mode 100644 work/defunct/complex_nomenclature_system/nomenclature.rb delete mode 100644 work/defunct/complex_nomenclature_system/nomenclature/assert.rb delete mode 100644 work/defunct/complex_nomenclature_system/nomenclature/expect.rb delete mode 100644 work/defunct/complex_nomenclature_system/nomenclature/must.rb delete mode 100644 work/defunct/complex_nomenclature_system/nomenclature/shall.rb delete mode 100644 work/defunct/complex_nomenclature_system/nomenclature/should.rb delete mode 100644 work/defunct/complex_nomenclature_system/nomenclature/verify.rb delete mode 100644 work/defunct/complex_nomenclature_system/nomenclature/will.rb delete mode 100644 work/defunct/object-assays/assay.rb delete mode 100644 work/defunct/object-assays/definitions.rb delete mode 100644 work/defunct/oldschool_extensions/is.rb delete mode 100644 work/defunct/oldschool_matchers/be.rb delete mode 100644 work/defunct/oldschool_matchers/is.rb delete mode 100644 work/defunct/static_assertion_methods/assertive/legacy.rb delete mode 100644 work/defunct/static_assertion_methods/matchers/be.rb delete mode 100644 work/defunct/static_assertion_methods/matchers/class.rb delete mode 100644 work/defunct/static_assertion_methods/matchers/rspec.rb delete mode 100644 work/defunct/static_assertion_methods/objective/is.rb delete mode 100644 work/defunct/static_assertion_methods/objective/must.rb delete mode 100644 work/defunct/tobe.rb diff --git a/.gemspec b/.gemspec deleted file mode 100644 index ea0db60..0000000 --- a/.gemspec +++ /dev/null @@ -1,307 +0,0 @@ -# encoding: utf-8 - -require 'yaml' -require 'pathname' - -module Indexer - - # Convert index data into a gemspec. - # - # Notes: - # * Assumes all executables are in bin/. - # * Does not yet handle default_executable setting. - # * Does not yet handle platform setting. - # * Does not yet handle required_ruby_version. - # * Support for rdoc entries is weak. - # - class GemspecExporter - - # File globs to include in package --unless a manifest file exists. - FILES = ".index .yardopts alt bin data demo ext features lib man spec test try* [A-Z]*.*" unless defined?(FILES) - - # File globs to omit from FILES. - OMIT = "Config.rb" unless defined?(OMIT) - - # Standard file patterns. - PATTERNS = { - :root => '{.index,Gemfile}', - :bin => 'bin/*', - :lib => 'lib/{**/}*', #.rb', - :ext => 'ext/{**/}extconf.rb', - :doc => '*.{txt,rdoc,md,markdown,tt,textile}', - :test => '{test,spec}/{**/}*.rb' - } unless defined?(PATTERNS) - - # For which revision of indexer spec is this converter intended? - REVISION = 2013 unless defined?(REVISION) - - # - def self.gemspec - new.to_gemspec - end - - # - attr :metadata - - # - def initialize(metadata=nil) - @root_check = false - - if metadata - root_dir = metadata.delete(:root) - if root_dir - @root = root_dir - @root_check = true - end - metadata = nil if metadata.empty? - end - - @metadata = metadata || YAML.load_file(root + '.index') - - if @metadata['revision'].to_i != REVISION - warn "This gemspec exporter was not designed for this revision of index metadata." - end - end - - # - def has_root? - root ? true : false - end - - # - def root - return @root if @root || @root_check - @root_check = true - @root = find_root - end - - # - def manifest - return nil unless root - @manifest ||= Dir.glob(root + 'manifest{,.txt}', File::FNM_CASEFOLD).first - end - - # - def scm - return nil unless root - @scm ||= %w{git hg}.find{ |m| (root + ".#{m}").directory? }.to_sym - end - - # - def files - return [] unless root - @files ||= \ - if manifest - File.readlines(manifest). - map{ |line| line.strip }. - reject{ |line| line.empty? || line[0,1] == '#' } - else - list = [] - Dir.chdir(root) do - FILES.split(/\s+/).each do |pattern| - list.concat(glob(pattern)) - end - OMIT.split(/\s+/).each do |pattern| - list = list - glob(pattern) - end - end - list - end.select{ |path| File.file?(path) }.uniq - end - - # - def glob_files(pattern) - return [] unless root - Dir.chdir(root) do - Dir.glob(pattern).select do |path| - File.file?(path) && files.include?(path) - end - end - end - - def patterns - PATTERNS - end - - def executables - @executables ||= \ - glob_files(patterns[:bin]).map do |path| - File.basename(path) - end - end - - def extensions - @extensions ||= \ - glob_files(patterns[:ext]).map do |path| - File.basename(path) - end - end - - def name - metadata['name'] || metadata['title'].downcase.gsub(/\W+/,'_') - end - - def homepage - page = ( - metadata['resources'].find{ |r| r['type'] =~ /^home/i } || - metadata['resources'].find{ |r| r['name'] =~ /^home/i } || - metadata['resources'].find{ |r| r['name'] =~ /^web/i } - ) - page ? page['uri'] : false - end - - def licenses - metadata['copyrights'].map{ |c| c['license'] }.compact - end - - def require_paths - paths = metadata['paths'] || {} - paths['load'] || ['lib'] - end - - # - # Convert to gemnspec. - # - def to_gemspec - if has_root? - Gem::Specification.new do |gemspec| - to_gemspec_data(gemspec) - to_gemspec_paths(gemspec) - end - else - Gem::Specification.new do |gemspec| - to_gemspec_data(gemspec) - to_gemspec_paths(gemspec) - end - end - end - - # - # Convert pure data settings. - # - def to_gemspec_data(gemspec) - gemspec.name = name - gemspec.version = metadata['version'] - gemspec.summary = metadata['summary'] - gemspec.description = metadata['description'] - - metadata['authors'].each do |author| - gemspec.authors << author['name'] - - if author.has_key?('email') - if gemspec.email - gemspec.email << author['email'] - else - gemspec.email = [author['email']] - end - end - end - - gemspec.licenses = licenses - - requirements = metadata['requirements'] || [] - requirements.each do |req| - next if req['optional'] - next if req['external'] - - name = req['name'] - groups = req['groups'] || [] - - version = gemify_version(req['version']) - - if groups.empty? or groups.include?('runtime') - # populate runtime dependencies - if gemspec.respond_to?(:add_runtime_dependency) - gemspec.add_runtime_dependency(name,*version) - else - gemspec.add_dependency(name,*version) - end - else - # populate development dependencies - if gemspec.respond_to?(:add_development_dependency) - gemspec.add_development_dependency(name,*version) - else - gemspec.add_dependency(name,*version) - end - end - end - - # convert external dependencies into gemspec requirements - requirements.each do |req| - next unless req['external'] - gemspec.requirements << ("%s-%s" % req.values_at('name', 'version')) - end - - gemspec.homepage = homepage - gemspec.require_paths = require_paths - gemspec.post_install_message = metadata['install_message'] - end - - # - # Set gemspec settings that require a root directory path. - # - def to_gemspec_paths(gemspec) - gemspec.files = files - gemspec.extensions = extensions - gemspec.executables = executables - - if Gem::VERSION < '1.7.' - gemspec.default_executable = gemspec.executables.first - end - - gemspec.test_files = glob_files(patterns[:test]) - - unless gemspec.files.include?('.document') - gemspec.extra_rdoc_files = glob_files(patterns[:doc]) - end - end - - # - # Return a copy of this file. This is used to generate a local - # .gemspec file that can automatically read the index file. - # - def self.source_code - File.read(__FILE__) - end - - private - - def find_root - root_files = patterns[:root] - if Dir.glob(root_files).first - Pathname.new(Dir.pwd) - elsif Dir.glob("../#{root_files}").first - Pathname.new(Dir.pwd).parent - else - #raise "Can't find root of project containing `#{root_files}'." - warn "Can't find root of project containing `#{root_files}'." - nil - end - end - - def glob(pattern) - if File.directory?(pattern) - Dir.glob(File.join(pattern, '**', '*')) - else - Dir.glob(pattern) - end - end - - def gemify_version(version) - case version - when /^(.*?)\+$/ - ">= #{$1}" - when /^(.*?)\-$/ - "< #{$1}" - when /^(.*?)\~$/ - "~> #{$1}" - else - version - end - end - - end - -end - -Indexer::GemspecExporter.gemspec \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e340ff6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +name: CI + +on: + push: + pull_request: + workflow_dispatch: + # Monthly, to catch breakage from new Ruby, Minitest or Test::Unit + # releases when nothing has been pushed. + schedule: + - cron: '0 6 1 * *' + +permissions: + contents: read + +jobs: + test: + name: Ruby ${{ matrix.ruby }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: ['2.7', '3.0', '3.1', '3.2', '3.3', '3.4', '4.0'] + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Demos, unit tests and adapters + run: bundle exec rake diff --git a/.gitignore b/.gitignore index fee1bd9..3e602d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,7 @@ -.fire/digest .yardoc doc log pkg -site tmp -web -wiki -work/trash -DEMO.md +*.gem +Gemfile.lock diff --git a/.index b/.index deleted file mode 100644 index 5abed1e..0000000 --- a/.index +++ /dev/null @@ -1,74 +0,0 @@ ---- -revision: 2013 -type: ruby -sources: -- var -authors: -- name: Trans - email: transfire@gmail.com -organizations: -- name: Rubyworks -requirements: -- name: ansi -- name: brass -- groups: - - build - development: true - name: detroit -- groups: - - build - development: true - name: ergo -- groups: - - test - development: true - name: qed -- groups: - - test - development: true - name: ae -conflicts: [] -alternatives: [] -resources: -- type: home - uri: http://rubyworks.github.com/assay - label: Homepage -- type: docs - uri: http://rubydoc.info/gems/assay/frames - label: Documentation -- type: code - uri: http://github.com/rubyworks/assay - label: Source Code -- type: bugs - uri: http://github.com/rubyworks/assay/issues - label: Issue Tracker -- type: chat - uri: http://chat.us.freenode.net/rubyworks - label: IRC Channel -- type: mail - uri: http://groups.google.com/groups/rubyworks-mailinglist - label: Mailing List -repositories: -- name: upstream - scm: git - uri: git@github.com:rubyworks/assay.git -categories: [] -copyrights: -- holder: Rubyworks - year: '2010' - license: BSD-2-Clause -customs: [] -paths: - lib: - - lib -created: '2010-11-14' -summary: Class-based Assertions Framework -title: Assay -version: 0.4.1 -name: assay -description: ! 'Assay defines assertions in the same way that Ruby defines exceptions. - - Each type of asserition, called an assay, is then a child of the base - - Assertion class, which itself is a subclass of the Exception class.' -date: '2013-03-09' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e71ca5b..0000000 --- a/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- -language: ruby -script: "bundle exec qed" -rvm: - - 1.9.2 - - 1.9.3 - - rbx-19mode - - jruby-19mode - diff --git a/.yardopts b/.yardopts index dedc60c..b26ef15 100644 --- a/.yardopts +++ b/.yardopts @@ -1,5 +1,5 @@ --title "Assay" ---readme README.rdoc +--readme README.md --protected --private lib diff --git a/Assembly b/Assembly deleted file mode 100644 index 0ac6b02..0000000 --- a/Assembly +++ /dev/null @@ -1,40 +0,0 @@ ---- -github: - gh_pages: web - -gem: - active: true - -dnote: - title: Source Notes - output: log/notes.html - -vclog: - output: - - log/history.html - - log/changes.html - -email: - mailto: - - ruby-talk@ruby-lang.org - - rubyworks-mailinglist@googlegroups.com - -qed: - files: demo/ - -qedoc: - files: demo/ - output: - - DEMO.md - - web/demos.html - -# OMG! Look at this old thing! -#rubyforge: -# service : Rubyforge -# unixname: <= suite %> -# groupid : ~ -# package : <= name %> -# sitemap: -# doc/rdoc: <= name %> -# active : false - diff --git a/Gemfile b/Gemfile index e45e65f..851fabc 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,2 @@ -source :rubygems +source 'https://rubygems.org' gemspec diff --git a/HISTORY.md b/HISTORY.md index bac7c6f..253a690 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,50 @@ # HISTORY +## Unreleased + +Assay is one library again. The notations that were spun off as separate +gems in 0.4 (Fluidity, RSpecial, Assay MiniTest and Assay TestUnit) are +back, each loaded on its own. Assay needs Ruby 2.7 or newer. + +Changes: + +* Add `assay/fluidity`, the fluent notation (`x.should.equal y`), from + the Fluidity gem. Its module is `Assay::Fluidity`. +* Add `assay/rspec`, RSpec-style matchers and `expect`, from the RSpecial + gem. Its module is `Assay::RSpec`. +* Add `assay/minitest` and `assay/testunit`, the assertion methods of + those frameworks, from the Assay MiniTest and Assay TestUnit gems. +* Rewrite the Minitest and Test::Unit adapters for Minitest 5 and 6 and + for test-unit 3. The old ones patched classes those frameworks no + longer have. +* `expect` takes a block: `expect{ ... }.to raise_error(ArgumentError)`. +* Fix `assert(false)` passing silently once `assay/fluidity/assert` was + loaded. Worse, Assay itself called that `assert`, so no assay could + fail either. +* Fix the fluent fallback to an object's own query method ignoring + negation: `x.should_not.be.no` now fails when `x.no?` is true. +* Fix `will_not` and `wont`. They were never defined, and loading the + `will` notation raised NameError. +* Fix `assert_in_epsilon` and `assert_not_in_epsilon` in the Test::Unit + notation, which raised NameError. +* Fix `CloseAssay` for a negative criterion, and its message for long + values. +* Give `LessAssay`, `LessEqualAssay`, `MoreAssay` and `MoreEqualAssay` + messages of their own (`5 <= 3`). They said `5 <=> 3 == 0`. +* `Kernel#like?` no longer tries `=~`, which Ruby 3.2 removed from + Object. It is now the same as Facets' `like?`. +* An operator with no assay of its own, used with `expect(x).to`, is + sent to the object and fails with an Assertion. It raised an + unrelated error. +* Assay's failures no longer depend on which `assert` method is in + scope: it calls BRASS's directly. +* `Assay::VERSION` gives the version. `Assay.metadata`, and the + constants made from it, are gone. +* Replace the old packaging (`.index`, `.gemspec`, `Assembly`, + `MANIFEST`) with a plain `assay.gemspec`, and Travis with GitHub + Actions, testing Ruby 2.7 to 4.0. + + ## 0.4.1 | 2012-01-27 This release adds CloseAssay for relative approxmation assertions on values, diff --git a/MANIFEST b/MANIFEST deleted file mode 100644 index f95eaac..0000000 --- a/MANIFEST +++ /dev/null @@ -1,117 +0,0 @@ -#!mast .index bin demo lib spec test [A-Z][A-Z]* -.index -demo/00_introduction.md -demo/01_assay_classes/00_introduction.md -demo/01_assay_classes/01_nil_assay.md -demo/01_assay_classes/02_boolean_assay.md -demo/01_assay_classes/03_false_assay.md -demo/01_assay_classes/03_true_assay.md -demo/01_assay_classes/04_like_assay.md -demo/01_assay_classes/05_equal_assay.md -demo/01_assay_classes/06_unequal_assay.md -demo/01_assay_classes/07_equality_assay.md -demo/01_assay_classes/08_identity_assay.md -demo/01_assay_classes/09_case_assay.md -demo/01_assay_classes/10_match_assay.md -demo/01_assay_classes/11_nomatch_assay.md -demo/01_assay_classes/12_compare_assay.md -demo/01_assay_classes/13_less_assay.md -demo/01_assay_classes/14_more_assay.md -demo/01_assay_classes/15_less_equal_assay.md -demo/01_assay_classes/16_more_equal_assay.md -demo/01_assay_classes/17_close_assay.md -demo/01_assay_classes/17_within_assay.md -demo/01_assay_classes/18_kind_assay.md -demo/01_assay_classes/19_instance_assay.md -demo/01_assay_classes/20_include_assay.md -demo/01_assay_classes/21_empty_assay.md -demo/01_assay_classes/22_respond_assay.md -demo/01_assay_classes/23_execution_assay.md -demo/01_assay_classes/23_return_assay.md -demo/01_assay_classes/24_rescue_assay.md -demo/01_assay_classes/25_raise_assay.md -demo/01_assay_classes/26_throw_assay.md -demo/01_assay_classes/27_path_assay.md -demo/01_assay_classes/28_directory_assay.md -demo/01_assay_classes/29_file_assay.md -demo/01_assay_classes/30_output_assay.md -demo/01_assay_classes/31_stdout_assay.md -demo/01_assay_classes/32_stderr_assay.md -demo/02_lookup.md -demo/03_assertor.md -demo/04_assay.md -demo/applique/helper.rb -demo/applique/setup.rb -lib/assay/adapter/minitest.rb -lib/assay/adapter/testunit.rb -lib/assay/assertable.rb -lib/assay/assertion.rb -lib/assay/assertor.rb -lib/assay/boolean_assay.rb -lib/assay/case_assay.rb -lib/assay/close_assay.rb -lib/assay/compare_assay.rb -lib/assay/core_ext/kernel.rb -lib/assay/core_ext/na.rb -lib/assay/directory_assay.rb -lib/assay/empty_assay.rb -lib/assay/equal_assay.rb -lib/assay/equality_assay.rb -lib/assay/execution_assay.rb -lib/assay/false_assay.rb -lib/assay/file_assay.rb -lib/assay/identity_assay.rb -lib/assay/include_assay.rb -lib/assay/instance_assay.rb -lib/assay/kind_assay.rb -lib/assay/less_assay.rb -lib/assay/less_equal_assay.rb -lib/assay/like_assay.rb -lib/assay/match_assay.rb -lib/assay/more_assay.rb -lib/assay/more_equal_assay.rb -lib/assay/nil_assay.rb -lib/assay/nomatch_assay.rb -lib/assay/output_assay.rb -lib/assay/path_assay.rb -lib/assay/raise_assay.rb -lib/assay/rescue_assay.rb -lib/assay/respond_assay.rb -lib/assay/return_assay.rb -lib/assay/silent_assay.rb -lib/assay/stderr_assay.rb -lib/assay/stdout_assay.rb -lib/assay/throw_assay.rb -lib/assay/true_assay.rb -lib/assay/unequal_assay.rb -lib/assay/within_assay.rb -lib/assay.rb -lib/assay.yml -test/case_compare_assay.rb -test/case_empty_assay.rb -test/case_equal_assay.rb -test/case_equality_assay.rb -test/case_false_assay.rb -test/case_identity_assay.rb -test/case_include_assay.rb -test/case_instance_assay.rb -test/case_kind_assay.rb -test/case_less_assay.rb -test/case_less_equal_assay.rb -test/case_like_assay.rb -test/case_match_assay.rb -test/case_more_assay.rb -test/case_more_equal_assay.rb -test/case_nil_assay.rb -test/case_nomatch_assay.rb -test/case_raise_assay.rb -test/case_respond_assay.rb -test/case_throw_assay.rb -test/case_true_assay.rb -test/case_unequal_assay.rb -test/case_within_assay.rb -test/helper.rb -LICENSE.txt -HISTORY.md -README.md -DEMO.md diff --git a/README.md b/README.md index 994369d..c94ee99 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,50 @@ # Assay -[Website](http://rubyworks.github.com/assay) / -[Documentation](http://rubydoc.info/gems/assay) / -[Report Issue](http://github.com/rubyworks/assay/issues) / -[Source Code](http://github.com/rubyworks/assay) +[Documentation](https://rubydoc.info/gems/assay) / +[Report Issue](https://github.com/rubyworks/assay/issues) / +[Source Code](https://github.com/rubyworks/assay) -[![Gem Version](https://badge.fury.io/rb/assay.png)](http://badge.fury.io/rb/assay) -[![Build Status](https://secure.travis-ci.org/rubyworks/assay.png)](http://travis-ci.org/rubyworks/assay)     -[![Flattr Me](http://api.flattr.com/button/flattr-badge-large.png)](http://flattr.com/thing/324911/Rubyworks-Ruby-Development-Fund) +[![Gem Version](https://badge.fury.io/rb/assay.svg)](https://badge.fury.io/rb/assay) +[![CI](https://github.com/rubyworks/assay/actions/workflows/ci.yml/badge.svg)](https://github.com/rubyworks/assay/actions/workflows/ci.yml) ## DESCRIPTION Assay defines assertions in the same way that Ruby defines -exceptions. An assertion then is nothing more that an -extended Exception class. Assay provides a complete set -of these assertion classes for the most common assertion types. -It also provides both TestUnit-style assertion methods and -RSpec-compatiable matchers built from these assertion classes -for use in your preferred test harness. Assay is compatible with -TestUnit, MiniTest, RSpec and other test frameworks. +exceptions. Each kind of assertion is a class: it knows how to test, +how to explain a failure, and it is the exception raised when the +assertion fails. Assay provides a complete set of these classes for +the common kinds of assertion. +On top of the classes Assay provides a choice of notations for writing +assertions, each loaded on its own: -## FEATURES +| Require | Notation | +|---|---| +| `assay/minitest` | Minitest's `assert_equal` and `must_equal` | +| `assay/testunit` | Test::Unit's `assert_equal` | +| `assay/rspec` | RSpec's `should eq` and `expect(x).to eq` | +| `assay/fluidity` | Assay's own: `x.should.equal y`, `x.assert == y` | -* Patterned after the Ruby exception system. -* Allows assertions specialized error messages. -* Supports any variety of assertion "grammers". -* Can be used with almost any test framework. +Whichever you choose, a failure is an instance of the same assay class, +and any test framework that follows the +[BRASS](https://github.com/rubyworks/brass) standard counts it as a +failed assertion. -## LIMITATIONS +## FEATURES -* Assay is Ruby 1.9+ only! +* Patterned after the Ruby exception system. +* A failed assertion has a type, and an error message to suit it. +* Supports any variety of assertion notation. +* Can be used with almost any test framework. ## INSTALLATION -To install with RubyGems simply open a console and type: - $ gem install assay -Site installation with the tarball can be done with Ruby Setup -(gem install setup). See http://rubyworks.github.com/setup. +Assay needs Ruby 2.7 or newer. ## UTILIZATION @@ -50,128 +52,167 @@ Site installation with the tarball can be done with Ruby Setup ### Assay Classes Assay consists of a set of Assertion subclasses known as *assays*. They -are akin to Ruby's Exception subclasses, indeed the +Assertion+ base class +are akin to Ruby's Exception subclasses, indeed the `Assertion` base class is a subclass of Exception. But assays have special class methods that are used to make assertions. -Consider the +EqualityAssay+ class. It defines methods for asserting equality +Consider the `EqualAssay` class. It defines methods for asserting equality via the `#==` method. - EqualityAssay.assert!(1,1) + EqualAssay.assert!(1,1) Additionally, we can check the assertion's test without actually raising the assertion if it fails using the query method. - EqualityAssay.pass?(1,1) #=> true + EqualAssay.pass?(1,1) #=> true Assays also provide the opposite method `#refute!` along with `#fail?`. - EqualityAssay.refute!(1,2) + EqualAssay.refute!(1,2) - EqualityAssay.fail?(1,2) #=> true + EqualAssay.fail?(1,2) #=> true Assay instances are test matchers, which can be conveniently defined with `#[]`. - EqualityAssay[1] =~ 1 + EqualAssay[1] =~ 1 Notice in the example we have used `#=~` to apply the matcher which makes the `#assert!` call to the Assay object. Likewise `#!~` can be used to call `#refute!` instead. And note that `#===` is also an alias for `#=~`. - EqualityAssay[1] === 1 + EqualAssay[1] === 1 -Which means assay matchers can be used in case statments. +Which means assay matchers can be used in case statements. case 10 - when InstanceAssay[Fixnum] - when EqualityAssay[10.0] + when InstanceAssay[Integer] + when EqualAssay[10.0] end Pretty neat. -### Framework Adapters +### Notations -Assay follows a standard practice of defining assertion error classes with -an `#assertion?` method that returns +true+. This can be used by any test -framework to easily detect when a raised error is an assertion rather than -an ordinary error. To add support for this to common test frameworks Assay -provides adapters. +The classes make a sound foundation, but in the end we want to write +assertions easily and concisely. Each notation is a thin layer over the +assay classes, and is loaded only when asked for. -For example, to use assay with MiniTest framework add to your test helper -script: +#### Fluidity - require 'assay/adapter/minitest' +Assay's own notation reads as a chain of words off the object under test. -Likewise for TestUnit. + require 'assay/fluidity' - require 'assay/adapter/testunit' + 10.should.be.kind_of(Integer) + 10.should_not.equal(20) -An RSpec adadpter is in the works, and should be out with the next release. +If you are accustomed to Minitest's spec methods, you might prefer `must`. -Note that even without the adapter, you can still use Assay with other test -frameworks. They will simply count Assay's assertions as regular errors. + 10.must.be.kind_of(Integer) -### Customized Grammars +And to satisfy the technical aficionados there is `assert`. -Of course the classes are interesting and clearly make for a sound foundation, -but in the end we want to write assertions more easily and concisely. For this -we turn to separate "grammar" projects that depend on Assay's classes. The -first of these, created as a spin-off project to demonstrate Assay's prowess, -is {Fluidity}[http://rubyworks.github.com/fluidity]. Here is a quick taste of -that gem's functionality. + 10.assert.kind_of(Integer) + 10.assert == 10 - require 'fluidity' +`assay/fluidity` loads `should`, `must` and `assert`. Each can be loaded +alone (`assay/fluidity/should`), and `is` and `will` are available the +same way (`assay/fluidity/is`, `assay/fluidity/will`). - 10.should.be.kind_of(Integer) +#### RSpec -But is you are acustom to MiniTest's spec methods, you might prefer `must`. + require 'assay/rspec' - 10.must.be.kind_of(Integer) + include Assay::Matchers -And to satisfy all those technical aficionados (like yours truly) there is `assert`. + 10.should be_kind_of(Integer) - 10.assert.kind_of(Integer) + expect(10).to eq(10) + expect{ raise ArgumentError }.to raise_error(ArgumentError) -Thre are also compatibility grammar projects available, spun-off from Assay, that -provide compatability with legacy test frameworks which can serve as transition -to Assay from these other frameworks. Follow the links below for each: +#### Minitest -* [Assay TestUnit](http://github.com/rubyworks/assay-testunit) -* [Assay MiniTest](http://github.com/rubyworks/assay-minitest) -* [RSpecial](http://github.com/rubyworks/rspecial) + require 'assay/minitest' -Usage is essentially the same for any one of them. For example, + include Assay::Assertions - require 'assay/rspec' + assert_equal 10, 5 + 5 + assert_kind_of Integer, 10 - include Assay::Matchers + 10.must_equal 5 + 5 - 10.should be_kind_of(Integer) +#### Test::Unit -Note that the compatibility modules are not yet 100% compatable, lacking some -of the more esoteric and complex features. But they are very nearly so, and -will become more so in time. + require 'assay/testunit' -These are just a few possible grammars. There is no reason not to build -your own grammar on top of Assay's classes if you have another approach in mind. -Indeed, please do! That, after all, is the main purpose of having such -a set of reusable assertion classes! + include Assay::Assertions + + assert_equal 10, 5 + 5 + assert_not_equal 10, 6 + 5 + +The three compatibility notations make it possible to move tests to +another framework without rewriting their assertions. They cover the +commonly used parts of each framework's API, not all of it. + +These are just a few possible notations. There is no reason not to build +your own on top of Assay's classes if you have another approach in mind. +That, after all, is the purpose of having a set of reusable assertion +classes. Assay classes can be looked up by operator or by name, which +makes this easy: + + Assay.lookup(:==) #=> EqualAssay + Assay.lookup(:empty?) #=> EmptyAssay + +### Framework Adapters + +Assay follows the BRASS standard: its assertion classes have an +`#assertion?` method that returns `true`, by which a test framework can +tell a failed assertion from an ordinary error. +[Rubytest](https://github.com/rubyworks/rubytest) and the frameworks +built on it do this already. For Minitest and Test::Unit, which don't, +Assay provides adapters. Add one to your test helper: + + require 'assay/adapter/minitest' + +or + + require 'assay/adapter/testunit' + +Without the adapter you can still use Assay with these frameworks. They +will count Assay's failed assertions as errors rather than failures. + +RSpec has no adapter. It reports any exception raised in an example as +a failure of that example, so Assay works in it as is. + +### Upgrading from 0.4 + +Since version 0.5 the notations are part of Assay again. The separate +gems are retired: + +| Before | Now | +|---|---| +| gem `fluidity`, `require 'fluidity'` | `require 'assay/fluidity'` | +| gem `rspecial`, `require 'rspecial'` | `require 'assay/rspec'` | +| gem `assay-minitest` | `require 'assay/minitest'` | +| gem `assay-testunit` | `require 'assay/testunit'` | + +`Fluidity` is now `Assay::Fluidity`, and `RSpecial` is `Assay::RSpec`. +`Assay::Assertions`, `Assay::Matchers` and `Assay::Extensions` are as +they were. ### Learning More -There's more learn about Assay, mainly the variety of assay classes available, -but also a few other bits of functionality not comvered here. To learn -about these check out the {QED documentation}[http://github.com/rubyworks/assay] -which provides an overiew of functionality with working examples, and the -the {API documentation}[http://rubydoc.info/gems/asasy] for a more in depth look -under the hood. +There is more to learn about Assay, mainly the variety of assay classes +available. The [demos](https://github.com/rubyworks/assay/tree/master/demo) +give an overview with working examples: they are run as tests with +[QED](https://github.com/rubyworks/qed). The +[API documentation](https://rubydoc.info/gems/assay) has the rest. ## LICENSE & COPYRIGHT Copyright (c) 2010 Rubyworks -This program is ditributed under the terms of the *BSD-2-Cluase* license. - -See LICENSE.txtfile for details. +This program is distributed under the terms of the *BSD-2-Clause* license. +See LICENSE.txt file for details. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..53f1a21 --- /dev/null +++ b/Rakefile @@ -0,0 +1,31 @@ +require 'rubygems/package_task' + +gemspec = Gem::Specification.load('assay.gemspec') + +Gem::PackageTask.new(gemspec) do |pkg| + pkg.need_zip = false + pkg.need_tar = false +end + +# Each notation extends Object in its own way, so each set of demos runs +# in a process of its own. +DEMOS = %w[core minitest testunit rspec fluidity] + +desc "Run the QED demos" +task :demo do + DEMOS.each do |set| + sh "bundle exec qed -Ilib demo/#{set}" + end +end + +desc "Run the unit tests" +task :test do + sh 'bundle exec rubytest -Ilib -r ./test/helper test/case_*.rb' +end + +desc "Check the framework adapters" +task :adapters do + sh 'bundle exec ruby -Ilib test/adapters.rb' +end + +task :default => [:demo, :test, :adapters] diff --git a/assay.gemspec b/assay.gemspec new file mode 100644 index 0000000..3dd904a --- /dev/null +++ b/assay.gemspec @@ -0,0 +1,39 @@ +require_relative 'lib/assay/version' + +Gem::Specification.new do |s| + s.name = 'assay' + s.version = Assay::VERSION + s.summary = 'Class-based assertions, and the notations built on them' + s.description = 'Assay defines assertions the way Ruby defines exceptions: each kind of ' \ + 'assertion is a class, which knows how to test, how to explain a failure, and ' \ + 'is the exception raised. On top of the classes it provides a choice of ' \ + 'notations: Minitest and Test::Unit style assertion methods, RSpec style ' \ + 'matchers, and a fluent notation of its own.' + + s.authors = ['Thomas Sawyer'] + s.email = ['transfire@gmail.com'] + + s.homepage = 'https://github.com/rubyworks/assay' + s.license = 'BSD-2-Clause' + + s.metadata = { + 'source_code_uri' => 'https://github.com/rubyworks/assay', + 'changelog_uri' => 'https://github.com/rubyworks/assay/blob/master/HISTORY.md', + 'bug_tracker_uri' => 'https://github.com/rubyworks/assay/issues' + } + + s.required_ruby_version = '>= 2.7' + + s.files = Dir['lib/**/*.rb', 'demo/**/*', 'LICENSE.txt', 'README.md', 'HISTORY.md', '.yardopts'] + s.require_paths = ['lib'] + + s.add_dependency 'brass', '>= 1.2' + s.add_dependency 'ansi', '>= 1.5' + + s.add_development_dependency 'rake', '>= 13' + s.add_development_dependency 'qed', '>= 2.9' + s.add_development_dependency 'rubytest', '>= 0.11.1' + s.add_development_dependency 'lemon', '>= 0.9' + s.add_development_dependency 'minitest', '>= 5.0' + s.add_development_dependency 'test-unit', '>= 3.0' +end diff --git a/demo/applique/helper.rb b/demo/applique/helper.rb index 5fc1972..d4693bd 100644 --- a/demo/applique/helper.rb +++ b/demo/applique/helper.rb @@ -28,6 +28,8 @@ def expect(error) end end +alias assert_raises expect + def increment_counts(which) case which when :pass diff --git a/demo/00_introduction.md b/demo/core/00_introduction.md similarity index 100% rename from demo/00_introduction.md rename to demo/core/00_introduction.md diff --git a/demo/01_assay_classes/00_introduction.md b/demo/core/01_assay_classes/00_introduction.md similarity index 100% rename from demo/01_assay_classes/00_introduction.md rename to demo/core/01_assay_classes/00_introduction.md diff --git a/demo/01_assay_classes/01_nil_assay.md b/demo/core/01_assay_classes/01_nil_assay.md similarity index 100% rename from demo/01_assay_classes/01_nil_assay.md rename to demo/core/01_assay_classes/01_nil_assay.md diff --git a/demo/01_assay_classes/02_boolean_assay.md b/demo/core/01_assay_classes/02_boolean_assay.md similarity index 100% rename from demo/01_assay_classes/02_boolean_assay.md rename to demo/core/01_assay_classes/02_boolean_assay.md diff --git a/demo/01_assay_classes/03_false_assay.md b/demo/core/01_assay_classes/03_false_assay.md similarity index 100% rename from demo/01_assay_classes/03_false_assay.md rename to demo/core/01_assay_classes/03_false_assay.md diff --git a/demo/01_assay_classes/03_true_assay.md b/demo/core/01_assay_classes/03_true_assay.md similarity index 100% rename from demo/01_assay_classes/03_true_assay.md rename to demo/core/01_assay_classes/03_true_assay.md diff --git a/demo/01_assay_classes/04_like_assay.md b/demo/core/01_assay_classes/04_like_assay.md similarity index 100% rename from demo/01_assay_classes/04_like_assay.md rename to demo/core/01_assay_classes/04_like_assay.md diff --git a/demo/01_assay_classes/05_equal_assay.md b/demo/core/01_assay_classes/05_equal_assay.md similarity index 100% rename from demo/01_assay_classes/05_equal_assay.md rename to demo/core/01_assay_classes/05_equal_assay.md diff --git a/demo/01_assay_classes/06_unequal_assay.md b/demo/core/01_assay_classes/06_unequal_assay.md similarity index 100% rename from demo/01_assay_classes/06_unequal_assay.md rename to demo/core/01_assay_classes/06_unequal_assay.md diff --git a/demo/01_assay_classes/07_equality_assay.md b/demo/core/01_assay_classes/07_equality_assay.md similarity index 100% rename from demo/01_assay_classes/07_equality_assay.md rename to demo/core/01_assay_classes/07_equality_assay.md diff --git a/demo/01_assay_classes/08_identity_assay.md b/demo/core/01_assay_classes/08_identity_assay.md similarity index 100% rename from demo/01_assay_classes/08_identity_assay.md rename to demo/core/01_assay_classes/08_identity_assay.md diff --git a/demo/01_assay_classes/09_case_assay.md b/demo/core/01_assay_classes/09_case_assay.md similarity index 100% rename from demo/01_assay_classes/09_case_assay.md rename to demo/core/01_assay_classes/09_case_assay.md diff --git a/demo/01_assay_classes/10_match_assay.md b/demo/core/01_assay_classes/10_match_assay.md similarity index 100% rename from demo/01_assay_classes/10_match_assay.md rename to demo/core/01_assay_classes/10_match_assay.md diff --git a/demo/01_assay_classes/11_nomatch_assay.md b/demo/core/01_assay_classes/11_nomatch_assay.md similarity index 100% rename from demo/01_assay_classes/11_nomatch_assay.md rename to demo/core/01_assay_classes/11_nomatch_assay.md diff --git a/demo/01_assay_classes/12_compare_assay.md b/demo/core/01_assay_classes/12_compare_assay.md similarity index 100% rename from demo/01_assay_classes/12_compare_assay.md rename to demo/core/01_assay_classes/12_compare_assay.md diff --git a/demo/01_assay_classes/13_less_assay.md b/demo/core/01_assay_classes/13_less_assay.md similarity index 100% rename from demo/01_assay_classes/13_less_assay.md rename to demo/core/01_assay_classes/13_less_assay.md diff --git a/demo/01_assay_classes/14_more_assay.md b/demo/core/01_assay_classes/14_more_assay.md similarity index 100% rename from demo/01_assay_classes/14_more_assay.md rename to demo/core/01_assay_classes/14_more_assay.md diff --git a/demo/01_assay_classes/15_less_equal_assay.md b/demo/core/01_assay_classes/15_less_equal_assay.md similarity index 100% rename from demo/01_assay_classes/15_less_equal_assay.md rename to demo/core/01_assay_classes/15_less_equal_assay.md diff --git a/demo/01_assay_classes/16_more_equal_assay.md b/demo/core/01_assay_classes/16_more_equal_assay.md similarity index 100% rename from demo/01_assay_classes/16_more_equal_assay.md rename to demo/core/01_assay_classes/16_more_equal_assay.md diff --git a/demo/01_assay_classes/17_close_assay.md b/demo/core/01_assay_classes/17_close_assay.md similarity index 100% rename from demo/01_assay_classes/17_close_assay.md rename to demo/core/01_assay_classes/17_close_assay.md diff --git a/demo/01_assay_classes/17_within_assay.md b/demo/core/01_assay_classes/17_within_assay.md similarity index 100% rename from demo/01_assay_classes/17_within_assay.md rename to demo/core/01_assay_classes/17_within_assay.md diff --git a/demo/01_assay_classes/18_kind_assay.md b/demo/core/01_assay_classes/18_kind_assay.md similarity index 77% rename from demo/01_assay_classes/18_kind_assay.md rename to demo/core/01_assay_classes/18_kind_assay.md index 863b626..ee5043f 100644 --- a/demo/01_assay_classes/18_kind_assay.md +++ b/demo/core/01_assay_classes/18_kind_assay.md @@ -3,7 +3,7 @@ The `KindAssay` asserts that an object is a class or any ancestor of that class. - assert KindAssay.pass?(1, Fixnum) + assert KindAssay.pass?(1, Integer) assert KindAssay.pass?(1, Numeric) refute KindAssay.pass?(1, String) @@ -12,6 +12,6 @@ And conversely, assert KindAssay.fail?(1, String) - refute KindAssay.fail?(1, Fixnum) + refute KindAssay.fail?(1, Integer) refute KindAssay.fail?(1, Numeric) diff --git a/demo/01_assay_classes/19_instance_assay.md b/demo/core/01_assay_classes/19_instance_assay.md similarity index 77% rename from demo/01_assay_classes/19_instance_assay.md rename to demo/core/01_assay_classes/19_instance_assay.md index 56cb542..b1cef95 100644 --- a/demo/01_assay_classes/19_instance_assay.md +++ b/demo/core/01_assay_classes/19_instance_assay.md @@ -2,7 +2,7 @@ The `InstanceAssay` asserts that an object is an instance of a specific class. - assert InstanceAssay.pass?(1, Fixnum) + assert InstanceAssay.pass?(1, Integer) refute InstanceAssay.pass?(1, Numeric) refute InstanceAssay.pass?(1, String) @@ -12,5 +12,5 @@ And conversely, assert InstanceAssay.fail?(1, String) assert InstanceAssay.fail?(1, Numeric) - refute InstanceAssay.fail?(1, Fixnum) + refute InstanceAssay.fail?(1, Integer) diff --git a/demo/01_assay_classes/20_include_assay.md b/demo/core/01_assay_classes/20_include_assay.md similarity index 100% rename from demo/01_assay_classes/20_include_assay.md rename to demo/core/01_assay_classes/20_include_assay.md diff --git a/demo/01_assay_classes/21_empty_assay.md b/demo/core/01_assay_classes/21_empty_assay.md similarity index 100% rename from demo/01_assay_classes/21_empty_assay.md rename to demo/core/01_assay_classes/21_empty_assay.md diff --git a/demo/01_assay_classes/22_respond_assay.md b/demo/core/01_assay_classes/22_respond_assay.md similarity index 100% rename from demo/01_assay_classes/22_respond_assay.md rename to demo/core/01_assay_classes/22_respond_assay.md diff --git a/demo/01_assay_classes/23_execution_assay.md b/demo/core/01_assay_classes/23_execution_assay.md similarity index 100% rename from demo/01_assay_classes/23_execution_assay.md rename to demo/core/01_assay_classes/23_execution_assay.md diff --git a/demo/01_assay_classes/23_return_assay.md b/demo/core/01_assay_classes/23_return_assay.md similarity index 100% rename from demo/01_assay_classes/23_return_assay.md rename to demo/core/01_assay_classes/23_return_assay.md diff --git a/demo/01_assay_classes/24_rescue_assay.md b/demo/core/01_assay_classes/24_rescue_assay.md similarity index 100% rename from demo/01_assay_classes/24_rescue_assay.md rename to demo/core/01_assay_classes/24_rescue_assay.md diff --git a/demo/01_assay_classes/25_raise_assay.md b/demo/core/01_assay_classes/25_raise_assay.md similarity index 100% rename from demo/01_assay_classes/25_raise_assay.md rename to demo/core/01_assay_classes/25_raise_assay.md diff --git a/demo/01_assay_classes/26_throw_assay.md b/demo/core/01_assay_classes/26_throw_assay.md similarity index 100% rename from demo/01_assay_classes/26_throw_assay.md rename to demo/core/01_assay_classes/26_throw_assay.md diff --git a/demo/01_assay_classes/27_path_assay.md b/demo/core/01_assay_classes/27_path_assay.md similarity index 100% rename from demo/01_assay_classes/27_path_assay.md rename to demo/core/01_assay_classes/27_path_assay.md diff --git a/demo/01_assay_classes/28_directory_assay.md b/demo/core/01_assay_classes/28_directory_assay.md similarity index 100% rename from demo/01_assay_classes/28_directory_assay.md rename to demo/core/01_assay_classes/28_directory_assay.md diff --git a/demo/01_assay_classes/29_file_assay.md b/demo/core/01_assay_classes/29_file_assay.md similarity index 100% rename from demo/01_assay_classes/29_file_assay.md rename to demo/core/01_assay_classes/29_file_assay.md diff --git a/demo/01_assay_classes/30_output_assay.md b/demo/core/01_assay_classes/30_output_assay.md similarity index 100% rename from demo/01_assay_classes/30_output_assay.md rename to demo/core/01_assay_classes/30_output_assay.md diff --git a/demo/01_assay_classes/31_stdout_assay.md b/demo/core/01_assay_classes/31_stdout_assay.md similarity index 100% rename from demo/01_assay_classes/31_stdout_assay.md rename to demo/core/01_assay_classes/31_stdout_assay.md diff --git a/demo/01_assay_classes/32_stderr_assay.md b/demo/core/01_assay_classes/32_stderr_assay.md similarity index 100% rename from demo/01_assay_classes/32_stderr_assay.md rename to demo/core/01_assay_classes/32_stderr_assay.md diff --git a/demo/02_lookup.md b/demo/core/02_lookup.md similarity index 100% rename from demo/02_lookup.md rename to demo/core/02_lookup.md diff --git a/demo/03_assertor.md b/demo/core/03_assertor.md similarity index 100% rename from demo/03_assertor.md rename to demo/core/03_assertor.md diff --git a/demo/04_assay.md b/demo/core/04_assay.md similarity index 75% rename from demo/04_assay.md rename to demo/core/04_assay.md index 418fa22..3212382 100644 --- a/demo/04_assay.md +++ b/demo/core/04_assay.md @@ -1,16 +1,10 @@ # Assay Class Methods -## Metadata +## Version -Assay support full project metadata access thanks to the `.ruby` -standard. +The version of the library is available as a constant. - Assay.metadata['name'] #=> 'assay' - -The metadata also dynamically translates into constants, so we -can work with this information in the traditional fashion. - - Assay::NAME #=> 'assay' + assert Assay::VERSION =~ /^\d+\.\d+\.\d+/ ## Color Messages diff --git a/demo/fluidity/00_intro.md b/demo/fluidity/00_intro.md new file mode 100644 index 0000000..b404663 --- /dev/null +++ b/demo/fluidity/00_intro.md @@ -0,0 +1,7 @@ +# Fluidity + +Fluidity is Assay's own notation: a chain of words read off the object +under test, such as `x.should.be.kind_of?(Integer)`. Each of its verbs +can be loaded on its own, or all the common ones together with + + require 'assay/fluidity' diff --git a/demo/fluidity/01_should.md b/demo/fluidity/01_should.md new file mode 100644 index 0000000..85f6dfb --- /dev/null +++ b/demo/fluidity/01_should.md @@ -0,0 +1,52 @@ +## Should + + require 'assay/fluidity/should' + +Now we have a fluent notation with which to make assertions. + + true.should.be.true + false.should.be.false + + (5 + 5).should.equal 10 + + [1,2,3].should.include(2) + +We can also use the associated operator (Ruby's built-in query method name). + + false.should.be.false? + true.should.be.true? + + (5 + 5).should == 10 + +Indefinite article `a` and `an` are suppored. + + 12.should.be.a.kind_of?(Integer) + +As is `not` for negation. + + 12.should.not.equal(20) + +We should also make sure such assertions can fail. + + IncludeAssay.should.be.raised do + [1,2,3].should.include(4) + end + + FalseAssay.should.be.raised do + true.should.be.false + end + + EqualAssay.should.be.raised do + (5 + 5).should == 11 + end + +Matcher notation is also supported, if you have any matcher classes +to use. Assay classes can be converted to matchers, so we can use +one of those to try this out. + + be_sixteen = EqualAssay[16.0] + + 16.should be_sixteen + + 15.should_not be_sixteen + diff --git a/demo/fluidity/02_must.md b/demo/fluidity/02_must.md new file mode 100644 index 0000000..8822e01 --- /dev/null +++ b/demo/fluidity/02_must.md @@ -0,0 +1,58 @@ +## Must + + require 'assay/fluidity/must' + +Now we have a fluent notation with which to make assertions. + + true.must.be.true + false.must.be.false + + (5 + 5).must.equal 10 + + [1,2,3].must.include(2) + +We can also use the associated operator (Ruby's built-in query method name). + + false.must.be.false? + true.must.be.true? + + (5 + 5).must == 10 + +Indefinite article `a` and `an` are suppored. + + 12.must.be.a.kind_of?(Integer) + + 12.must.be.an.instance_of?(Integer) + +As is `not` for negation. + + 12.must.not.equal(20) + +Or `must_not` can also be used. + + 12.must_not.equal(20) + +We must also make sure such assertions can fail. + + IncludeAssay.must.be.raised do + [1,2,3].must.include(4) + end + + FalseAssay.must.be.raised do + true.must.be.false + end + + EqualAssay.must.be.raised do + (5 + 5).must == 11 + end + +Matcher notation is also supported, if you have any matcher classes +to use. Assay classes can be converted to matchers, so we can use +one of those to try this out. + + be_sixteen = EqualAssay[16.0] + + 16.must be_sixteen + + 15.must_not be_sixteen + diff --git a/demo/fluidity/03_assert.md b/demo/fluidity/03_assert.md new file mode 100644 index 0000000..fde27bb --- /dev/null +++ b/demo/fluidity/03_assert.md @@ -0,0 +1,71 @@ +## Grammer + + require 'assay/fluidity/assert' + +Now we have a fluent notation with which to make assertions. + + true.assert.true + false.assert.false + + (5 + 5).must.equal 10 + + [1,2,3].must.include(2) + +We can also use the associated operator (Ruby's built-in query method name). + + false.assert.false? + true.assert.true? + + (5 + 5).assert == 10 + + (9 + 9).assert.not == 10 + + 12.assert.kind_of?(Integer) + +As is `not` for negation. + + 12.assert.not.equal(20) + +Or `should_not` can also be used. + + 12.should_not.equal(20) + +We must also make sure such assertions can fail. Since #assert is special +method to assay classes, we can use it as on these as part of our test +grmmer. So we use the raw `#assert!` method to handle the test. + + RaiseAssay.assert!(IncludeAssay) do + [1,2,3].assert.include(4) + end + + RaiseAssay.assert!(FalseAssay) do + true.assert.false + end + + RaiseAssay.assert!(EqualAssay) do + (5 + 5).assert == 11 + end + +Matcher notation is also supported, if you have any matcher classes +to use. Assay classes can be converted to matchers, so we can use +one of those to try this out. + + is_sixteen = EqualAssay[16.0] + + 16.assert is_sixteen + + +The ordinary form of `assert`, given a truth value, still works as it +does without the fluent notation. + + o = Object.new + + o.instance_eval{ assert(true) } + + RaiseAssay.assert!(RuntimeError) do + o.instance_eval{ assert(false) } + end + + RaiseAssay.assert!(RuntimeError) do + o.instance_eval{ assert(nil) } + end diff --git a/demo/fluidity/04_other.md b/demo/fluidity/04_other.md new file mode 100644 index 0000000..16cdf0b --- /dev/null +++ b/demo/fluidity/04_other.md @@ -0,0 +1,35 @@ +## Other Stuff + +What if there is an assertion made for which no Assay class exists? +If the target object has a query method defined by the same name, +that is, one ending in a `?` mark, then that mehtod will be used +to test the assertion. + + c = Class.new do + def initialize(truth) + @truth = truth + end + def yes? + @truth + end + def no? + !@truth + end + end + + x = c.new(true) + + x.should.be.yes + + x.should_not.be.no + + +And such an assertion fails when the query says otherwise. + + RaiseAssay.assert!(Assertion) do + x.should.be.no + end + + RaiseAssay.assert!(Assertion) do + x.should_not.be.yes + end diff --git a/demo/minitest/01_minitest_extensions.rdoc b/demo/minitest/01_minitest_extensions.rdoc new file mode 100644 index 0000000..b3e062c --- /dev/null +++ b/demo/minitest/01_minitest_extensions.rdoc @@ -0,0 +1,217 @@ += MiniTest Compatible Extensions + + require 'assay/minitest' + + class ::Object + include ::Assay::Extensions + end + +== must_be + + 1.must_be(:<, 2) + 1.must_be(:odd?) + + expect ::ExecutionAssay do + 1.wont_be(:<, 2) + end + + 1.wont_be(:>, 2) + 1.wont_be(:even?) + +== must_equal + + 1.must_equal(1) + + expect ::EqualAssay do + 1.must_equal(2) + end + + 1.wont_equal(2) + +== TrueAssay + + true.must_be_true + + expect ::TrueAssay do + false.must_be_true + end + + false.wont_be_true + +== must_be_false + + false.must_be_false + + expect ::FalseAssay do + true.must_be_false + end + + true.wont_be_false + +== must_be_nil + + nil.must_be_nil + + expect ::NilAssay do + true.must_be_nil + end + + false.wont_be_nil + +== must_be_empty + + [].must_be_empty + + expect ::EmptyAssay do + [1].must_be_empty + end + + [1].wont_be_empty + +== must_include + + [1].must_include(1) + + expect ::IncludeAssay do + [1].must_include(2) + end + + [1].wont_include(2) + +== must_be_within_delta + + 1.must_be_within_delta(2, 1.5) + + expect ::WithinAssay do + 1.must_be_within_delta(2, 0.5) + end + + 1.wont_be_within_delta(2, 0.5) + +== must_match + + "abc".must_match(/a/) + + expect ::MatchAssay do + "abc".must_match(/x/) + end + + "abc".wont_match(/g/) + +== must_eql + + 1.must_eql(1) + + expect ::EqualityAssay do + 1.must_eql(1.0) + end + + 1.wont_eql(1.0) + +== must_be_same_as + + :a.must_be_same_as(:a) + + expect ::IdentityAssay do + "a".must_be_same_as("a") + end + + :a.wont_be_same_as('a') + +== must_be_instance_of + + 1.must_be_instance_of(Integer) + + expect ::InstanceAssay do + 1.must_be_instance_of(String) + end + + 1.wont_be_instance_of(String) + +== must_kind_of + + 1.must_be_kind_of(Integer) + + expect ::KindAssay do + 1.must_be_kind_of(String) + end + + 1.wont_be_kind_of(String) + +== must_raise + + procedure = lambda{ raise ::ArgumentError } + + procedure.must_raise(::ArgumentError) + + expect ::RaiseAssay do + procedure.must_raise(::TypeError) + end + + procedure.wont_raise(::TypeError) + +== must_respond_to + + "string".must_respond_to(:upcase) + + expect ::RespondAssay do + "string".must_respond_to(:not_a_method) + end + + "string".wont_respond_to(:not_a_method) + +== must_satisfy + + 5.must_satisfy{ |x| x > 3 } + + expect ::ExecutionAssay do + 5.must_satisfy{ |x| x < 3 } + end + + 5.wont_satisfy{ |x| x < 3 } + +== must_send + + 5.must_send([:+, 1]) + + expect ::ExecutionAssay do + 5.must_send([:upcase]) + end + + 5.wont_send([:upcase]) + +== must_throw + + procedure = lambda{ throw :foo } + + procedure.must_throw(:foo) + + expect ::ThrowAssay do + procedure.must_throw(:bar) + end + + procedure.wont_throw(:bar) + +== must_output + + procedure = lambda{ puts "fun!" } + + procedure.must_output('fun!') + + expect ::OutputAssay do + procedure.must_output('not!') + end + +== must_be_like + +The `#must_be_like` method is not a MiniText expectation, but we have thrown it +in for gooe measure. + + /a/.must_be_like('a') + + expect ::LikeAssay do + 'a'.must_be_like(10) + end + + 'a'.wont_be_like(10) + diff --git a/demo/minitest/02_minitest_assertions.rdoc b/demo/minitest/02_minitest_assertions.rdoc new file mode 100644 index 0000000..389c785 --- /dev/null +++ b/demo/minitest/02_minitest_assertions.rdoc @@ -0,0 +1,250 @@ += Assertion Methods + + require 'assay/minitest' + + include ::Assay::Assertions + +== assert + + assert(true, "yep it is so") + + expect ::Assertion do + assert(false, "yep it is so") + end + + refute(false, "not on you life") + +== assert_boolean + + assert_boolean(true) + assert_boolean(false) + + refute_boolean(nil) + refute_boolean(:foo) + +== assert_equal + + assert_equal(1,1) + + expect ::EqualAssay do + assert_equal(1,2) + end + + refute_equal(1,2) + +== assert_true + + assert_true(true) + + expect ::TrueAssay do + assert_true(false) + end + + refute_true(false) + +== assert_false + + assert_false(false) + + expect ::FalseAssay do + assert_false(true) + end + + refute_false(true) + +== assert_nil + + assert_nil(nil) + + expect ::NilAssay do + assert_nil(true) + end + + refute_nil(true) + refute_nil(false) + +== assert_in_delta + + assert_in_delta(1, 1.5, 0.5) + + expect ::WithinAssay do + assert_in_delta(1, 2.5, 1) + end + + refute_in_delta(1, 2.5, 1) + +== assert_in_epsilon + + assert_in_epsilon(1, 1.5, 2) + + expect ::CloseAssay do + assert_in_epsilon(1, 2.5, 1) + end + + refute_in_epsilon(1, 2.5, 1) + +== assert_match + + assert_match(/a/, "abc") + + expect ::MatchAssay do + assert_match(/x/, "abc") + end + + refute_match(/a/, "bcd") + +== assert_no_match + + assert_no_match(/a/, "bcd") + + expect ::MatchAssay do + assert_no_match(/a/, "abc") + end + +== assert_operator + + assert_operator(3, :<, 4) + + expect ::ExecutionAssay do + assert_operator(4, :<, 3) + end + + refute_operator(4, :<, 3) + +== assert_equivalent + + assert_equivalent(1, 1) + + expect ::EqualityAssay do + assert_equivalent(1, 1.0) + end + + refute_equivalent(1, 1.0) + +== assert_empty + + assert_empty([]) + + expect ::EmptyAssay do + assert_empty([1,2,3]) + end + + refute_empty([1,2,3]) + +== assert_include + + assert_includes([1,2,3], 1) + + expect ::IncludeAssay do + assert_includes([1,2,3], 4) + end + + refute_includes([1,2,3], 4) + +== assert_same + + assert_same(:a, :a) + + expect ::IdentityAssay do + assert_same("a", "a") + end + + refute_same(:a, :b) + +== assert_instance_of + + assert_instance_of(Integer, 1) + + expect ::InstanceAssay do + assert_instance_of(String, 1) + end + + refute_instance_of(String, 1) + +== assert_kind_of + + assert_kind_of(Integer, 1) + + expect ::KindAssay do + assert_kind_of(String, 1) + end + + refute_kind_of(String, 1) + +== assert_raises + + assert_raises(ArgumentError){ raise ArgumentError } + + expect ::RaiseAssay do + assert_raises(ArgumentError){ raise TypeError } + end + + refute_raises(ArgumentError){ raise TypeError } + +== assert_nothing_raised + + assert_nothing_raised{ 'good' } + + expect ::RescueAssay do + assert_nothing_raised{ raise } + end + + refute_nothing_raised{ raise } + +== assert_respond_to + + assert_respond_to("string", :upcase) + + expect ::RespondAssay do + assert_respond_to("string", :not_a_method) + end + + refute_respond_to("string", :not_a_method) + +== assert_block + + assert_block{ :ok } + + expect ::ExecutionAssay do + assert_block{ raise } + end + +== assert_throws + + assert_throws(:foo){ throw :foo } + + expect ::ThrowAssay do + assert_throws(:foo){ throw :bar } + end + + refute_throws(:foo){ throw :bar } + +== assert_predicate + + assert_predicate(10, :even?) + + refute_predicate(10, :odd?) + +== assert_output + + assert_output('this'){ puts 'this' } + + refute_output('this'){ puts 'that' } + +== assert_silent + + assert_silent{ nil } + + refute_silent{ puts 'that' } + +== assert_alike + + assert_alike(1,1) + assert_alike(1,1.0) + + expect ::LikeAssay do + assert_alike(1,"1") + end + + refute_alike(1,"1") + diff --git a/demo/rspec/00_introduction.md b/demo/rspec/00_introduction.md new file mode 100644 index 0000000..548c08d --- /dev/null +++ b/demo/rspec/00_introduction.md @@ -0,0 +1,16 @@ +# RSpec Notation + +## Setup + +First we need to require the library. + + require 'assay/rspec' + +This loads Assay and adds `#should` and `#should_not` to `BasicObject`. +The matcher methods are in the module `Assay::RSpec::Matchers`, which +is also included into `Assay::Matchers`. To use them, include either +module into the test scope. + + include Assay::Matchers + +With that in place, we are ready to use the matchers. diff --git a/demo/rspec/01_should.md b/demo/rspec/01_should.md new file mode 100644 index 0000000..f7bc4c6 --- /dev/null +++ b/demo/rspec/01_should.md @@ -0,0 +1,24 @@ +## RSpec Should Method + +### should + +Becuase the `#should` method used `=~` as the assertion operator, +you can do something a bit unexpected, such as, + + 'a'.should /a/ + +### should= + +As a shortcut one can also use the `#should=` method instead of +the usual two-step `should ==` call. + + 10.should = 10 + + assert_raises ::EqualAssay do + 10.should = 20 + end + +The same is true for `#should_not`. + + 10.should_not = 20 + diff --git a/demo/rspec/02_matchers.md b/demo/rspec/02_matchers.md new file mode 100644 index 0000000..b245356 --- /dev/null +++ b/demo/rspec/02_matchers.md @@ -0,0 +1,176 @@ +## RSpec Matchers + +### should equal + + 1.should = 1 + + assert_raises ::EqualAssay do + 1.should = 2 + end + +### be_true + + true.should be_true + + assert_raises ::TrueAssay do + false.should be_true + end + +### be_false + + false.should be_false + + assert_raises ::FalseAssay do + true.should be_false + end + +### be_nil + + nil.should be_nil + + assert_raises ::NilAssay do + true.should be_nil + end + +### be_empty + + [].should be_empty + + assert_raises ::EmptyAssay do + [1].should be_empty + end + + [1].should_not be_empty + +### be_close + + 1.should be_close(1.5, 2) + + assert_raises ::WithinAssay do + 1.should be_close(0.5, 2) + end + + 1.should_not be_close(0.5, 2) + +### match + + "abc".should match(/a/) + + assert_raises ::MatchAssay do + "abc".should match(/x/) + end + + "abc".should_not match(/g/) + +### eql + + 1.should eql(1) + + assert_raises ::EqualityAssay do + 1.should eql(1.0) + end + + 1.should_not eql(1.0) + +### equal + + :a.should equal(:a) + + assert_raises ::IdentityAssay do + "a".should equal("a") + end + + :a.should_not equal('a') + +### be_instance_of + + 1.should be_instance_of(Integer) + + assert_raises ::InstanceAssay do + 1.should be_instance_of(String) + end + + 1.should_not be_instance_of(String) + +### be_kind_of + + 1.should be_kind_of(Integer) + + assert_raises ::KindAssay do + 1.should be_kind_of(String) + end + + 1.should_not be_kind_of(String) + +### raise_error + + procedure = lambda{ raise ::ArgumentError } + + procedure.should raise_error(::ArgumentError) + + assert_raises ::RaiseAssay do + procedure.should raise_error(::TypeError) + end + + procedure.should_not raise_error(::TypeError) + +### respond_to + + "string".should respond_to(:upcase) + + assert_raises ::RespondAssay do + "string".should respond_to(:not_a_method) + end + + "string".should_not respond_to(:not_a_method) + +### satisfy + + 5.should satisfy{ |x| x > 3 } + + assert_raises ::ExecutionAssay do + 5.should satisfy{ |x| x < 3 } + end + + 5.should_not satisfy{ |x| x < 3 } + +### throw_symbol + + procedure = lambda{ throw :foo } + + procedure.should throw_symbol(:foo) + + assert_raises ::ThrowAssay do + procedure.should throw_symbol(:bar) + end + + procedure.should_not throw_symbol(:bar) + +## Supplemental Matchers + +### equate_to + +This is not strictly an RSpec matcher, but we have thrown it in for good measure. +It is equivalent to using the `#should=` method. + + 10.should equate_to(10) + + assert_raises ::EqualityAssay do + 10.should equate_to(10.0) + end + + 10.should_not equate_to(10.0) + +### be_like + +The `#be_like` matcher is not strictly an RSpec matcher, but we have thrown it +in for good measure. + + /a/.should be_like('a') + + assert_raises ::LikeAssay do + /a/.should be_like('b') + end + + /a/.should_not be_like('b') + diff --git a/demo/rspec/03_have.md b/demo/rspec/03_have.md new file mode 100644 index 0000000..6031108 --- /dev/null +++ b/demo/rspec/03_have.md @@ -0,0 +1,51 @@ +### Have + +The `#have` matchers make it easy to set expectations about the size +of a collection. In general the term `items` is used if the target +object is a collection. + + a = [1, 2, 3] + + a.should have(3).items + a.should_not have(2).items + a.should_not have(4).items + + a.should have_exactly(3).items + a.should_not have_exactly(2).items + a.should_not have_exactly(4).items + + a.should have_at_least(2).items + a.should have_at_most(4).items + +But a method that returns a collection can be used instead. + + class ::String + def words + split(' ') + end + end + + s = "a sentence with some words" + + s.should have(5).words + s.should_not have(4).words + s.should_not have(6).words + + s.should have_exactly(5).words + s.should_not have_exactly(4).words + s.should_not have_exactly(6).words + + s.should have_at_least(4).words + s.should have_at_most(6).words + +Besides `#have` there is also `#have_at_least` and `#have_at_most`. + + a = [1, 2, 3] + + a.should have_at_least(2).items + a.should have_at_most(4).items + + a.should have_at_least(3).items + a.should have_at_most(3).items + + diff --git a/demo/rspec/04_expect.md b/demo/rspec/04_expect.md new file mode 100644 index 0000000..38dd46c --- /dev/null +++ b/demo/rspec/04_expect.md @@ -0,0 +1,42 @@ +## RSpec Expect + +### expect + +Expect is RSpecs new and approved assertion notation. It works +very much like `#should` but it isn't an Object extension, which +is considered a "*better practice*". + + expect(10).to eq(10) + +### operators + +It can also delegate operators, so the above example can also be +written. + + expect(10).to == 10 + + assert_raises EqualAssay do + expect(10).to == 20 + end + + +Any other operator is sent to the object, and has to come back true. + + expect(10).to > 5 + + assert_raises LessEqualAssay do + expect(10).to <= 5 + end + +### blocks + +Given a block instead of a value, `expect` passes the block to the +matcher, which is how raising and throwing are tested. + + expect{ raise ArgumentError }.to raise_error(ArgumentError) + + expect{ :fine }.to_not raise_error(ArgumentError) + + assert_raises RaiseAssay do + expect{ :fine }.to raise_error(ArgumentError) + end diff --git a/demo/rspec/applique/setup.rb b/demo/rspec/applique/setup.rb new file mode 100644 index 0000000..731d41a --- /dev/null +++ b/demo/rspec/applique/setup.rb @@ -0,0 +1,2 @@ +require 'assay/rspec' +include ::Assay::Matchers diff --git a/demo/testunit/01_testunit_assertions.md b/demo/testunit/01_testunit_assertions.md new file mode 100644 index 0000000..72513fb --- /dev/null +++ b/demo/testunit/01_testunit_assertions.md @@ -0,0 +1,266 @@ +# Assertion Methods + +To use the assertion methods, first require the library. + + require 'assay/testunit' + +Then include them into your test scope. + + include ::Assay::Assertions + +## assert_equal + + assert_equal(1,1) + + expect ::EqualAssay do + assert_equal(1,2) + end + + assert_not_equal(1,2) + +## assert_true + + assert_true(true) + + expect ::TrueAssay do + assert_true(false) + end + + assert_not_true(false) + assert_not_true(nil) + +## assert_false + + assert_false(false) + + expect ::FalseAssay do + assert_false(true) + end + + assert_not_false(true) + assert_not_false(nil) + +## assert_nil + + assert_nil(nil) + + expect ::NilAssay do + assert_nil(true) + end + + assert_not_nil(true) + assert_not_nil(false) + +## assert_in_delta + + assert_in_delta(1, 1.5, 2) + + expect ::WithinAssay do + assert_in_delta(1, 2.5, 1) + end + + assert_not_in_delta(1, 2, 0.5) + +## assert_in_epsilon + + assert_in_epsilon(1, 1.5, 2) + assert_in_epsilon(0, 1.5, 2) + + expect ::CloseAssay do + assert_in_epsilon(1, 2.5, 1) + end + + assert_not_in_epsilon(1, 2.5, 1) + assert_not_in_epsilon(0, 2.5, 1) + +## assert_match + + assert_match(/a/, "abc") + + expect ::MatchAssay do + assert_match(/x/, "abc") + end + + assert_not_match(/a/, "bcd") + +## assert_no_match + + assert_no_match(/a/, "bcd") + + expect ::NoMatchAssay do + assert_no_match(/a/, "abc") + end + +## assert_empty + + assert_empty([]) + + expect ::EmptyAssay do + assert_empty([1,2,3]) + end + + assert_not_empty([1,2,3]) + +## assert_include + + assert_includes([1,2,3], 1) + + expect ::IncludeAssay do + assert_includes([1,2,3], 4) + end + + assert_not_includes([1,2,3], 4) + +## assert_same + + assert_same(:a, :a) + + expect ::IdentityAssay do + assert_same("a", "a") + end + + assert_not_same(:a, :b) + +## assert_instance_of + + assert_instance_of(Integer, 1) + + expect ::InstanceAssay do + assert_instance_of(String, 1) + end + + assert_not_instance_of(String, 1) + +## assert_kind_of + + assert_kind_of(Integer, 1) + + expect ::KindAssay do + assert_kind_of(String, 1) + end + + assert_not_kind_of(String, 1) + +## assert_raise + + assert_raise(ArgumentError){ raise ArgumentError } + + expect ::RaiseAssay do + assert_raise(ArgumentError){ raise TypeError } + end + + assert_not_raised(ArgumentError){ raise TypeError } + +## assert_raise_kind_of + + assert_raise_kind_of(StandardError){ raise } + + expect ::RescueAssay do + assert_raise_kind_of(ArgumentError){ raise TypeError } + end + + assert_raise_kind_of(Exception){ raise } + +## assert_nothing_raised + + assert_nothing_raised{ true } + assert_nothing_raised{ nil } + + expect ::RescueAssay do + assert_nothing_raised{ raise } + end + +## assert_respond_to + + assert_respond_to("string", :upcase) + + expect ::RespondAssay do + assert_respond_to("string", :not_a_method) + end + + assert_not_respond_to("string", :not_a_method) + +## assert_block + + assert_block{ :ok } + + expect ::ExecutionAssay do + assert_block{ raise } + end + +## assert_throw + + assert_throw(:foo){ throw :foo } + + expect ::ThrowAssay do + assert_throw(:foo){ throw :bar } + end + + assert_not_thrown(:foo){ throw :bar } + +## assert_nothing_thrown + + assert_nothing_thrown{ nil } + + expect ::ThrowAssay do + assert_nothing_thrown{ throw :bar } + end + +## assert_compare + + assert_compare(1, :<, 2) + assert_compare(2, :>, 1) + assert_compare(1, :<=, 1) + assert_compare(1, :>=, 1) + assert_compare(1, :<=, 2) + assert_compare(2, :>=, 1) + assert_compare(1, :==, 1) + + expect ArgumentError do + assert_compare(1, :<=>, 1) + end + +## assert_operator + + assert_operator([], :<<, 1) + +## assert_predicate + + assert_predicate(10, :even?) + + assert_not_predicate(10, :odd?) + +## assert_path_exist + + assert_path_exist(__FILE__) + + assert_path_not_exist(__FILE__ + '.foobar') + +## assert_boolean + + assert_boolean(true) + assert_boolean(false) + + assert_not_boolean(nil) + +## assert_alike + + assert_alike(1,1) + assert_alike(1,1.0) + + expect ::LikeAssay do + assert_alike(1,"1") + end + + assert_not_alike(1,"1") + +## assert_equivalent + + assert_equivalent(1, 1) + + expect ::EqualityAssay do + assert_equivalent(1, 1.0) + end + + assert_not_equivalent(1, 1.0) + diff --git a/etc/qed.rb b/etc/qed.rb deleted file mode 100644 index 4567dfa..0000000 --- a/etc/qed.rb +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env ruby - -# -# Setup QED to create coverage report. -# -QED.configure 'cov' do - require 'simplecov' - SimpleCov.start do - coverage_dir 'log/coverage' - #add_group "RSpec", "lib/assay/rspec.rb" - end -end - diff --git a/lib/assay.rb b/lib/assay.rb index 2ec3a4d..6ba1475 100644 --- a/lib/assay.rb +++ b/lib/assay.rb @@ -1,30 +1,16 @@ +# Assay (https://github.com/rubyworks/assay) +# Copyright (c) 2010 Rubyworks. License (spdx) BSD-2-Clause. + +require_relative 'assay/version' + # Load Assay's assertion classes. require_relative 'assay/assertion' -dir = File.dirname(__FILE__) + '/assay' -Dir.entries(dir).each do |file| - next if File.extname(file) != '.rb' - require_relative 'assay/' + file +Dir[File.join(__dir__, 'assay', '*_assay.rb')].sort.each do |file| + require_relative 'assay/' + File.basename(file, '.rb') end module Assay - # - # Returns Hash table of project metadata. - # - def self.metadata - @spec ||= ( - require 'yaml' - YAML.load(File.new(File.dirname(__FILE__) + '/assay.yml')) - ) - end - - # - # Check metadata for missing constants. - # - def self.const_missing(name) - metadata[name.to_s.downcase] || super(name) - end - # # Returns a list of Assertion subclasses. # diff --git a/lib/assay.yml b/lib/assay.yml deleted file mode 120000 index 064ee51..0000000 --- a/lib/assay.yml +++ /dev/null @@ -1 +0,0 @@ -../.ruby \ No newline at end of file diff --git a/lib/assay/adapter/minitest.rb b/lib/assay/adapter/minitest.rb index b3287f7..38231cd 100644 --- a/lib/assay/adapter/minitest.rb +++ b/lib/assay/adapter/minitest.rb @@ -1,25 +1,36 @@ -module MiniTest #:nodoc: - class Unit #:nodoc: - # To teach MiniTest to recognize the expanded concept of assertions - # we add in an extra capture clause to the it's #puke method. - def puke c, m, x - case x - when MiniTest::Skip - @skips = @skips + 1 - x = "Skipped:\n#{m}(#{c}) [#{location x}]:\n#{x.message}\n" - when MiniTest::Assertion - @failures = @failures + 1 - x = "Failure:\n#{m}(#{c}) [#{location x}]:\n#{x.message}\n" - when x.respond_to?(:assertion?) && x.assertion? - @failures = @failures + 1 - x = "Failure:\n#{m}(#{c}) [#{location x}]:\n#{x.message}\n" - else - @errors = @errors + 1 - b = MiniTest::filter_backtrace(x.backtrace).join("\n ") - x = "Error:\n#{m}(#{c}):\n#{x.class}: #{x.message}\n #{b}\n" +require 'minitest' + +module Assay + module Adapter + + # Teaches Minitest that any exception answering true to `assertion?` + # (the BRASS standard) is a failed assertion, not an error. Without + # this Minitest still runs tests that use Assay, but counts their + # failures as errors. + # + # Loaded with `require 'assay/adapter/minitest'`. Needs Minitest 5 + # or newer. + # + module Minitest + + def capture_exceptions + super do + begin + yield + rescue ::Minitest::Assertion, *::Minitest::Test::PASSTHROUGH_EXCEPTIONS + raise + rescue Exception => error + raise unless error.respond_to?(:assertion?) && error.assertion? + failure = ::Minitest::Assertion.new(error.message) + failure.set_backtrace(error.backtrace) + raise failure + end + end end - @report << x - x[0, 1] + end + end end + +Minitest::Test.prepend(Assay::Adapter::Minitest) diff --git a/lib/assay/adapter/testunit.rb b/lib/assay/adapter/testunit.rb index f911827..08e681c 100644 --- a/lib/assay/adapter/testunit.rb +++ b/lib/assay/adapter/testunit.rb @@ -1,42 +1,35 @@ -module Test #:nodoc: - module Unit #:nodoc: - class TestCase #:nodoc: - # Runs the individual test method represented by this - # instance of the fixture, collecting statistics, failures - # and errors in result. - def run(result) - yield(STARTED, name) - @_result = result - begin - setup - __send__(@method_name) - rescue AssertionFailedError => e - add_failure(e.message, e.backtrace) - rescue Exception => e - if e.respond_to?(:assertion?) && e.assertion? - add_failure(e.message, e.backtrace) - else - raise if PASSTHROUGH_EXCEPTIONS.include? $!.class - add_error($!) - end - ensure - begin - teardown - rescue AssertionFailedError => e - add_failure(e.message, e.backtrace) - rescue Exception => e - if e.respond_to?(:assertion?) && e.assertion? - add_failure(e.message, e.backtrace) - else - raise if PASSTHROUGH_EXCEPTIONS.include? $!.class - add_error($!) - end - end - end - result.add_run - yield(FINISHED, name) - end +require 'test/unit' + +module Assay + module Adapter + + # Teaches Test::Unit that any exception answering true to `assertion?` + # (the BRASS standard) is a failed assertion, not an error. Without + # this Test::Unit still runs tests that use Assay, but counts their + # failures as errors. + # + # Loaded with `require 'assay/adapter/testunit'`. Needs the test-unit + # gem, version 3 or newer. + # + module TestUnit + + def self.included(base) + base.exception_handler(:handle_brass_assertion) + end + + private + + def handle_brass_assertion(exception) + return false if exception.is_a?(::Test::Unit::AssertionFailedError) + return false unless exception.respond_to?(:assertion?) && exception.assertion? + problem_occurred + add_failure(exception.message, exception.backtrace) + true + end + end + end end +Test::Unit::TestCase.send(:include, Assay::Adapter::TestUnit) diff --git a/lib/assay/assertable.rb b/lib/assay/assertable.rb index d27cb31..a9926b4 100644 --- a/lib/assay/assertable.rb +++ b/lib/assay/assertable.rb @@ -82,7 +82,7 @@ def assert!(*arguments, &block) pass = pass?(*arguments, &block) - assert pass, self, message, backtrace + ::Kernel.assert pass, self, message, backtrace #if pass?(*arguments, &block) # increment(:pass) @@ -105,7 +105,7 @@ def refute!(*arguments, &block) fail = fail?(*arguments, &block) - assert fail, self, message, backtrace + ::Kernel.assert fail, self, message, backtrace #if fail?(*arguments, &block) # increment(:pass) @@ -161,7 +161,7 @@ def standard_message(*arguments, &block) t.times{ vars << vars.last.succ } msg = '' - msg << "a#{op} " + vars.join(',') + "\n" + msg << "a#{op}" + vars.join(', ') + "\n" msg << args_inspect.join("\n") msg else diff --git a/lib/assay/close_assay.rb b/lib/assay/close_assay.rb index 389a835..f47a645 100644 --- a/lib/assay/close_assay.rb +++ b/lib/assay/close_assay.rb @@ -18,7 +18,7 @@ def self.pass?(subject, criterion, epsilon) #(a - b).abs / [a.abs, b.abs].max <= e - d = b * e # [a.abs,b.abs].max * e + d = (b * e).abs (b - d) <= a && (b + d) >= a end @@ -32,7 +32,7 @@ def self.assert_message(subject, criterion, delta) e = delta.inspect if [a, b, e].any?{ |e| e.to_s.size > SIZE_LIMIT } - "b(1 - e) <= a <= b(1 + e)\na) #{a}\nb) #{b}\nd) #{d}" + "b(1 - e) <= a <= b(1 + e)\na) #{a}\nb) #{b}\ne) #{e}" else "#{b}(1 - #{e}) <= #{a} <= #{b}(1 + #{e})" end diff --git a/lib/assay/core_ext/kernel.rb b/lib/assay/core_ext/kernel.rb index 8a09a0f..4a79e4e 100644 --- a/lib/assay/core_ext/kernel.rb +++ b/lib/assay/core_ext/kernel.rb @@ -10,11 +10,9 @@ def identical?(other) object_id == other.object_id end - # Ascertain likeness, returns true if any of `equal?`, `eql?`, `==`, - # `===` or `=~` evaluate truthfully, either with `self` as the receiver - # or `other` as the receiver. - # - # @todo Should `#=~` be apart of this comparison? + # Ascertain likeness, returns true if any of `equal?`, `eql?`, `==` or + # `===` evaluate truthfully, either with `self` as the receiver or + # `other` as the receiver. # # @param [Object] other # Any object reference. @@ -26,12 +24,10 @@ def like?(other) self.eql?(other) || self.==(other) || self.===(other) || - self.=~(other) || other.equal?(self) || other.eql?(self) || other.==(self) || - other.===(self) || - other.=~(self) + other.===(self) ? true : false end # diff --git a/lib/assay/fluidity.rb b/lib/assay/fluidity.rb new file mode 100644 index 0000000..1a570f1 --- /dev/null +++ b/lib/assay/fluidity.rb @@ -0,0 +1,6 @@ +require_relative '../assay' + +require_relative 'fluidity/grammar' +require_relative 'fluidity/should' +require_relative 'fluidity/must' +require_relative 'fluidity/assert' diff --git a/lib/assay/fluidity/assert.rb b/lib/assay/fluidity/assert.rb new file mode 100644 index 0000000..0660870 --- /dev/null +++ b/lib/assay/fluidity/assert.rb @@ -0,0 +1,27 @@ +require_relative 'grammar' + +class Object + + # Use `assert` nomenclature for assertions. + # + # 10.assert.kind_of?(Integer) + # + def assert(*args, &blk) + return ::Assay::Fluidity::Grammar::Assert.new(self) if args.empty? + + matcher = args.first + + if ::Assay::Assertor === matcher + matcher =~ self + else + super(*args, &blk) + end + end + +end + + +module Kernel + public :assert + public :refute +end diff --git a/lib/assay/fluidity/grammar.rb b/lib/assay/fluidity/grammar.rb new file mode 100644 index 0000000..61aee61 --- /dev/null +++ b/lib/assay/fluidity/grammar.rb @@ -0,0 +1,140 @@ +require_relative '../../assay' + +module Assay; end +module Assay::Fluidity + + module Grammar + + class Base + + def initialize(target, negate=false) + @target = target + @negate = negate + end + + # Have to override the ususal `#==` method to support this. + def ==(other) + if @negate + ::EqualAssay.refute!(@target, other, :backtrace=>caller) + else + ::EqualAssay.assert!(@target, other, :backtrace=>caller) + end + end + + #private + + def method_missing(s, *a, &b) + if assay = (::Assertion.by_name(s) || ::Assertion.by_operator(s)) + if @negate + assay.refute!(@target, *a, &b) + else + assay.assert!(@target, *a, &b) + end + else + q = (s.to_s.end_with?('?') ? s : (s.to_s+'?')) + if @target.respond_to?(q) + truth = @target.send(q, *a, &b) + if @negate + ::Kernel.assert(!truth, ::Assertion, "! #{@target.inspect}.#{q}", caller) + else + ::Kernel.assert(truth, ::Assertion, "#{@target.inspect}.#{q}", caller) + end + else + super(s, *a, &b) + end + end + end + + end + + # + class Assert < Base + + #def method_missing(s, *a, &b) + # call(s, *a, &b) + #end + + def not + Assert.new(@target, !@negate) + end + + end + + # + class Be < Base + + #def method_missing(s, *a, &b) + # call(s, *a, &b) + #end + + # + def a + self + end + + # + def an + self + end + + end + + # + class Is < Be + + def not + Is.new(@target, !@negate) + end + + end + + # + class Must < Base + + #def method_missing(s, *a, &b) + # call(s, *a, &b) + #end + + def be + Be.new(@target, @negate) + end + + def not + Must.new(@target, !@negate) + end + + end + + # + class Will < Base + + def be + Be.new(@target, @negate) + end + + def not + Will.new(@target, !@negate) + end + + end + + # + class Should < Base + + #def method_missing(s, *a, &b) + # call(s, *a, &b) + #end + + def be + Be.new(@target, @negate) + end + + def not + Should.new(@target, !@negate) + end + + end + + end + +end diff --git a/lib/assay/fluidity/is.rb b/lib/assay/fluidity/is.rb new file mode 100644 index 0000000..05e4420 --- /dev/null +++ b/lib/assay/fluidity/is.rb @@ -0,0 +1,18 @@ +require_relative 'grammar' + +class Object #BasicObject + + # Use `is` nomenclature for assertions. + # + # 10.is.kind_of?(Integer) + # + def is(matcher=nil) + if matcher + matcher === self + else + ::Assay::Fluidity::Grammar::Is.new(self) + end + end + +end + diff --git a/lib/assay/fluidity/must.rb b/lib/assay/fluidity/must.rb new file mode 100644 index 0000000..59c58b4 --- /dev/null +++ b/lib/assay/fluidity/must.rb @@ -0,0 +1,38 @@ +require_relative 'grammar' + +# TODO: What about BasicObject ? + +class Object #BasicObject + + # Use `must` nomenclature for assertions. + # + # 10.must.be.kind_of(Integer) + # + def must(matcher=nil) + if matcher + matcher =~ self + else + ::Assay::Fluidity::Grammar::Must.new(self) + end + end + + # Also, `must_not` nomenclature for assertions. + # + # 10.must_not.be.kind_of?(Integer) + # + def must_not(matcher=nil) + if matcher + matcher !~ self + else + ::Assay::Fluidity::Grammar::Must.new(self, true) + end + end + + # Contraction do must not. + # + # 10.mustnt.be.kind_of?(Integer) + # + alias_method :mustnt, :must_not + +end + diff --git a/lib/assay/fluidity/should.rb b/lib/assay/fluidity/should.rb new file mode 100644 index 0000000..877219a --- /dev/null +++ b/lib/assay/fluidity/should.rb @@ -0,0 +1,32 @@ +require_relative 'grammar' + +class Object #BasicObject + + # Use `should` nomenclature for assertions. + # + # 10.should.be.kind_of(Integer) + # + def should(matcher=nil) + if matcher + matcher =~ self + else + ::Assay::Fluidity::Grammar::Should.new(self) + end + end + + # Also, `should_not` nomenclature for assertions. + # + # 10.should_not.be.kind_of?(Integer) + # + def should_not(matcher=nil) + if matcher + matcher !~ self + else + ::Assay::Fluidity::Grammar::Should.new(self, true) + end + end + + alias_method :shouldnt, :should_not + +end + diff --git a/lib/assay/fluidity/will.rb b/lib/assay/fluidity/will.rb new file mode 100644 index 0000000..2287664 --- /dev/null +++ b/lib/assay/fluidity/will.rb @@ -0,0 +1,36 @@ +require_relative 'grammar' + +class Object #BasicObject + + # Use `will` nomenclature for assertions. + # + # 10.will.be.kind_of(Integer) + # + def will(matcher=nil) + if matcher + matcher =~ self + else + ::Assay::Fluidity::Grammar::Will.new(self) + end + end + + # Also, `will_not` nomenclature for assertions. + # + # 10.will_not.be.kind_of?(Integer) + # + def will_not(matcher=nil) + if matcher + matcher !~ self + else + ::Assay::Fluidity::Grammar::Will.new(self, true) + end + end + + # Contraction of will not. + # + # 10.wont.be.kind_of?(Integer) + # + alias_method :wont, :will_not + +end + diff --git a/lib/assay/less_assay.rb b/lib/assay/less_assay.rb index 6ac836b..68e7353 100644 --- a/lib/assay/less_assay.rb +++ b/lib/assay/less_assay.rb @@ -14,5 +14,11 @@ def self.pass?(subject, criterion) subject < criterion end -end + # + # Error message, e.g. `5 < 3`. + # + def self.assert_message(subject, criterion) + standard_message(subject, criterion) + end +end diff --git a/lib/assay/less_equal_assay.rb b/lib/assay/less_equal_assay.rb index e425acf..444dc56 100644 --- a/lib/assay/less_equal_assay.rb +++ b/lib/assay/less_equal_assay.rb @@ -21,5 +21,11 @@ def self.pass?(subject, criterion) subject <= criterion end -end + # + # Error message, e.g. `5 <= 3`. + # + def self.assert_message(subject, criterion) + standard_message(subject, criterion) + end +end diff --git a/lib/assay/minitest.rb b/lib/assay/minitest.rb new file mode 100644 index 0000000..42e477f --- /dev/null +++ b/lib/assay/minitest.rb @@ -0,0 +1,24 @@ +require_relative '../assay' + +require_relative 'minitest/assertions' +require_relative 'minitest/extensions' + +module Assay + # `Minitest` is how the framework spells its name now. + Minitest = MiniTest unless const_defined?(:Minitest, false) +end + +# Minitest-compatible assertion methods (`assert_equal`, ...), to mix +# into a test scope. +module Assay::Assertions + include Assay::MiniTest::Assertions +end + +# Minitest-compatible expectation methods (`must_equal`, ...). +module Assay::Extensions + include Assay::MiniTest::Extensions +end + +class Object + include Assay::Extensions +end diff --git a/lib/assay/minitest/assertions.rb b/lib/assay/minitest/assertions.rb new file mode 100644 index 0000000..377aab7 --- /dev/null +++ b/lib/assay/minitest/assertions.rb @@ -0,0 +1,495 @@ +module Assay; end +module Assay::MiniTest + + # This module holds the MiniTest assertion methods for MiniTest + # compatibility. + # + # While it does not provide 100% of MiniTest's assertions at the moment, + # compatibility is very close and will improved with upcoming releases. + # + # TODO: Should we adjust error messages to be like MiniTests ? + # + module Assertions + + # + def assert(truth, msg=nil) + Assertion.assert!(truth, :message=>msg) + end + + # + def refute(untruth, msg=nil) + Assertion.refute!(untruth, :message=>msg) + end + + # + #def assert_alias_method(object, alias_name, original_name, message = nil) + #end + + # + # Passes if actual is like expected, where `like` means satisfyin any one + # of `#===`, `#==`, `#eql?` or `#equal?` calls. + # + # This is not strictly a Test::Unit assertion but is added here to cover + # all of Assay's availabe assertion classes. + # + def assert_alike(exp, act, msg=nil) + LikeAssay.assert!(act, exp, :message=>msg, :backtrace=>caller) + end + + # + # Passes if actual is NOT like expected, where `like` means satisfyin any + # one of `#===`, `#==`, `#eql?` or `#equal?` calls. + # + def refute_alike(exp, act, msg=nil) + LikeAssay.refute!(act, exp, :message=>msg, :backtrace=>caller) + end + + # + # + # + def assert_block(message="assert_block failed.", &block) + ExecutionAssay.assert!(:message=>message, &block) + end + + # + # Passes if `boolean` is either `true` or `false`. + # + def assert_boolean(boolean, message=nil) + BooleanAssay.assert!(boolean, :message=>message) + end + + # + # Passes if `boolean` is neither `true` or `false`. + # + def refute_boolean(boolean, message=nil) + BooleanAssay.refute!(boolean, :message=>message) + end + + # + #def assert_const_defined(object, constant_name, message = nil) + #end + # + #def refute_const_defined(object, constant_name, message = nil) + #end + + # Passes if object is empty. + # + # assert_empty(object) + # + def assert_empty(exp, msg=nil) + EmptyAssay.assert!(exp, :message=>msg, :backtrace=>caller) + end + + # Passes if object is not empty. + # + # refute_empty(object) + # + def refute_empty(exp, msg=nil) + EmptyAssay.refute!(exp, :message=>msg, :backtrace=>caller) + end + + # Passes if expected == +actual. + # + # Note that the ordering of arguments is important, + # since a helpful error message is generated when this + # one fails that tells you the values of expected and actual. + # + # assert_equal 'MY STRING', 'my string'.upcase + # + def assert_equal(exp, act, msg=nil) + EqualAssay.assert!(act, exp, :message=>msg, :backtrace=>caller) + end + + # Passes if expected != actual + # + # refute_equal 'some string', 5 + # + def refute_equal(exp, act, msg=nil) + EqualAssay.refute!(act, exp, :message=>msg, :backtrace=>caller) + end + + # + #def assert_fail_assertion(message = nil) + #end + + # + # Passed if object is +false+. + # + # assert_false(false) + # + def assert_false(exp, msg=nil) + FalseAssay.assert!(exp, :message=>msg, :backtrace=>caller) + end + + # + # Passed if object is not +false+. + # + # refute_false(false) + # + def refute_false(exp, msg=nil) + FalseAssay.refute!(exp, :message=>msg, :backtrace=>caller) + end + + # + # Passes if expected and actual are equal within absolute delta. + # + # assert_in_delta 0.05, (50000.0 / 10**6), 0.00001 + # + def assert_in_delta(exp, act, delta, msg=nil) + WithinAssay.assert!(act, exp, delta, :message=>msg, :backtrace=>caller) + end + + # + # Passes if expected and actual are NOT equal within absolute delta. + # + # refute_in_delta 0.05, (50000.0 / 10**6), 0.00001 + # + def refute_in_delta(exp, act, delta, msg=nil) + WithinAssay.refute!(act, exp, delta, :message=>msg, :backtrace=>caller) + end + + # + # Passes if expected and actual are equal within relative `epsilon`. + # + def assert_in_epsilon(exp, act, epsilon=0.001, message=nil) + #delta = [exp, act].min * epsilon + CloseAssay.assert!(act, exp, epsilon, :message=>message, :backtrace=>caller) + end + + # + # Passes if expected and actual are NOT equal within relative `epsilon`. + # + def refute_in_epsilon(exp, act, epsilon=0.001, message=nil) + #delta = [exp, act].min * epsilon + CloseAssay.refute!(act, exp, epsilon, :message=>message, :backtrace=>caller) + end + + # + # Passes if `collection` contains `member`. + # + def assert_includes(collection, member, message=nil) + IncludeAssay.assert!(collection, member, :message=>message, :backtrace=>caller) + end + + # + # Passes if `collection` does not contain `member`. + # + def refute_includes(collection, member, message=nil) + IncludeAssay.refute!(collection, member, :message=>message, :backtrace=>caller) + end + + # + # Passes if object is an instance of class. + # + # assert_instance_of(String, 'foo') + # + def assert_instance_of(cls, obj, msg=nil) + InstanceAssay.assert!(obj, cls, :message=>msg, :backtrace=>caller) + end + + # + # Passes if object is not an instance of class. + # + # refute_instance_of(String, 500) + # + def refute_instance_of(cls, obj, msg=nil) + InstanceAssay.refute!(obj, cls, :message=>msg, :backtrace=>caller) + end + + # + # Passes if object .kind_of? klass + # + # assert_kind_of(Object, 'foo') + # + def assert_kind_of(cls, obj, msg=nil) + KindAssay.assert!(obj, cls, :message=>msg, :backtrace=>caller) + end + + # + # Passes if object .kind_of? klass + # + # refute_kind_of(Object, 'foo') + # + def refute_kind_of(cls, obj, msg=nil) + KindAssay.refute!(obj, cls, :message=>msg, :backtrace=>caller) + end + + # + # Passes if object matches pattern using `#=~` method. + # + # assert_match(/\d+/, 'five, 6, seven') + # + def assert_match(pattern, string, msg=nil) + MatchAssay.assert!(string, pattern, :message=>msg, :backtrace=>caller) + end + + # + # Passes if object does not match pattern using `#=~` method. + # + # assert_no_match(/two/, 'one 2 three') + # + def refute_match(pattern, string, msg=nil) + MatchAssay.refute!(string, pattern, :message=>msg, :backtrace=>caller) + end + + # + # Passes if object does not match pattern using `#!~` method. + # + # assert_no_match(/two/, 'one 2 three') + # + def assert_no_match(pattern, string, msg=nil) + NoMatchAssay.assert!(string, pattern, :message=>msg, :backtrace=>caller) + end + + # + # Passes if object is +nil+. + # + # assert_nil(nil) + # + def assert_nil(exp, msg=nil) + NilAssay.assert!(exp, :message=>msg, :backtrace=>caller) + end + + # + # Passes if object is not +nil+. + # + # refute_nil(true) + # + def refute_nil(exp, msg=nil) + NilAssay.refute!(exp, :message=>msg, :backtrace=>caller) + end + + # + # Passes if a block outputs matching test to `stdout` or `staderr`. + # + # This does not work _exactly_ like the original MiniTest assertion in + # that it is an *and* condition between the two stdout and stderr, whereas + # the original is and *or* condition. + # + # Note that this assertion translates into two separate underlying assertions, + # so counts for it may be double of what one might expect. + # + def assert_output(stdout=nil, stderr=nil, &block) + StdoutAssay.assert!(stdout, :backtrace=>caller, &block) if stdout + StderrAssay.assert!(stderr, :backtrace=>caller, &block) if stderr + end + + # + # Passes if a block outputs matching test to `stdout` or `staderr`. + # + # This does not work _exactly_ like the original MiniTest assertion in + # that it is an *and* condition between the two stdout and stderr, whereas + # the original is and *or* condition. + # + # Note that this assertion translates into two separate underlying assertions, + # so counts for it may be double of what one might expect. + # + def refute_output(stdout=nil, stderr=nil, &block) + StdoutAssay.refute!(stdout, :backtrace=>caller, &block) if stdout + StderrAssay.refute!(stderr, :backtrace=>caller, &block) if stderr + end + + # + # Like {#assert_output} but ensures no output. + # + def assert_silent(msg=nil, &block) + SilentAssay.assert!(:message=>msg, :backtrace=>caller, &block) + end + + # + # Like {#refute_output} but ensures some output. + # + def refute_silent(msg=nil, &block) + SilentAssay.refute!(:message=>msg, :backtrace=>caller, &block) + end + + # + # Passes it +predicate+ sent to object returns postively. + # + # assert_predicate(10, :even?) + # + def assert_predicate(object, predicate, message=nil) + ExecutionAssay.assert!(:message=>message, :backtrace=>caller) do + object.__send__(predicate) + end + end + + # + # Passes it +predicate+ sent to object returns negatively. + # + # refute_predicate(10, :odd?) + # + def refute_predicate(object, predicate, message=nil) + ExecutionAssay.refute!(:message=>message, :backtrace=>caller) do + object.__send__(predicate) + end + end + + # + # Passes if +object+ respond_to? +methods+. + # + # assert_respond_to 'bugbear', :slice + # + def assert_respond_to(reciever, method, msg=nil) + RespondAssay.assert!(reciever, method, :message=>msg, :backtrace=>caller) + end + alias_method :assert_responds_to, :assert_respond_to + + # + # Passes if +object+ does not respond_to? +methods+. + # + # refute_respond_to 'bugbear', :slice + # + def refute_respond_to(reciever, method, msg=nil) + RespondAssay.refute!(reciever, method, :message=>msg, :backtrace=>caller) + end + + # + # Passes if +expected+ .eql? +actual+. + # + # Note that the ordering of arguments is important, + # since a helpful error message is generated when this + # one fails that tells you the values of expected and actual. + # + # assert_equivalent 'MY STRING', 'my string'.upcase + # + def assert_equivalent(exp, act, msg=nil) + EqualityAssay.assert!(act, exp, :message=>msg, :backtrace=>caller) + end + + # + # Passes if +criterion+ is NOT equivalent to +actual+ as tested using `#eql?`. + # + # refute_equivalent 'some string', 5 + # + def refute_equivalent(criterion, act, msg=nil) + EqualityAssay.refute!(act, criterion, :message=>msg, :backtrace=>caller) + end + + # + # + # + def assert_operator(receiver, operator, operand, message=nil) + ExecutionAssay.assert!(:message=>message, :backtrace=>caller) do + receiver.__send__(operator, operand) + end + end + + # + # + # + def refute_operator(receiver, operator, operand, message=nil) + ExecutionAssay.refute!(:message=>message, :backtrace=>caller) do + receiver.__send__(operator, operand) + end + end + + # + # Passes if the block raises given exception(s). + # + # assert_raises RuntimeError do + # raise 'Boom!!!' + # end + # + def assert_raises(*exceptions, &block) + msg = (Exception === exceptions.last ? exceptions.pop : nil) + RaiseAssay.assert!(*exceptions, :message=>msg, :backtrace=>caller, &block) + end + + # + # Passes if the block *does not* raise given exception(s). + # + # refute_raises RuntimeError do + # raise 'Boom!!!' + # end + # + def refute_raises(*exceptions, &block) + msg = (Exception === exceptions.last ? exceptions.pop : nil) + RaiseAssay.refute!(*exceptions, :message=>msg, :backtrace=>caller, &block) + end + + # + # Passes if the block yields successfully. + # + # refute_nothing_raised "Couldn't do the thing" do + # do_the_thing + # end + # + def assert_nothing_raised(msg=nil, &block) + RescueAssay.refute!(Exception, :message=>msg, :backtrace=>caller, &block) + end + + # + # Passes if the block yields successfully. + # + # refute_nothing_raised "Couldn't do the thing" do + # do_the_thing + # end + # + def refute_nothing_raised(msg=nil, &block) + RescueAssay.assert!(Exception, :message=>msg, :backtrace=>caller, &block) + end + + # + # Passes if actual is the same exact object as expected. + # + # assert_same(object, object) + # + def assert_same(exp, act, msg=nil) + IdentityAssay.assert!(act, exp, :message=>msg, :backtrace=>caller) + end + + # + # Passes if actual is not the same exact object as expected. + # + # refute_same(object, other) + # + def refute_same(exp, act, msg=nil) + IdentityAssay.refute!(act, exp, :message=>msg, :backtrace=>caller) + end + + # + #def assert_send(send_array, message=nil) + #end + + # + # Passes if the block throws `expected` object. + # + # assert_throw :done do + # throw :done + # end + # + def assert_throws(expected, msg=nil, &blk) + ThrowAssay.assert!(expected, :message=>msg, :backtrace=>caller, &blk) + end + + # + # Passes if the block does not throws `expected` object. + # + # refute_throws :done do + # throw :chimp + # end + # + def refute_throws(expected, msg=nil, &blk) + ThrowAssay.refute!(expected, :message=>msg, :backtrace=>caller, &blk) + end + + # + # Passed if object is +true+. + # + def assert_true(exp, msg=nil) + TrueAssay.assert!(exp, :message=>msg, :backtrace=>caller) + end + + # + # Passed if object is not +true+. + # + # refute_true(false) + # + def refute_true(exp, msg=nil) + TrueAssay.refute!(exp, :message=>msg, :backtrace=>caller) + end + + end + +end diff --git a/lib/assay/minitest/extensions.rb b/lib/assay/minitest/extensions.rb new file mode 100644 index 0000000..7099eaf --- /dev/null +++ b/lib/assay/minitest/extensions.rb @@ -0,0 +1,496 @@ +module Assay; end +module Assay::MiniTest + + # This module provides extensions for MiniTest compatiblity. + # + # The set is not fully compataible, but provides most of MiniTest + # extensions. + # + # Compatability will improve with time. + # + module Extensions + + # Passes it operator with optional argument returns successfully. + # + # 10.must_be :>, 4 + # 10.must_be :even? + # + # @raise ExecutionAssay + # + def must_be(operator, argument=nil, msg=nil) + if argument + ExecutionAssay.assert!(:message=>msg) do + __send__(operator, argument) + end + else + ExecutionAssay.assert!(:message=>msg) do + __send__(operator) + end + end + end + + # + # Passes it operator with optional argument returns negatively. + # + # 10.wont_be :>, 20 + # 10.wont_be :odd? + # + # @raise ExecutionAssay + # + def wont_be(operator, argument=nil, msg=nil) + if argument + ExecutionAssay.refute!(:message=>msg) do + self.__send__(operator, argument) + end + else + ExecutionAssay.refute!(:message=>msg) do + self.__send__(operator) + end + end + end + + # + # Passes if object is like criterion. + # + # object.must_be_like(criterion) + # + # @raise LikeAssay + # + def must_be_like(exp, msg=nil) + LikeAssay.assert!(self, exp, :message=>msg, :backtrace=>caller) + end + + # + # Passes if object is not like criterion using {CompareAssay}. + # + # object.wont_be_like(criterion) + # + # @raise LikeAssay + # + def wont_be_like(exp, msg=nil) + LikeAssay.refute!(self, exp, :message=>msg, :backtrace=>caller) + end + + # + # Passes if expected and actual are equal within absolute delta tolerance. + # + # 0.05.must_be_within_delta (50000.0 / 10**6), 0.00001 + # + # @raise WithinAssay + # + def must_be_within_delta(exp, delta, msg=nil) + WithinAssay.assert!(self, exp, delta, :message=>msg, :backtrace=>caller) + end + + # + # Passes if expected and actual are NOT equal within absolute delta tolerance. + # + # 0.05.wont_be_within_delta (50000.0 / 10**6), 0.00001 + # + # @raise WithinAssay + # + def wont_be_within_delta(exp, delta, msg=nil) + WithinAssay.refute!(self, exp, delta, :message=>msg, :backtrace=>caller) + end + + # + # Passes if expected and actual are equal within relative epsilon tolerance. + # + # 0.05.must_be_within_epsilon (50000.0 / 10**6), 0.00001 + # + # @raise CloseAssay + # + def must_be_within_epsilon(exp, epsilon, msg=nil) + CloseAssay.assert!(self, exp, epsilon, :message=>msg, :backtrace=>caller) + end + + # + # Passes if expected and actual are NOT equal within relative epsilon tolerance. + # + # 0.05.wont_be_within_epsilon (50000.0 / 10**6), 0.00001 + # + # @raise CloseAssay + # + def wont_be_within_epsilon(exp, epsilon, msg=nil) + WithinAssay.refute!(self, exp, epsilon, :message=>msg, :backtrace=>caller) + end + + # + # Passes if object is empty. + # + # object.must_be_empty + # + # @raise EmptyAssay + # + def must_be_empty(msg=nil) + EmptyAssay.assert!(self, :message=>msg, :backtrace=>caller) + end + + # + # Passes if object is not empty. + # + # object.wont_be_empty + # + # @raise EmptyAssay + # + def wont_be_empty(msg=nil) + EmptyAssay.refute!(self, :message=>msg, :backtrace=>caller) + end + + # + # Passes if expected == +actual. + # + # Note that the ordering of arguments is important, + # since a helpful error message is generated when this + # one fails that tells you the values of expected and actual. + # + # 'MY STRING'.must_equal('my string'.upcase) + # + # @raise EqualAssay + # + def must_equal(exp, msg=nil) + EqualAssay.assert!(self, exp, :message=>msg, :backtrace=>caller) + end + + # + # Passes if expected != actual + # + # 'some string'.wont_equal('some other string') + # + # @raise EqualAssay + # + def wont_equal(exp, msg=nil) + EqualAssay.refute!(self, exp, :message=>msg, :backtrace=>caller) + end + + # + # Passes if method call returns successfully. + # + # "string".must_send([:upcase], "Doesn't upcase!") + # + # @raise ExecutionAssay + # + def must_send(send_array, msg=nil) + ExecutionAssay.assert!(:message=>msg, :backtrace=>caller) do + self.__send__(*send_array) + end + end + + # + # Passes if method call does not return successfully. + # + # "string".wont_send([:upcase], "Damn you, Uppercase!") + # + # @raise ExecutionAssay + # + def wont_send(send_array, msg=nil) + ExecutionAssay.refute!(:message=>msg, :backtrace=>caller) do + self.__send__(*send_array) + end + end + + # + # Passes if the block yields successfully. + # + # 5.must_satisfy{ |x| x > 3 } + # + # @raise ExecutionAssay + # + def must_satisfy(msg=nil, &block) + ExecutionAssay.assert!(self, :message=>msg, :backtrace=>caller, &block) + end + + # + # Passes if the block does not yield successfully. + # + # 5.wont_satisfy{ |x| x < 3 } + # + # @raise ExecutionAssay + # + def wont_satisfy(msg=nil, &block) + ExecutionAssay.refute!(self, :message=>msg, :backtrace=>caller, &block) + end + + # + # Passed if object is +false+. + # + # @raise FalseAssay + # + def must_be_false(msg=nil) + FalseAssay.assert!(self, :message=>msg, :backtrace=>caller) + end + + # + # Passed if object is not +false+. + # + # assert_not_false(false) + # + # @raise FalseAssay + # + def wont_be_false(msg=nil) + FalseAssay.refute!(self, :message=>msg, :backtrace=>caller) + end + + # + # Passes if `self` is the same exact object as expected. + # + # object.must_be_same_as(object) + # + # @raise IdentityAssay + # + def must_be_same_as(exp, msg=nil) + IdentityAssay.assert!(self, exp, :message=>msg, :backtrace=>caller) + end + + # + # Passes if actual is not the same exact object as expected. + # + # object.wont_be_same_as(other) + # + # @raise IdentityAssay + # + def wont_be_same_as(exp, msg=nil) + IdentityAssay.refute!(self, exp, :message=>msg, :backtrace=>caller) + end + + # + # Passes if object is an instance of class. + # + # 'foo'.must_be_instance_of(String) + # + # @raise InstanceAssay + # + def must_be_instance_of(cls, msg=nil) + InstanceAssay.assert!(self, cls, :message=>msg, :backtrace=>caller) + end + + # + # Passes if object is not an instance of class. + # + # 'foo'.wont_be_instance_of(Integer) + # + # @raise InstanceAssay + # + def wont_be_instance_of(cls, msg=nil) + InstanceAssay.refute!(self, cls, :message=>msg, :backtrace=>caller) + end + + # + # Passes if object is a kind of class. + # + # assert_kind_of(Object, 'foo') + # + # @raise KindAssay + # + def must_be_kind_of(cls, msg=nil) + KindAssay.assert!(self, cls, :message=>msg, :backtrace=>caller) + end + + # + # Passes if object is not a kind of class. + # + # assert_not_kind_of(Object, 'foo') + # + # @raise KindAssay + # + def wont_be_kind_of(cls, msg=nil) + KindAssay.refute!(self, cls, :message=>msg, :backtrace=>caller) + end + + # + # Passes if object matches pattern using `#=~` method. + # + # 'one 2 three'.must_match(/two/) + # + # @raise MatchAssay + # + def must_match(exp, msg=nil) + MatchAssay.assert!(self, exp, :message=>msg, :backtrace=>caller) + end + + # + # Passes if object does not match pattern using `#=~` method. + # + # 'one 2 three'.wont_match(/two/) + # + # @raise MatchAssay + # + def wont_match(exp, msg=nil) + MatchAssay.refute!(self, exp, :message=>msg, :backtrace=>caller) + end + + # + # Passed if object is +nil+. + # + # @raise NilAssay + # + def must_be_nil(msg=nil) + NilAssay.assert!(self, :message=>msg, :backtrace=>caller) + end + + # + # Passed if object is not +nil+. + # + # assert_not_nil(true) + # + # @raise NilAssay + # + def wont_be_nil(msg=nil) + NilAssay.refute!(self, :message=>msg, :backtrace=>caller) + end + + # + # Passes if the procedure raises a given exception. + # + # lambda{ raise 'Boom!!!' }.must_raise(RuntimeError) + # + # @raise RaiseAssay + # + def must_raise(exp, msg=nil, call=nil) + RaiseAssay.assert!(exp, msg=nil, call=nil, &self) + end + + # + # Passes if the procedure *does not* raise a given exceptions. + # + # lambda{ raise 'Boom!!!' }.wont_raise(IOError) + # + # @raise RaiseAssay + # + def wont_raise(exp, msg=nil, call=nil) + RaiseAssay.refute!(exp, msg, call, &self) + end + + # + # Passes if +object+ respond_to? +methods+. + # + # 'bugbear'.must_respond_to(:slice) + # + # @raise RespondAssay + # + def must_respond_to(method, msg=nil) + RespondAssay.assert!(self, method, :message=>msg, :backtrace=>caller) + end + + # + # Passes if +object+ does not respond_to? +methods+. + # + # 'bugbear'.wont_respond_to(:slice) + # + # @raise RespondAssay + # + def wont_respond_to(method, msg=nil) + RespondAssay.refute!(self, method, :message=>msg, :backtrace=>caller) + end + + # + # Passes if `criterion.eql?(actual)`. + # + # Note that the ordering of arguments is important, + # since a helpful error message is generated when this + # one fails that tells you the values of expected and actual. + # + # 'MY STRING'.must_be_equivalent_to('my string'.upcase) + # + # @raise EqualityAssay + # + def must_be_equivalent_to(criterion, msg=nil) + EqualityAssay.assert!(self, criterion, :message=>msg, :backtrace=>caller) + end + + alias_method :must_eql, :must_be_equivalent_to + + # + # Passes if NOT `criterion.eql?(actual)`. + # + # 'MY STRING'.wont_be_equivalent_to('some other string') + # + # @raise EqualityAssay + # + def wont_be_equivalent_to(criterion, msg=nil) + EqualityAssay.refute!(self, criterion, :message=>msg, :backtrace=>caller) + end + + alias_method :wont_eql, :wont_be_equivalent_to + + # + # Passes if the block throws expected_symbol + # + # assert_throws :done do + # throw :done + # end + # + # @raise ThrowAssay + # + def must_throw(sym, msg=nil) + ThrowAssay.assert!(sym, :message=>msg, :backtrace=>caller, &self) + end + + # + # Passes if the block throws expected_symbol + # + # refute_throws :done do + # throw :chimp + # end + # + # @raise ThrowAssay + # + def wont_throw(sym, msg=nil) + ThrowAssay.refute!(sym, :message=>msg, :backtrace=>caller, &self) + end + + # + # Passed if object is +true+. + # + # object.must_be_true + # + # @raise TrueAssay + # + def must_be_true(msg=nil) + TrueAssay.assert!(self, :message=>msg, :backtrace=>caller) + end + + # + # Passed if object is not +true+. + # + # object.wont_be_true + # + # @raise TrueAssay + # + def wont_be_true(msg=nil) + TrueAssay.refute!(self, :message=>msg, :backtrace=>caller) + end + + # + # Passes if `self.include?(object)`. + # + # @raise IncludeAssay + # + def must_include(object, msg=nil) + IncludeAssay.assert!(self, object, :message=>msg, :backtrace=>caller) + end + + # + # Passes if `self.include?(object)`. + # + # @raise IncludeAssay + # + def wont_include(object, msg=nil) + IncludeAssay.refute!(self, object, :message=>msg, :backtrace=>caller) + end + + # + # Passes if output matches +pattern+. + # + # @example + # proc{ puts "fun!" }.must_output('fun!') + # + # @raise OutputAssay + # + def must_output(pattern, msg=nil) + OutputAssay.assert!(pattern, :message=>msg, :backtrace=>caller, &self) + end + + end + +end diff --git a/lib/assay/more_assay.rb b/lib/assay/more_assay.rb index 5e1c051..ff96b28 100644 --- a/lib/assay/more_assay.rb +++ b/lib/assay/more_assay.rb @@ -14,5 +14,11 @@ def self.pass?(subject, criterion) subject > criterion end -end + # + # Error message, e.g. `5 > 3`. + # + def self.assert_message(subject, criterion) + standard_message(subject, criterion) + end +end diff --git a/lib/assay/more_equal_assay.rb b/lib/assay/more_equal_assay.rb index 4594f06..73d69b0 100644 --- a/lib/assay/more_equal_assay.rb +++ b/lib/assay/more_equal_assay.rb @@ -21,5 +21,11 @@ def self.pass?(subject, criterion) subject >= criterion end -end + # + # Error message, e.g. `5 >= 3`. + # + def self.assert_message(subject, criterion) + standard_message(subject, criterion) + end +end diff --git a/lib/assay/rspec.rb b/lib/assay/rspec.rb new file mode 100644 index 0000000..0d4beaa --- /dev/null +++ b/lib/assay/rspec.rb @@ -0,0 +1,13 @@ +require_relative '../assay' + +require_relative 'rspec/matchers' +require_relative 'rspec/have' +require_relative 'rspec/should' +require_relative 'rspec/expect' +require_relative 'rspec/operatics' + +# RSpec-compatible matcher methods (`eq`, `be_nil`, `expect`, ...), to mix +# into a test scope. +module Assay::Matchers + include Assay::RSpec::Matchers +end diff --git a/lib/assay/rspec/expect.rb b/lib/assay/rspec/expect.rb new file mode 100644 index 0000000..c808158 --- /dev/null +++ b/lib/assay/rspec/expect.rb @@ -0,0 +1,151 @@ +module Assay::RSpec + + # Wraps the target of an expectation. + # + # @example + # expect(something) # => Expect + # + # # used with `to` + # expect(actual).to eq(3) + # + # # with `to_not` + # expect(actual).to_not eq(3) + # + class Expect + + # @api private + def initialize(target) + @target = target + end + + # Runs the given expectation, passing if `matcher` returns true. + # + # @example + # expect(value).to eq(5) + # expect { perform }.to raise_error + # + # @param [Matcher] + # matcher + # + # @param [String] message optional message to display when the expectation fails + # + # @return [Boolean] true if the expectation succeeds (else raises) + # + # @see RSpec::Matchers + # + def to(matcher=nil, message=nil, &block) + #prevent_operator_matchers(:to, matcher) + handle_positive_matcher(@target, matcher, message, &block) + end + + # Runs the given expectation, passing if `matcher` returns false. + # + # @example + # expect(value).to_not eq(5) + # expect(value).not_to eq(5) + # + # @param [Matcher] + # matcher + # + # @param [String] message optional message to display when the expectation fails + # + # @return [Boolean] false if the negative expectation succeeds (else raises) + # + # @see RSpec::Matchers + # + def to_not(matcher=nil, message=nil, &block) + #prevent_operator_matchers(:to_not, matcher) + handle_negative_matcher(@target, matcher, message, &block) + end + + alias :not_to :to_not + + private + + #def prevent_operator_matchers(verb, matcher) + # return if matcher + # + # raise ArgumentError, "The expect syntax does not support operator matchers, " + + # "so you must pass a matcher to `##{verb}`." + #end + + # + # @todo how to customize the message? + # + def handle_positive_matcher(actual, matcher, message=nil, &block) + check_message(message) + + #::RSpec::Matchers.last_should = :should + #::RSpec::Matchers.last_matcher = matcher + + if block + actual = block.call(actual) + end + + #return ::RSpec::Matchers::BuiltIn::PositiveOperatorMatcher.new(actual) if matcher.nil? + + return Operatics.new(actual) if matcher.nil? + + matcher =~ actual + + #match = matcher.matches?(actual, &block) + #return match if match + + #message ||= matcher.respond_to?(:failure_message_for_should) ? + # matcher.failure_message_for_should : + # matcher.failure_message + + #if matcher.respond_to?(:diffable?) && matcher.diffable? + # ::RSpec::Expectations.fail_with message, matcher.expected, matcher.actual + #else + # ::RSpec::Expectations.fail_with message + #end + end + + # + # @todo how to customize the message? + # + def handle_negative_matcher(actual, matcher, message=nil, &block) + check_message(message) + + #::RSpec::Matchers.last_should = :should_not + #::RSpec::Matchers.last_matcher = matcher + + if block + actual = block.call(actual) + end + + #return ::RSpec::Matchers::BuiltIn::NegativeOperatorMatcher.new(actual) if matcher.nil? + + return Operatics.new(actual, true) if matcher.nil? + + matcher !~ actual + + #match = matcher.respond_to?(:does_not_match?) ? + # !matcher.does_not_match?(actual, &block) : + # matcher.matches?(actual, &block) + #return match unless match + + #message ||= matcher.respond_to?(:failure_message_for_should_not) ? + # matcher.failure_message_for_should_not : + # matcher.negative_failure_message + + #if matcher.respond_to?(:diffable?) && matcher.diffable? + # ::RSpec::Expectations.fail_with message, matcher.expected, matcher.actual + #else + # ::RSpec::Expectations.fail_with message + #end + end + + def message_must_be_string(msg) + "WARNING: ignoring the provided expectation message argument " + + "(#{msg.inspect}) since it is not a string." + end + + def check_message(msg) + ::Kernel.warn message_must_be_string(msg) unless msg.nil? || msg.is_a?(String) + end + + end + +end diff --git a/lib/assay/rspec/have.rb b/lib/assay/rspec/have.rb new file mode 100644 index 0000000..a569d86 --- /dev/null +++ b/lib/assay/rspec/have.rb @@ -0,0 +1,201 @@ +module Assay::RSpec + + # Delegate to Have Assays. + # + class Have + + attr :expected + + attr :collection_name + + attr :relation + + # + # Initialize new Have delegator. + # + def initialize(expected, relation=:exactly) + @expected = case expected + when :no then 0 + when String then expected.to_i + else expected + end + @relation = relation + @collection_name = nil + end + + # + # @param [#size,#length,#count] collection_or_owner + # + def collection(collection_or_owner) + if collection_or_owner.respond_to?(@collection_name) + collection_or_owner.__send__(@collection_name, *@args, &@block) + elsif query_method(collection_or_owner) + collection_or_owner + else + collection_or_owner.__send__(@collection_name, *@args, &@block) + end + end + + # + # + # + def query_method(collection) + [:size, :length, :count].detect {|m| collection.respond_to?(m)} + end + + # + # + # + def method_missing(method, *args, &block) + @collection_name = method + @args = args + @block = block + + case @relation + when :at_least + Assay::RSpec::HaveAtLeastAssay.assertor(self) + when :at_most + Assay::RSpec::HaveAtMostAssay.assertor(self) + else + Assay::RSpec::HaveExactlyAssay.assertor(self) + end + end + + # + # + module Helpers + + # + # + # + def collection_set(collection_or_owner, have) + collection = have.collection(collection_or_owner) + query_method = query_method(collection) + + raise not_a_collection(have) unless query_method + + actual = collection.__send__(query_method) + + return collection, query_method, actual + end + + # + # Return the actual size of the collection. + # + def collection_actual(collection_or_owner, have) + collection_set(collection_or_owner, have).last + end + + # + # Which size method to use: `size`, `length` or `count`. + # + def query_method(collection) + [:size, :length, :count].detect {|m| collection.respond_to?(m)} + end + + # + # Message to use when collection doesn't respond to `size`, `length` or `count`. + # + def not_a_collection(have) + "expected #{have.collection_name} to be a collection but it does not respond to #length, #size or #count" + end + + # + # TODO: use when verbose error message mode + # + def self.assert_description(collection_or_owner, have) + collection, method, actual = collection_set(collection_or_owner, have) + "expected #{have.relation} #{have.expected} #{have.collection_name}, got #{actual}" + end + + # + # + # + def self.refute_descrptipon(collection_or_owner, have) + collection, method, actual = collection_set(collection_or_owner, have) + "expected not to have #{have.relation} #{have.expected} #{have.collection_name}, got #{actual}" + end + + end + + end + + # + # + class HaveExactlyAssay < EqualAssay + + extend Have::Helpers + + register :have + + # + # + # + def self.pass?(collection_or_owner, have) + actual = collection_actual(collection_or_owner, have) + super(actual, have.expected) + end + + # + # Error message for have equal assertion. + # + def self.assert_message(collection_or_owner, have) + actual = collection_actual(collection_or_owner, have) + super(actual, have.expected) + end + + end + + # + # + class HaveAtLeastAssay < MoreEqualAssay + + extend Have::Helpers + + register :have_at_least + + # + # + # + def self.pass?(collection_or_owner, have) + actual = collection_actual(collection_or_owner, have) + super(actual, have.expected) + end + + # + # + # + def self.assert_message(collection_or_owner, have) + actual = collection_actual(collection_or_owner, have) + super(actual, have.expected) + end + + end + + # + # + class HaveAtMostAssay < LessEqualAssay + + extend Have::Helpers + + register :have_at_most + + # + # + # + def self.pass?(collection_or_owner, have) + actual = collection_actual(collection_or_owner, have) + super(actual, have.expected) + end + + # + # + # + def self.assert_message(collection_or_owner, have) + actual = collection_actual(collection_or_owner, have) + super(actual, have.expected) + end + + end + +end diff --git a/lib/assay/rspec/matchers.rb b/lib/assay/rspec/matchers.rb new file mode 100644 index 0000000..674e5da --- /dev/null +++ b/lib/assay/rspec/matchers.rb @@ -0,0 +1,272 @@ +module Assay; end +module Assay::RSpec + + # This module provides matchers for RSpec-compatiblity. + # + # The set is not fully compataible, but provides most RSpec matchers. + # The most notable exlusion for the moment is the `have` matchers. + # + # Compatability will improve with time. Feel _obligated_ to submit a + # patch if you really need it. ;) + # + # @see https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers + # + module Matchers + + #def self.included(base) + # @_once ||= require_relative('should').nil? + #end + + #def self.extended(base) + # @_once ||= require_relative('should').nil? + #end + + # Passes if the expected and actual are alike. + # + # object.should be_like(criterion) + # + # There is no equivalant for this in RSpec, we simply add it + # here to cover all Assays available. + # + # @raise LikeAssay + # + def be_like(criterion) + LikeAssay.assertor(criterion) + end + + # Passes if expected and actual are nto equal within delta tolerance. + # + # value.should be_close(delta, criterion) + # + # @raise WithinAssay + # + def be_close(delta, criterion) + WithinAssay.assertor(criterion, delta) + end + + # Passes if object is empty. + # + # object.should be_empty + # + # @raise EmptyAssay + # + def be_empty + EmptyAssay.assertor + end + + # Passes if +expected+ == +actual+. + # + # 'MY STRING'.should equate_to('my string'.upcase) + # 'MY STRING'.should_not equate_to('another string') + # + # This matcher is not supported by RSpec, but is added so that the + # EqualityAssay has an explict matcher available. + # + # @raise EqualityAssay + # + def equate_to(exp) + EqualityAssay.assertor(exp) + end + + # + # Passes if block is satisfied given target object as argument. + # + # 5.should satisfy{ |n| n > 3} + # + # @raise ExecutionAssay + # + def satisfy(&block) + ExecutionAssay.assertor(&block) + end + + # + # Passed if object is +false+. + # + # value.should be_false + # + # @raise FalseAssay + # + def be_false + FalseAssay.assertor + end + + # + # Passes if actual is the same exact object as expected. + # + # object.should be_identical_to(object) + # + # @raise IdentityAssay + # + def equal(obj) + IdentityAssay.assertor(obj) + end + + alias :be_identical_to :equal + + # + # Passes if `actual == expected`. + # + # object.should eq(object) + # + # @raise EqualAssay + # + def eq(obj) + EqualAssay.assertor(obj) + end + + # + # Passes if object is an instance of class. + # + # object.should be_instance_of(class) + # + # @raise InstanceAssay + # + def be_instance_of(cls) + InstanceAssay.assertor(cls) + end + + alias :be_an_instance_of :be_instance_of + + # + # Pass if object is a kind of class. + # + # object.should be_kind_of(class) + # + # @raise KindAssay + # + def be_kind_of(cls) + KindAssay.assertor(cls) + end + + alias :be_a_kind_of :be_kind_of + alias :be_a :be_kind_of + alias :be_an :be_kind_of + + # + # Pass if object matches pattern using `#=~` method. + # + # object.should match(regexp) + # + # @raise MatchAssay + # + def match(regexp) + MatchAssay.assertor(regexp) + end + + # + # Pass if object is +nil+. + # + # value.should be_nil + # + # @raise NilAssay + # + def be_nil + NilAssay.assertor + end + + # + # Pass if an exception is raised. + # + # lambda { do_something_risky }.should raise_error + # lambda { do_something_risky }.should raise_error(PoorRiskDecisionError) + # + # @raise RaiseAssay + # + # @todo Support for message matching ? + # + def raise_error(exception=Exception) + RaiseAssay.assertor(exception) + end + + # + # Pass if object responds to message. + # + # object.should respond_to(:method_name) + # + # @raise RespondAssay + # + def respond_to(method) + RespondAssay.assertor(method) + end + + # + # Pass if two objects are equal using `#eql?` method. + # + # object1.should eql(object2) + # + # @raise EqualityAssay + # + def eql(exp) + EqualityAssay.assertor(exp) + end + + # + # Pass if procedure throws a specified symbol. + # + # lambda { do_something_risky }.should throw_symbol + # lambda { do_something_risky }.should throw_symbol(:that_was_risky) + # + # @raise ThrowAssay + # + # @todo Support for throw argument. (Does RSpec even support this?) + # + def throw_symbol(sym=nil) #, arg=nil) + ThrowAssay.assertor(sym) + end + + # + # Passed if object is +true+. + # + # object.should be_true + # + # @raise TrueAssay + # + def be_true + TrueAssay.assertor + end + + # + # + # + def have(n) + Have.new(n) + end + + alias :have_exactly :have + + # + # + # + def have_at_least(n) + Have.new(n, :at_least) + end + + # + # + # + def have_at_most(n) + Have.new(n, :at_most) + end + + # + # Wrap the target of an expectation, a value or a block. + # + # expect(actual).to eq(3) + # expect{ perform }.to raise_error(ArgumentError) + # + def expect(*target, &block) + case + when block && !target.empty? + raise ArgumentError, "expect takes a value or a block, not both" + when block + Expect.new(block) + when target.size == 1 + Expect.new(target.first) + else + raise ArgumentError, "wrong number of arguments (given #{target.size}, expected 1)" + end + end + + end + +end diff --git a/lib/assay/rspec/operatics.rb b/lib/assay/rspec/operatics.rb new file mode 100644 index 0000000..cf9c7fb --- /dev/null +++ b/lib/assay/rspec/operatics.rb @@ -0,0 +1,57 @@ +module Assay::RSpec + + # Operatics delegates operator based assertions for execpt.rb. + # + class Operatics < Object + instance_methods.each{ |m| undef_method m if m.to_s =~ /^\W/ } + + # + def initialize(target, negate=false) + @target = target + @negate = negate + end + + private + + # + def method_missing(op, *a, &b) + super(op, *a, &b) if op.to_s =~ /^\w/ + + if @negate + refute!(op, *a, &b) + else + assert!(op, *a, &b) + end + end + + # + def assert!(op, *a, &b) + if assay = Assertion.by_operator(op) + return assay.assert!(@target, *a, &b) + else + ::Kernel.assert(@target.__send__(op, *a, &b), ::Assertion, "#{@target.inspect} #{op} #{a.map{ |x| x.inspect }.join(', ')}", caller) + end + end + + # + def refute!(op, *a, &b) + if assay = Assertion.by_operator(op) + return assay.refute!(@target, *a, &b) + else + ::Kernel.refute(@target.__send__(op, *a, &b), ::Assertion, "! #{@target.inspect} #{op} #{a.map{ |x| x.inspect }.join(', ')}", caller) + end + end + + # + def generic?(op) + @target.method(op).owner == ::Kernel + end if ::Method.method_defined?(:owner) + + # + def generic?(op) + @target.method(op).to_s.include?('(Kernel)') + end unless ::Method.method_defined?(:owner) + + end + +end diff --git a/lib/assay/rspec/should.rb b/lib/assay/rspec/should.rb new file mode 100644 index 0000000..7a8ea50 --- /dev/null +++ b/lib/assay/rspec/should.rb @@ -0,0 +1,49 @@ +module Assay::RSpec + + # The Should module is included into BasicObject to provide + # the needed assertion interface that RSpec utilizes. Namely, the + # `should` and `should_not` methods. + # + module Should + + # + # Use `should` nomenclature for assertions. + # + # 10.should be_kind_of(Integer) + # + def should(matcher) + matcher =~ self + end + + # + # Also, `should_not` nomenclature for assertions. + # + # 10.should_not be_kind_of?(Integer) + # + def should_not(matcher) + matcher !~ self + end + + # + # + # + def should=(value) + EqualAssay.assert!(self, value) + end + + # + # + # + def should_not=(value) + EqualAssay.refute!(self, value) + end + + end + +end + + +class BasicObject # Object ? + include ::Assay::RSpec::Should +end + diff --git a/lib/assay/testunit.rb b/lib/assay/testunit.rb new file mode 100644 index 0000000..e4804ec --- /dev/null +++ b/lib/assay/testunit.rb @@ -0,0 +1,9 @@ +require_relative '../assay' + +require_relative 'testunit/assertions' + +# Test::Unit-compatible assertion methods (`assert_equal`, ...), to mix +# into a test scope. +module Assay::Assertions + include Assay::TestUnit::Assertions +end diff --git a/lib/assay/testunit/assertions.rb b/lib/assay/testunit/assertions.rb new file mode 100644 index 0000000..8bfe7ff --- /dev/null +++ b/lib/assay/testunit/assertions.rb @@ -0,0 +1,484 @@ +module Assay; end +module Assay::TestUnit + + # This module holds the Test::Unit assertion methods for Test::Unit + # compatibility. + # + # While it does not provide 100% of Test::Unit assertions at the moment, + # compatibility will improved with upcoming releases. + # + # @see http://test-unit.rubyforge.org/test-unit/en/ + # + # @todo Should we adjust error message to be like Test::Units ? + # + module Assertions + + # + #def assert_alias_method(object, alias_name, original_name, message = nil) + #end + + # + # Passes if actual is like expected, where `like` means satisfyin any one + # of `#===`, `#==`, `#eql?` or `#equal?` calls. + # + # This is not strictly a Test::Unit assertion but is added here to cover + # all of Assay's availabe assertion classes. + # + def assert_alike(exp, act, msg=nil) + LikeAssay.assert!(act, exp, :message=>msg, :backtrace=>caller) + end + + # + # Passes if actual is NOT like expected, where `like` means satisfyin any + # one of `#===`, `#==`, `#eql?` or `#equal?` calls. + # + def assert_not_alike(exp, act, msg=nil) + LikeAssay.refute!(act, exp, :message=>msg, :backtrace=>caller) + end + + # + # + # + def assert_block(message="assert_block failed.", &block) + ExecutionAssay.assert!(:message=>message, &block) + end + + # + # Passes if `boolean` is either `true` or `false`. + # + def assert_boolean(boolean, message=nil) + BooleanAssay.assert!(boolean, :message=>message) + end + + # + # Passes if `boolean` is not either `true` or `false`. + # + def assert_not_boolean(boolean, message=nil) + BooleanAssay.refute!(boolean, :message=>message) + end + + # Passes if `object` satisify compaision by `operator`. + # + def assert_compare(receiver, operator, operand, message=nil) + case operator.to_sym + when :< + LessAssay.assert!(receiver, operand, :message=>message, :backtrace=>caller) + when :<= + LessEqualAssay.assert!(receiver, operand, :message=>message, :backtrace=>caller) + when :> + MoreAssay.assert!(receiver, operand, :message=>message, :backtrace=>caller) + when :>= + MoreEqualAssay.assert!(receiver, operand, :message=>message, :backtrace=>caller) + when :== + EqualAssay.assert!(operand, receiver, :message=>message, :backtrace=>caller) + else + raise ArgumentError, "comparision operator must be one of <, <=, >, >= or '=='" + end + end + + # + # + # + #def assert_const_defined(object, constant_name, message=nil) + #end + + # + # + # + #def assert_not_const_defined(object, constant_name, message=nil) + #end + + # Passes if object is empty. + # + # assert_empty(object) + # + def assert_empty(exp, msg=nil) + EmptyAssay.assert!(exp, :message=>msg, :backtrace=>caller) + end + + # Passes if object is not empty. + # + # refute_empty(object) + # + def assert_not_empty(exp, msg=nil) + EmptyAssay.refute!(exp, :message=>msg, :backtrace=>caller) + end + + # Passes if expected == +actual. + # + # Note that the ordering of arguments is important, + # since a helpful error message is generated when this + # one fails that tells you the values of expected and actual. + # + # assert_equal 'MY STRING', 'my string'.upcase + # + def assert_equal(exp, act, msg=nil) + EqualAssay.assert!(act, exp, :message=>msg, :backtrace=>caller) + end + + # Passes if expected != actual + # + # assert_not_equal 'some string', 5 + # + def assert_not_equal(exp, act, msg=nil) + EqualAssay.refute!(act, exp, :message=>msg, :backtrace=>caller) + end + + # + #def assert_fail_assertion(message = nil) + #end + + # + # Passed if object is +false+. + # + # assert_false(false) + # + def assert_false(exp, msg=nil) + FalseAssay.assert!(exp, :message=>msg, :backtrace=>caller) + end + + # + # Passed if object is not +false+. + # + # assert_not_false(false) + # + def assert_not_false(exp, msg=nil) + FalseAssay.refute!(exp, :message=>msg, :backtrace=>caller) + end + + # + # Passes if expected and actual are equal within `delta` absolte tolerance. + # + # assert_in_delta 0.05, (50000.0 / 10**6), 0.00001 + # + def assert_in_delta(exp, act, delta, msg=nil) + WithinAssay.assert!(act, exp, delta, :message=>msg, :backtrace=>caller) + end + + # + # Passes if expected and actual are NOT equal within `delta` absolute tolerance. + # + # assert_not_in_delta 0.05, (50000.0 / 10**6), 0.00001 + # + def assert_not_in_delta(exp, act, delta, msg=nil) + WithinAssay.refute!(act, exp, delta, :message=>msg, :backtrace=>caller) + end + + # + # Passes if `exp` and `act` are within `epsilon` relative tolerance. + # + def assert_in_epsilon(exp, act, epsilon=0.001, message=nil) + exp = epsilon if exp.zero? # why does minitest do this? + CloseAssay.assert!(act, exp, epsilon, :message=>message, :backtrace=>caller) + end + + # + # Passes if `exp` and `act` are NOT within `epsilon` relative tolerance. + # + def assert_not_in_epsilon(exp, act, epsilon=0.001, message=nil) + exp = epsilon if exp.zero? + CloseAssay.refute!(act, exp, epsilon, :message=>message, :backtrace=>caller) + end + + # + # Passes if `collection` contains `member`. + # + def assert_includes(collection, member, message=nil) + IncludeAssay.assert!(collection, member, :message=>message, :backtrace=>caller) + end + + # + # Passes if `collection` does not contain `member`. + # + def assert_not_includes(collection, member, message=nil) + IncludeAssay.refute!(collection, member, :message=>message, :backtrace=>caller) + end + + # + # Passes if object is an instance of class. + # + # assert_instance_of(String, 'foo') + # + def assert_instance_of(cls, obj, msg=nil) + InstanceAssay.assert!(obj, cls, :message=>msg, :backtrace=>caller) + end + + # + # Passes if object is not an instance of class. + # + # assert_not_instance_of(String, 500) + # + def assert_not_instance_of(cls, obj, msg=nil) + InstanceAssay.refute!(obj, cls, :message=>msg, :backtrace=>caller) + end + + # + # Passes if object .kind_of? klass + # + # assert_kind_of(Object, 'foo') + # + def assert_kind_of(cls, obj, msg=nil) + KindAssay.assert!(obj, cls, :message=>msg, :backtrace=>caller) + end + + # + # Passes if object .kind_of? klass + # + # assert_not_kind_of(Object, 'foo') + # + def assert_not_kind_of(cls, obj, msg=nil) + KindAssay.refute!(obj, cls, :message=>msg, :backtrace=>caller) + end + + # Passes if object matches pattern using `#=~` method. + # + # assert_match(/\d+/, 'five, 6, seven') + # + def assert_match(pattern, string, msg=nil) + MatchAssay.assert!(string, pattern, :message=>msg, :backtrace=>caller) + end + + # Passes if object does not match pattern using `#=~` method. + # + # assert_no_match(/two/, 'one 2 three') + # + def assert_not_match(pattern, string, msg=nil) + MatchAssay.refute!(string, pattern, :message=>msg, :backtrace=>caller) + end + + # Passes if object has no match pattern using `#!~` method. + # + # assert_no_match(/two/, 'one 2 three') + # + def assert_no_match(pattern, string, msg=nil) + NoMatchAssay.assert!(string, pattern, :message=>msg, :backtrace=>caller) + end + + ## Passes if object has a match pattern using `#!~` method. + ## + ## assert_not_no_match(/two/, 'one two three') + ## + #def assert_not_no_match(pattern, string, msg=nil) + # NoMatchAssay.refute!(string, pattern, :message=>msg, :backtrace=>caller) + #end + + # Passed if object is +nil+. + # + # assert_nil(nil) + # + def assert_nil(exp, msg=nil) + NilAssay.assert!(exp, :message=>msg, :backtrace=>caller) + end + + # Passed if object is not +nil+. + # + # assert_not_nil(true) + # + def assert_not_nil(exp, msg=nil) + NilAssay.refute!(exp, :message=>msg, :backtrace=>caller) + end + + # + # + # + def assert_predicate(object, predicate, message = nil) + ExecutionAssay.assert!(:message=>message) do + object.__send__(predicate) + end + end + + # + # + # + def assert_not_predicate(object, predicate, message = nil) + ExecutionAssay.refute!(:message=>message) do + object.__send__(predicate) + end + end + + # + # Passes if +object+ respond_to? +methods+. + # + # assert_respond_to 'bugbear', :slice + # + def assert_respond_to(reciever, method, msg=nil) + RespondAssay.assert!(reciever, method, :message=>msg, :backtrace=>caller) + end + alias_method :assert_responds_to, :assert_respond_to + + # + # Passes if +object+ does not respond_to? +methods+. + # + # assert_not_respond_to 'bugbear', :slice + # + def assert_not_respond_to(reciever, method, msg=nil) + RespondAssay.refute!(reciever, method, :message=>msg, :backtrace=>caller) + end + + # Passes if +expected+ .eql? +actual+. + # + # Note that the ordering of arguments is important, + # since a helpful error message is generated when this + # one fails that tells you the values of expected and actual. + # + # assert_equivalent 'MY STRING', 'my string'.upcase + # + def assert_equivalent(exp, act, msg=nil) + EqualityAssay.assert!(act, exp, :message=>msg, :backtrace=>caller) + end + + # Passes if +criterion+ is NOT equivalent to +actual+ as tested using `#eql?`. + # + # assert_not_equivalent 1, 1.0 + # + def assert_not_equivalent(criterion, act, msg=nil) + EqualityAssay.refute!(act, criterion, :message=>msg, :backtrace=>caller) + end + + # + # + # TODO: Is this supposed to be restricted in some way? + def assert_operator(receiver, operator, operand, message=nil) + ExecutionAssay.assert!(:message=>message, :backtrace=>caller) do + receiver.__send__(operator, operand) + end + end + + # + # + # + def assert_path_exist(path, message=nil) + PathAssay.assert!(path, :message=>message, :backtrace=>caller) + end + + # + # + # + def assert_path_not_exist(path, message=nil) + PathAssay.refute!(path, :message=>message, :backtrace=>caller) + end + + # + # Passes if the block raises a given exception. + # + # assert_raise RuntimeError do + # raise 'Boom!!!' + # end + # + def assert_raise(exception, message=nil, &block) + RaiseAssay.assert!(exception, :message=>message, :backtrace=>caller, &block) + end + + alias_method :assert_raises, :assert_raise + + # + # Passes if the block *does not* raise a given exceptions. + # + # assert_not_raised IOError do + # raise 'Boom!!!' + # end + # + def assert_not_raised(exception, message=nil, &block) #:yeild: + RaiseAssay.refute!(exception, :message=>message, :backtrace=>caller, &block) + end + + # + # Passes if the block yields successfully. + # + # assert_nothing_raised "Couldn't do the thing" do + # do_the_thing + # end + # + def assert_nothing_raised(message=nil, &block) + RescueAssay.refute!(Exception, :message=>message, :backtrace=>caller, &block) + end + + # + # Passes if the block raises a given exception. + # + # assert_raise_kind_of RuntimeError do + # raise 'Boom!!!' + # end + # + def assert_raise_kind_of(exception_class, message=nil, &block) + RescueAssay.assert!(exception_class, :message=>message, :backtrace=>caller, &block) + end + + # + #def assert_raise_message(*args, &block) + #end + + # + # Passes if actual is the same exact object as expected. + # + # assert_same(object, object) + # + def assert_same(exp, act, msg=nil) + IdentityAssay.assert!(act, exp, :message=>msg, :backtrace=>caller) + end + + # + # Passes if actual is not the same exact object as expected. + # + # assert_not_same(object, other) + # + def assert_not_same(exp, act, msg=nil) + IdentityAssay.refute!(act, exp, :message=>msg, :backtrace=>caller) + end + + # + # + # + #def assert_send(send_array, message=nil) + #end + + # + # Passes if the block throws `expected` object. + # + # assert_throw :done do + # throw :done + # end + # + def assert_throw(expected, msg=nil, &blk) + ThrowAssay.assert!(expected, :message=>msg, :backtrace=>caller, &blk) + end + + alias_method :assert_throws, :assert_throw + + # + # Passes if the block does not throws `expected` object. + # + # assert_not_thrown :done do + # throw :chimp + # end + # + def assert_not_thrown(expected, msg=nil, &blk) + ThrowAssay.refute!(expected, :message=>msg, :backtrace=>caller, &blk) + end + + # + # + # + def assert_nothing_thrown(message=nil, &blk) + ThrowAssay.refute!(nil, :message=>message, &blk) + end + + # + # Passed if object is +true+. + # + def assert_true(exp, msg=nil) + TrueAssay.assert!(exp, :message=>msg, :backtrace=>caller) + end + + # + # Passed if object is not +true+. + # + # assert_not_true(false) + # + def assert_not_true(exp, msg=nil) + TrueAssay.refute!(exp, :message=>msg, :backtrace=>caller) + end + + end + +end diff --git a/lib/assay/version.rb b/lib/assay/version.rb new file mode 100644 index 0000000..7a6f462 --- /dev/null +++ b/lib/assay/version.rb @@ -0,0 +1,3 @@ +module Assay + VERSION = '0.5.0' +end diff --git a/test/adapter/minitest_example.rb b/test/adapter/minitest_example.rb new file mode 100644 index 0000000..8028d02 --- /dev/null +++ b/test/adapter/minitest_example.rb @@ -0,0 +1,11 @@ +require 'assay' +require 'assay/adapter/minitest' +require 'minitest/autorun' + +class AdapterExample < Minitest::Test + def test_pass; EqualAssay.assert!(1, 1); end + def test_assay_fail; EqualAssay.assert!(1, 2); end + def test_native_fail; assert_equal 1, 2; end + def test_error; raise "oops"; end + def test_skip; skip "later"; end +end diff --git a/test/adapter/testunit_example.rb b/test/adapter/testunit_example.rb new file mode 100644 index 0000000..0b02d97 --- /dev/null +++ b/test/adapter/testunit_example.rb @@ -0,0 +1,10 @@ +require 'assay' +require 'assay/adapter/testunit' +require 'test/unit' + +class AdapterExample < Test::Unit::TestCase + def test_pass; EqualAssay.assert!(1, 1); end + def test_assay_fail; EqualAssay.assert!(1, 2); end + def test_native_fail; assert_equal 1, 2; end + def test_error; raise "oops"; end +end diff --git a/test/adapters.rb b/test/adapters.rb new file mode 100644 index 0000000..14fcfd1 --- /dev/null +++ b/test/adapters.rb @@ -0,0 +1,26 @@ +# Runs a small suite under Minitest and under Test::Unit with Assay's +# adapter loaded, and checks that a failed assay is counted as a failure +# and not as an error. Each runs in a process of its own, because the two +# frameworks don't share one. + +require 'rbconfig' + +checks = { + 'minitest_example.rb' => /5 runs, \d+ assertions, 2 failures, 1 errors, 1 skips/, + 'testunit_example.rb' => /4 tests, \d+ assertions, 2 failures, 1 errors/ +} + +failed = false + +checks.each do |file, expected| + path = File.join(__dir__, 'adapter', file) + output = IO.popen([RbConfig.ruby, '-Ilib', path], err: [:child, :out], &:read) + if output =~ expected + puts "ok #{file}" + else + failed = true + puts "not ok #{file}: expected #{expected.inspect} in\n#{output}" + end +end + +exit 1 if failed diff --git a/test/case_instance_assay.rb b/test/case_instance_assay.rb index f2bc718..181ac12 100644 --- a/test/case_instance_assay.rb +++ b/test/case_instance_assay.rb @@ -5,8 +5,8 @@ class_method :pass? do test do - assert InstanceAssay.pass?(1,Fixnum) - refute InstanceAssay.pass?(1,Integer) + assert InstanceAssay.pass?(1,Integer) + refute InstanceAssay.pass?(1,Numeric) end end @@ -14,7 +14,7 @@ class_method :fail? do test do - refute InstanceAssay.fail?(1,Fixnum) + refute InstanceAssay.fail?(1,Integer) assert InstanceAssay.fail?(1,String) end @@ -23,7 +23,7 @@ class_method :assert! do test do - InstanceAssay.assert!(1,Fixnum) + InstanceAssay.assert!(1,Integer) end test do @@ -42,7 +42,7 @@ test do expect InstanceAssay do - InstanceAssay.refute!(1,Fixnum) + InstanceAssay.refute!(1,Integer) end end diff --git a/test/case_kind_assay.rb b/test/case_kind_assay.rb index eb98854..26ae439 100644 --- a/test/case_kind_assay.rb +++ b/test/case_kind_assay.rb @@ -23,7 +23,7 @@ class_method :assert! do test do - KindAssay.assert!(1,Fixnum) + KindAssay.assert!(1,Integer) end test do diff --git a/test/case_raise_assay.rb b/test/case_raise_assay.rb index 86874be..ab790b8 100644 --- a/test/case_raise_assay.rb +++ b/test/case_raise_assay.rb @@ -5,7 +5,7 @@ class_method :pass? do test do - assert RaiseAssay.pass?(StandardError){ raise } + assert RaiseAssay.pass?(StandardError){ raise StandardError } refute RaiseAssay.pass?(ArgumentError){ raise } end @@ -14,7 +14,7 @@ class_method :fail? do test do - refute RaiseAssay.fail?(StandardError){ raise } + refute RaiseAssay.fail?(StandardError){ raise StandardError } assert RaiseAssay.fail?(ArgumentError){ raise } end @@ -23,7 +23,7 @@ class_method :assert! do test do - RaiseAssay.assert!(StandardError){ raise } + RaiseAssay.assert!(StandardError){ raise StandardError } end test do @@ -42,7 +42,7 @@ test do expect RaiseAssay do - RaiseAssay.refute!(StandardError){ raise } + RaiseAssay.refute!(StandardError){ raise StandardError } end end diff --git a/try/qed/01_example.rdoc b/try/qed/01_example.rdoc deleted file mode 100644 index 641db52..0000000 --- a/try/qed/01_example.rdoc +++ /dev/null @@ -1,23 +0,0 @@ -= Sample Assay via QED - - require 'assay' - - include Assay::Matchers - -Example of a failed assertion. - - 1.assert is_equal_to(2) - -Example of a failed refutation. - - 1.refute is_equal_to(1) - -Lets try the assertives. - - include Assay::Assertives - -Now - - assert_equal(1,2, "1 is not 2 dingo!") - -QED. diff --git a/try/testunit/example.rb b/try/testunit/example.rb deleted file mode 100644 index c66cbfc..0000000 --- a/try/testunit/example.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'test/unit' -require 'assay' -require 'assay/adapters/testunit' - -class ExampleTest < Test::Unit::TestCase - - include Assay::Assertives - - def test_this - assert_equal(1,2,"not this dingo!") - end -end - diff --git a/var/authors b/var/authors deleted file mode 100644 index d375be2..0000000 --- a/var/authors +++ /dev/null @@ -1,2 +0,0 @@ ---- -- Trans diff --git a/var/copyrights b/var/copyrights deleted file mode 100644 index fcfc69d..0000000 --- a/var/copyrights +++ /dev/null @@ -1,2 +0,0 @@ ---- -- 2010 Rubyworks (BSD-2-Clause) diff --git a/var/created b/var/created deleted file mode 100644 index 7dd7089..0000000 --- a/var/created +++ /dev/null @@ -1 +0,0 @@ -2010-11-14 diff --git a/var/description b/var/description deleted file mode 100644 index e54d814..0000000 --- a/var/description +++ /dev/null @@ -1,3 +0,0 @@ -Assay defines assertions in the same way that Ruby defines exceptions. -Each type of asserition, called an assay, is then a child of the base -Assertion class, which itself is a subclass of the Exception class. diff --git a/var/name b/var/name deleted file mode 100644 index 7679d05..0000000 --- a/var/name +++ /dev/null @@ -1 +0,0 @@ -assay diff --git a/var/organizations b/var/organizations deleted file mode 100644 index a2119fd..0000000 --- a/var/organizations +++ /dev/null @@ -1,2 +0,0 @@ ---- -- Rubyworks diff --git a/var/repositories b/var/repositories deleted file mode 100644 index 639ca69..0000000 --- a/var/repositories +++ /dev/null @@ -1,3 +0,0 @@ ---- -upstream: git@github.com:rubyworks/assay.git - diff --git a/var/requirements b/var/requirements deleted file mode 100644 index 3c9a6eb..0000000 --- a/var/requirements +++ /dev/null @@ -1,8 +0,0 @@ ---- -- ansi -- brass -- detroit (build) -- ergo (build) -- qed (test) -- ae (test) - diff --git a/var/resources b/var/resources deleted file mode 100644 index 5598d34..0000000 --- a/var/resources +++ /dev/null @@ -1,8 +0,0 @@ ---- -home: http://rubyworks.github.com/assay -docs: http://rubydoc.info/gems/assay/frames -code: http://github.com/rubyworks/assay -bugs: http://github.com/rubyworks/assay/issues -chat: http://chat.us.freenode.net/rubyworks -mail: http://groups.google.com/groups/rubyworks-mailinglist - diff --git a/var/summary b/var/summary deleted file mode 100644 index 04d6886..0000000 --- a/var/summary +++ /dev/null @@ -1 +0,0 @@ -Class-based Assertions Framework diff --git a/var/title b/var/title deleted file mode 100644 index 83e537d..0000000 --- a/var/title +++ /dev/null @@ -1 +0,0 @@ -Assay diff --git a/var/version b/var/version deleted file mode 100644 index 267577d..0000000 --- a/var/version +++ /dev/null @@ -1 +0,0 @@ -0.4.1 diff --git a/work/benchmarks/mem_method.rb b/work/benchmarks/mem_method.rb deleted file mode 100644 index 16c3781..0000000 --- a/work/benchmarks/mem_method.rb +++ /dev/null @@ -1,18 +0,0 @@ -n = 1000000 - -class X - def self.call(a,b) - a == b - end - - def initialize(a,b) - @a = a - @b = b - end - def call - @a == @b - end -end - -n.times{ X.call(1,1) } - diff --git a/work/benchmarks/mem_object.rb b/work/benchmarks/mem_object.rb deleted file mode 100644 index e180571..0000000 --- a/work/benchmarks/mem_object.rb +++ /dev/null @@ -1,18 +0,0 @@ -n = 1000000 - -class X - def self.call(a,b) - a == b - end - - def initialize(a,b) - @a = a - @b = b - end - def call - @a == @b - end -end - -n.times{ X.new(1,1).call } - diff --git a/work/benchmarks/method_vs_object.rb b/work/benchmarks/method_vs_object.rb deleted file mode 100644 index 72ca029..0000000 --- a/work/benchmarks/method_vs_object.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'benchmark' - -class X - def self.call(a,b) - a == b - end - - def initialize(a,b) - @a = a - @b = b - end - def call - @a == @b - end -end - - -n = 1000000 -Benchmark.bm do |x| - x.report("method") { n.times{ X.call(1,1) } } - x.report("object") { n.times{ X.new(1,1).call } } -end - diff --git a/work/consider/approx.rb b/work/consider/approx.rb deleted file mode 100644 index 9e2a5a8..0000000 --- a/work/consider/approx.rb +++ /dev/null @@ -1,35 +0,0 @@ -def close1(a,b,x) - (a >= (b - x)) && (a <= (b + x)) -end - -def close2(a,b,x) - (a / b - 1).abs <= x/b -end - -def close3(a,b,x) - ax, bx = a/x, b/x - (ax >= (bx - 1)) && (a <= (bx + 1)) -end - -def close4(a,b,x) - ax, bx = a/x, b/x - (ax / bx - 1).abs <= 1/bx -end - -def close5(a,b,x) - (a - b).abs / [a.abs, b.abs].max <= x -end - - -try = [[1.0, 1.1, 0.2, true], [1.1, 1.0, 0.1, true], [1.0, 1.1, 0.01, false]] - -try.each do |(a,b,x,r)| - c1 = close1(a,b,x) - c2 = close2(a,b,x) - c3 = close3(a,b,x) - c4 = close4(a,b,x) - c5 = close5(a,b,x) - - puts "%f %f %f %5s | %5s %5s %5s %5s %5s" % [a,b,x,r,c1,c2,c3,c4,c5] -end - diff --git a/work/consider/operator.rb b/work/consider/operator.rb deleted file mode 100644 index 8681d4b..0000000 --- a/work/consider/operator.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'assertion' - -module Assertable - - # Compares the +object1+ with +object2+ using operator. - # - # Passes if object1.send(operator, object2) is true. - # - # assert_operator 5, :>=, 4 - # - def assert_operator(o1, op, o2, opts={}) - if !o1.__send__(op, o2) - msg = opts[:message] || "Expected #{o1}.#{op}(#{o2}) to be true" - fail Assertion.new(msg, caller) - end - end - -end diff --git a/work/consider/return_failure.rb b/work/consider/return_failure.rb deleted file mode 100644 index e9bc2e1..0000000 --- a/work/consider/return_failure.rb +++ /dev/null @@ -1,136 +0,0 @@ -require 'assay/failure' - -module Assay - - #NoArgument = Object.new - - # DEPRECATE: This class has little value. Instead of doing - # - # assert_returns(4){ v } - # - # Simply test equality on the returned value. - # - # assert_equal(4, v) - # - # TODO: What's up with N/A? Use Facets' NA object? - class ReturnFailure < Failure - - # - def self.assert(exp, opts={}, &blk) #:yeild: - #msg = fail_message(exp) - res = yield - if :"N/A" == exp - chk = (res ? true : false) - args = [exp] - else - chk = (exp == res) - #msg = msg + ", but was #{res}" - args = [exp, res] - end - if !chk - msg = opts[:message] - bkt = opts[:backtrace] || caller - fail new(msg, :backtrace=>bkt, :arguments=>args) - end - end - - # - def self.refute(exp, opts={}, &blk) # :yield: - #msg = fail_message!(exp) - res = yield - if :"N/A" == exp - chk = (res ? false : true) - args = [exp] - else - chk = (exp != res) - #msg = msg + ", but was #{res}" - args = [exp, res] - end - if !chk - msg = opts[:message] - bkt = opts[:backtrace] || caller - fail new(msg, :backtrace=>bkt, :arguments=>args) - end - end - - # Check assertion. - def self.check(exp) #:yield: - case exp - when :"N/A" - yield ? true : false - else - exp == yield - end - end - - # - def to_s - return super unless @arguments.size == 2 - - exp = @arguments[0].inspect - - if @_negated - if :"N/A" == exp - "Expected block NOT to return a value" - else - "Expected block NOT to return #{exp}" - end - else - if :"N/A" == exp - "Expected block to return a value" - else - "Expected block to return #{exp}" - end - end - end - - end - - - module Assertable - - # Passes if the block yields a specified value (Compares with #==). - # - # assert_returns "something wanted" do - # do_the_thing - # end - # - def assert_returns(exp=:"N/A", opts={}, &blk) # :yield: - opts[:backtrace] ||= caller - ReturnFailure.assert(exp, opts, &blk) - end - - # Passes if the block does not yield a specific value. - # - # refute_returns "something unwanted" do - # do_the_thing - # end - # - def refute_returns(exp=:"N/A", opts={}, &blk) # :yield: - opts[:backtrace] ||= caller - ReturnFailure.refute(exp, opts, &blk) - end - - alias_method :assert_does_not_return, :refute_returns - end - - - module Matchers - # - # - # object.assert is_returned{ ... } - # - def is_returned(&blk) - ReturnFailure.to_matcher(&blk) - end - - # - # - # object.should be_returned{ ... } - # - def be_returned(&blk) - ReturnFailure.to_matcher(&blk) - end - end - -end diff --git a/work/consider/sends.rb b/work/consider/sends.rb deleted file mode 100644 index 451a8d6..0000000 --- a/work/consider/sends.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'assertion' - -module Assertable - # Passes if the method send returns a true value. - # The parameter +send_array+ is composed of: - # - # * receiver - # * method - # * arguments to method - # - # Example: - # - # sends [[1, 2], :include?, 4] - # - # NOTE: You can not change the message for this assertion. - # - def assert_sends(receiver, method, *args) - pass = begin - receiver.__send__(method, *args) - true - rescue Excepton #StandardError - false - end - msg = opts[:message] || "Expected #{receiver}.#{method}(*#{args.inspect}) call to return" - call = opts[:backtrace] || caller - fail Assertion.new(msg, call) unless pass - end - - # Passes if the method send *does not* return. - # The parameter +send_array+ is composed of: - # - # * receiver - # * method - # * arguments to method - # - # Example: - # - # sends [[1, 2], :include?, 4] - # - # NOTE: You can not change the message for this assertion. - # - def assert_does_not_send(receiver, method, *args) - pass = begin - receiver.__send__(method, *args) - true - rescue Excepton #StandardError - false - end - msg = opts[:message] || "Expected #{receiver}.#{method}(*#{args.inspect}) call NOT to return" - call = opts[:backtrace] || caller - fail Assertion.new(msg, call) if pass - end -end diff --git a/work/defunct/assertable_module/assertable.rb b/work/defunct/assertable_module/assertable.rb deleted file mode 100644 index 8ffe736..0000000 --- a/work/defunct/assertable_module/assertable.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'asserere/failures' - -# = Assertable -# -# Singleton methods defined against Assertable -# are transformated into assertions corresponding -# to active nomenclatures and then defined as instance -# methods of Assertable. -# -# Example -# -# require 'ae/nomenclature/assert' -# require 'ae/nomenclature/should' -# -# def Assertable.should_be_like_mike(name) -# raise CompareFailure.new("Not a Mike!", caller) unless /mike/i =~ name -# end -# -# include Assertable -# -# assert_like_jimmy("Jim Bo") -# should_be_like_jimmy("Jim Bo") -# -module Assertable - - ObjectSpace.each_object(Class) do |cls| - if cls < Failure - define_method(cls.assertable_method) do |*args, &blk| - opts = Hash === args.last ? args.pop : {} - opts[:backtrace] ||= caller - cls.check(*args, opts, &blk) - end - end - end - -end - diff --git a/work/defunct/assertable_module/assertable/compare.rb b/work/defunct/assertable_module/assertable/compare.rb deleted file mode 100644 index 0d71b3b..0000000 --- a/work/defunct/assertable_module/assertable/compare.rb +++ /dev/null @@ -1,22 +0,0 @@ -module Assertable - - # Passes if +actual+ .equte? +expected+. - # - # o = Object.new - # assert_like(o, o) - # - def self.like(exp, act, opts={}) - opts[:backtrace] ||= caller - CompareFailure.assert(exp, act, opts) - end - - # Passes if ! actual .equte? expected - # - # assert_not_like(Object.new, Object.new) - # - def self.not_like(exp, act, opts) - opts[:backtrace] ||= caller - CompareFailure.assert(exp, act, opts) - end - -end diff --git a/work/defunct/assertable_module/assertable/delta.rb b/work/defunct/assertable_module/assertable/delta.rb deleted file mode 100644 index ab4f23c..0000000 --- a/work/defunct/assertable_module/assertable/delta.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'assertions/failures/delta' - -module Assertable - - # Passes if expected_float and actual_float are equal within delta tolerance. - # - # assert_in_delta 0.05, (50000.0 / 10**6), 0.00001 - # - def assert_in_delta(exp, act, delta, opts={}) - opts[:backtrace] ||= caller - DeltaFailure.assert(exp, act, delta, opts) - end - - # Passes if expected_float and actual_float are equal not within delta tolerance. - # - # assert_not_in_delta 0.05, (50000.0 / 10**6), 0.00001 - # - def self.not_in_delta(exp, act, delta, opts) - opts[:backtrace] ||= caller - DeltaFailure.assert!(exp, act, delta, opts) - end - -end diff --git a/work/defunct/assertable_module/assertable/equality.rb b/work/defunct/assertable_module/assertable/equality.rb deleted file mode 100644 index 0611d21..0000000 --- a/work/defunct/assertable_module/assertable/equality.rb +++ /dev/null @@ -1,27 +0,0 @@ -require 'assertions/failures/equality' - -module Assertable - - # Passes if expected == +actual. - # - # Note that the ordering of arguments is important, - # since a helpful error message is generated when this - # one fails that tells you the values of expected and actual. - # - # assert_equal 'MY STRING', 'my string'.upcase - # - def assert_equal(exp, act, opts={}) - opts[:backtrace] ||= caller - EqualityFailure.assert(exp, act, opts) - end - - # Passes if expected != actual - # - # assert_not_equal 'some string', 5 - # - def assert_not_equal(exp, act, opts) - opts[:backtrace] ||= caller - EqualityFailure.assert!(exp, act, opts) - end - -end diff --git a/work/defunct/assertable_module/assertable/execution.rb b/work/defunct/assertable_module/assertable/execution.rb deleted file mode 100644 index 15ebb94..0000000 --- a/work/defunct/assertable_module/assertable/execution.rb +++ /dev/null @@ -1,27 +0,0 @@ -require 'assertion' - -module Assertable - - # Passes if the block yields successfully. - # - # assert_executes "Couldn't do the thing" do - # do_the_thing - # end - # - def assert_executes(opts={}, &blk) # :yield: - opts[:backtrace] ||= caller - ExecutionFailure.assert(blk, opts) - end - - # Passes if the block does not yield successfully. - # - # assert_not_executes "Couldn't do the thing" do - # do_the_thing - # end - # - def assert_not_executes(opts={}, &blk) # :yield: - opts[:backtrace] ||= caller - ExecutionFailure.assert!(blk, opts) - end - -end diff --git a/work/defunct/assertable_module/assertable/false.rb b/work/defunct/assertable_module/assertable/false.rb deleted file mode 100644 index cb9b4be..0000000 --- a/work/defunct/assertable_module/assertable/false.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'assertions/failures/false' - -module Assertable - - # Passed if object is +false+. - # - def assert_false(exp, opts={}) - opts[:backtrace] ||= caller - FalseFailure.assert(exp, opts) - end - - # Passed if object is not +false+. - # - # assert_not_false(false) - # - def assert_not_false(exp, opts={}) - opts[:backtrace] ||= caller - FalseFailure.assert!(exp, opts) - end - -end diff --git a/work/defunct/assertable_module/assertable/identity.rb b/work/defunct/assertable_module/assertable/identity.rb deleted file mode 100644 index 86514ef..0000000 --- a/work/defunct/assertable_module/assertable/identity.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'assertions/failures/identity' - -module Assertable - - # Passes if +actual+ .equal? +expected+ (i.e. they are the same instance). - # - # o = Object.new - # assert_identical(o, o) - # - def assert_identical(exp, act, opts={}) - opts[:backtrace] ||= caller - IdentityFailure.assert(exp, act, opts) - end - - # Passes if ! actual .equal? expected - # - # assert_not_identical(Object.new, Object.new) - # - def assert_not_identical(exp, act, opts={}) - opts[:backtrace] ||= caller - IdentityFailure.assert!(exp, act, opts) - end - -end diff --git a/work/defunct/assertable_module/assertable/instance.rb b/work/defunct/assertable_module/assertable/instance.rb deleted file mode 100644 index 345b6df..0000000 --- a/work/defunct/assertable_module/assertable/instance.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'assertions/failures/instance' - -module Assertable - - # Passes if object .instance_of? klass - # - # assert_instance_of(String, 'foo') - # - def self.instance_of(cls, obj, opts={}) - opts[:backtrace] ||= caller - InstanceFailure.assert(cls, act, opts) - end - - # Passes if object .instance_of? klass - # - # assert_instance_of(String, 'foo') - # - def self.not_instance_of(cls, obj, opts={}) - opts[:backtrace] ||= caller - InstanceFailure.assert!(cls, act, opts) - end - -end diff --git a/work/defunct/assertable_module/assertable/kind.rb b/work/defunct/assertable_module/assertable/kind.rb deleted file mode 100644 index a8a0eb4..0000000 --- a/work/defunct/assertable_module/assertable/kind.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'assertions/failures/kind' - -module Assertable - - # Passes if object .kind_of? klass - # - # assert_kind_of(Object, 'foo') - # - def assert_kind_of(cls, obj, opts={}) - opts[:backtrace] ||= caller - KindFailure.assert(exp, act, opts) - end - - # Passes if object .kind_of? klass - # - # assert_not_kind_of(Object, 'foo') - # - def assert_not_kind_of(cls, obj, opts={}) - opts[:backtrace] ||= caller - KindFailure.assert!(exp, act, opts) - end - -end diff --git a/work/defunct/assertable_module/assertable/match.rb b/work/defunct/assertable_module/assertable/match.rb deleted file mode 100644 index 4e8bf74..0000000 --- a/work/defunct/assertable_module/assertable/match.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'assertion/failures/match' - -module Assertable - - # Passes if string =~ pattern. - # - # assert_match(/\d+/, 'five, 6, seven') - # - def self.match(exp, act, opts={}) - opts[:backtrace] ||= caller - MatchFailure.assert(exp, act, opts) - end - - # Passes if regexp !~ string - # - # assert_no_match(/two/, 'one 2 three') - # - def self.no_match(exp, act, opts={}) - opts[:backtrace] ||= caller - MatchFailure.assert!(exp, act, opts) - end - -end diff --git a/work/defunct/assertable_module/assertable/nil.rb b/work/defunct/assertable_module/assertable/nil.rb deleted file mode 100644 index 16bf36d..0000000 --- a/work/defunct/assertable_module/assertable/nil.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'assertions/failures/nil' - -module Assertable - - # Passed if object is +nil+. - # - def assert_nil(exp, opts={}) - opts[:backtrace] ||= caller - NilFailure.assert(exp, opts) - end - - # Passed if object is not +nil+. - # - # assert_not_nil(true) - # - def assert_not_nil(exp, opts={}) - opts[:backtrace] ||= caller - NilFailure.assert!(exp, opts) - end - -end - diff --git a/work/defunct/assertable_module/assertable/raises.rb b/work/defunct/assertable_module/assertable/raises.rb deleted file mode 100644 index cecb7f0..0000000 --- a/work/defunct/assertable_module/assertable/raises.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'assertions/failures/raises' - -module Assertable - - # Passes if the block raises a given exceptions. - # - # assert_raises RuntimeError do - # raise 'Boom!!!' - # end - # - def self.raises(exp, msg=nil, call=nil, &blk) #:yeild: - RaiseFailure.assert(exp, msg=nil, call=nil, &blk) - end - - # Passes if the block *does not* raise a given exceptions. - # - # assert_not_raised IOError do - # raise 'Boom!!!' - # end - # - def self.not_raised(exp, msg=nil, call=nil, &blk) #:yeild: - RaiseFailure.assert!(exp, msg, call, &blk) - end - -end diff --git a/work/defunct/assertable_module/assertable/response.rb b/work/defunct/assertable_module/assertable/response.rb deleted file mode 100644 index e1b9cdf..0000000 --- a/work/defunct/assertable_module/assertable/response.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'assertions/failures/response' - -module Assertable - # Passes if +object+ respond_to? +methods+. - # - # assert_respond_to 'bugbear', :slice - # - def assert_respond_to(reciever, method, opts={}) - opts[:backtrace] ||= caller - ResponseFailure.assert(reciever, method, opts) - end - - # Passes if +object+ does not respond_to? +methods+. - # - # assert_not_respond_to 'bugbear', :slice - # - def assert_not_respond_to(reciever, method, opts={}) - opts[:backtrace] ||= caller - ResponseFailure.assert!(reciever, method, opts) - end -end diff --git a/work/defunct/assertable_module/assertable/returns.rb b/work/defunct/assertable_module/assertable/returns.rb deleted file mode 100644 index a1d2ac6..0000000 --- a/work/defunct/assertable_module/assertable/returns.rb +++ /dev/null @@ -1,27 +0,0 @@ -require 'assertions/failures/returns' - -module Assertable - - # Passes if the block yields a specified value (Compares with #==). - # - # assert_returns "Did not return something" do - # do_the_thing - # end - # - def assert_returns(exp=:"N/A", opts={}, &blk) # :yield: - opts[:backtrace] ||= caller - ReturnFailure.assert(exp, opts, &blk) - end - - # Passes if the block does not yield a specific value. - # - # assert_does_not_return "Returned something unwanted" do - # do_the_thing - # end - # - def assert_does_not_return(exp=:"N/A", opts={}, &blk) # :yield: - opts[:backtrace] ||= caller - ReturnFailure.assert!(exp, opts, &blk) - end - -end diff --git a/work/defunct/assertable_module/assertable/same.rb b/work/defunct/assertable_module/assertable/same.rb deleted file mode 100644 index 639ca22..0000000 --- a/work/defunct/assertable_module/assertable/same.rb +++ /dev/null @@ -1,27 +0,0 @@ -require 'assertions/failures/same' - -module Assertable - - # Passes if +expected+ .eq? +actual+. - # - # Note that the ordering of arguments is important, - # since a helpful error message is generated when this - # one fails that tells you the values of expected and actual. - # - # assert_equal 'MY STRING', 'my string'.upcase - # - def self.same(exp, act, opts={}) - opts[:backtrace] ||= caller - SameFailure.assert(exp, act, opts) - end - - # Passes if not +expected+ .eq? +actual+. - # - # assert_not_equal 'some string', 5 - # - def self.not_the_same(exp, act, opts={}) - opts[:backtrace] ||= caller - SameFailure.assert!(exp, act, opts) - end - -end diff --git a/work/defunct/assertable_module/assertable/true.rb b/work/defunct/assertable_module/assertable/true.rb deleted file mode 100644 index c5428a3..0000000 --- a/work/defunct/assertable_module/assertable/true.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'assertions/failures/true' - -module Assertable - - # Passed if object is +true+. - # - def assert_true(exp, opts={}) - opts[:backtrace] ||= caller - TrueFailure.assert(exp, opts) - end - - # Passed if object is not +true+. - # - # assert_not_true(false) - # - def assert_not_true(exp, opts={}) - opts[:backtrace] ||= caller - TrueFailure.assert!(exp, opts) - end - -end - diff --git a/work/defunct/assertable_module/assertions/compare.rb b/work/defunct/assertable_module/assertions/compare.rb deleted file mode 100644 index 53b6c63..0000000 --- a/work/defunct/assertable_module/assertions/compare.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'assertion' - -class CompareFailure < Assertion - def self.assertion_name - :like - end - - def self.fail_message(exp, act) - "Expected #{act.inspect} to be like #{exp.inspect}" - end - - def self.fail_message!(exp, act) - "Expected #{act.inspect} NOT to be like #{exp.inspect}" - end - - def self.check(exp, act) - exp.equals?(act) || - exp.eq?(act) || - exp.==(act) || - exp.===(act) - end -end - -module Assertable - # Passes if +actual+ .equte? +expected+. - # - # o = Object.new - # assert_like(o, o) - # - def self.like(exp, act, opts={}) - opts[:backtrace] ||= caller - CompareFailure.assert(exp, act, opts) - end - - # Passes if ! actual .equte? expected - # - # assert_not_like(Object.new, Object.new) - # - def self.not_like(exp, act, opts) - opts[:backtrace] ||= caller - CompareFailure.assert(exp, act, opts) - end -end diff --git a/work/defunct/assertable_module/assertions/equal.rb b/work/defunct/assertable_module/assertions/equal.rb deleted file mode 100644 index 65580a4..0000000 --- a/work/defunct/assertable_module/assertions/equal.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'ae/assertions/compare' - -class EqualityFailure < CompareFailure - def self.assertion_name - :equal - end - - def self.assertion_operator - :== - end - - def self.fail_message(exp, act) - "Expected #{act.inspect} == #{exp.inspect}" - end - - def self.fail_message!(exp, act) - "Expected #{act.inspect} != #{exp.inspect}" - end - - def self.check(exp, act) - exp == act - end - - def self.check!(exp, act) - exp != act - end -end - -module Assertable - # Passes if expected == +actual. - # - # Note that the ordering of arguments is important, - # since a helpful error message is generated when this - # one fails that tells you the values of expected and actual. - # - # assert_equal 'MY STRING', 'my string'.upcase - # - def assert_equal(exp, act, opts={}) - opts[:backtrace] ||= caller - EqualityFailure.assert(exp, act, opts) - end - - # Passes if expected != actual - # - # assert_not_equal 'some string', 5 - # - def assert_not_equal(exp, act, opts) - opts[:backtrace] ||= caller - EqualityFailure.assert!(exp, act, opts) - end -end diff --git a/work/defunct/assertable_module/assertions/execution.rb b/work/defunct/assertable_module/assertions/execution.rb deleted file mode 100644 index 94adfbc..0000000 --- a/work/defunct/assertable_module/assertions/execution.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'assertion' -require 'ae/assertable' - -class ExecutionFailure < Assertion - - def fail_message - "Expected procedure to execute sucessfully" - end - - def fail_message! - "Expected procedure not execute sucessfully" - end - - def check(&blk) - begin - blk.call - true - rescure Exception - false - end - end - -end - -module Assertable - - # Passes if the block yields successfully. - # - # assert_executes "Couldn't do the thing" do - # do_the_thing - # end - # - def self.executes(opts={}, &blk) # :yield: - opts[:backtrace] ||= caller - EcecutionFailure.assert(opts, &blk) - end - - # Passes if the block does not yield successfully. - # - # assert_not_executing "Couldn't do the thing" do - # do_the_thing - # end - # - def self.not_executing(opts={}, &blk) # :yield: - opts[:backtrace] ||= caller - EcecutionFailure.assert!(opts, &blk) - end - -end diff --git a/work/defunct/assertable_module/assertions/false.rb b/work/defunct/assertable_module/assertions/false.rb deleted file mode 100644 index 63e8576..0000000 --- a/work/defunct/assertable_module/assertions/false.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'ae/assertable' - -class IsFalseFailure < Assertion - def self.assertion_name - :false - end - - def fail_message(exp) - "Expected #{exp} to be false" - end - - def fail_message!(exp) - "Expected #{exp} NOT to be false" - end - - def self.check(act) - FalseClass === act - end -end - -module Assertable - # Passed if object is +false+. - # - def self.false(obj, opts={}) - opts[:backtrace] ||= caller - IsFalseFailure.assert(obj, opts) - end - - # Passed if object is not +false+. - # - # assert_not_false(false) - # - def self.not_false(obj, opts={}) - opts[:backtrace] ||= caller - IsFalseFailure.assert!(obj, opts) - end -end diff --git a/work/defunct/assertable_module/assertions/identity.rb b/work/defunct/assertable_module/assertions/identity.rb deleted file mode 100644 index 09ae816..0000000 --- a/work/defunct/assertable_module/assertions/identity.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'ae/assertions/compare' - -class IdentityFailure < CompareFailure - def self.assertion_name - :identical - end - - def fail_message(exp, act) - "Expected #{act.inspect} to be identical to #{exp.inspect}" - end - - def fail_message!(exp, act) - "Expected #{act.inspect} NOT to be identical to #{exp.inspect}" - end - - def self.check(exp, act) - exp.equal?(act) - end -end - -module Assertable - # Passes if +actual+ .equal? +expected+ (i.e. they are the same instance). - # - # o = Object.new - # assert_identical(o, o) - # - def self.identical(exp, act, opts={}) - opts[:backtrace] ||= caller - Identityfailure.assert(exp, act, opts) - end - - # Passes if ! actual .equal? expected - # - # assert_not_identical(Object.new, Object.new) - # - def self.not_identical(exp, act, opts={}) - opts[:backtrace] ||= caller - IdentityFailure.assert!(exp, act, opts) - end -end diff --git a/work/defunct/assertable_module/assertions/in_delta.rb b/work/defunct/assertable_module/assertions/in_delta.rb deleted file mode 100644 index 9466f54..0000000 --- a/work/defunct/assertable_module/assertions/in_delta.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'ae/assertions/compare' - -class InDeltaFailure < CompareFailure - def self.assertion_name - :in_delta - end - - def self.fail_message(exp, act, delta) - "Expected #{exp} to be within #{delta} of #{act}" - end - - def self.fail_message!(exp, act, delta) - "Expected #{exp} NOT to be within #{delta} of #{act}" - end - - def self.check(exp, act, delta) - (exp.to_f - act.to_f).abs <= delta.to_f - end -end - -module Assertable - # Passes if expected_float and actual_float are equal within delta tolerance. - # - # assert_in_delta 0.05, (50000.0 / 10**6), 0.00001 - # - def self.in_delta(exp, act, delta, opts={}) - opts[:backtrace] ||= caller - InDeltaFailure.assert(exp, act, delta, opts) - end - - # Passes if expected_float and actual_float are equal not within delta tolerance. - # - # assert_not_in_delta 0.05, (50000.0 / 10**6), 0.00001 - # - def self.not_in_delta(exp, act, delta, opts) - opts[:backtrace] ||= caller - InDeltaFailure.assert!(exp, act, delta, opts) - end -end diff --git a/work/defunct/assertable_module/assertions/instance_of.rb b/work/defunct/assertable_module/assertions/instance_of.rb deleted file mode 100644 index 5682aee..0000000 --- a/work/defunct/assertable_module/assertions/instance_of.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'ae/assertions/compare' - -class InstanceOfFailure < CompareFailure - def self.assertion_name - :instance_of - end - - def fail_message(cls, obj) - "Expected #{obj} to be a #{cls}" - end - - def fail_message!(cls, obj) - "Expected #{obj} NOT to be #{cls}" - end - - def self.check(exp, act) - act.instance_of?(exp) - end -end - -module Assertable - # Passes if object .instance_of? klass - # - # assert_instance_of(String, 'foo') - # - def self.instance_of(cls, obj, opts={}) - opts[:backtrace] ||= caller - InstanceOfFailure.assert(cls, obj, opts) - end - - # Passes if object .instance_of? klass - # - # assert_instance_of(String, 'foo') - # - def self.not_instance_of(cls, obj, opts={}) - opts[:backtrace] ||= caller - InstanceOfFailure.assert!(cls, obj, opts) - end -end diff --git a/work/defunct/assertable_module/assertions/kind_of.rb b/work/defunct/assertable_module/assertions/kind_of.rb deleted file mode 100644 index 788b8fe..0000000 --- a/work/defunct/assertable_module/assertions/kind_of.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'ae/assertions/compare' - -# Passes if object .kind_of? cls -# -# assert_kind_of(Object, 'foo') -# -# === Contemporary -# -# 'foo'.assert.kind_of?(Object) -# -class KindOfFailure < CompareFailure - def self.assertion_name - :kind_of - end - - def fail_message(cls, obj) - "Expected #{obj.inspect} to be a kind of #{cls}" - end - - def fail_message!(cls, obj) - "Expected #{obj.inspect} to NOT be a kind of #{cls}" - end - - def check(cls, obj) - obj.kind_of?(cls) - end -end - -module Assertable - # Passes if object .kind_of? klass - # - # assert_kind_of(Object, 'foo') - # - def self.kind_of(cls, obj, opts={}) - opts[:backtrace] ||= caller - KindOfFailure.assert(cls, obj, opts={}) - end - - # Passes if object .kind_of? klass - # - # assert_kind_of(Object, 'foo') - # - def self.not_kind_of(cls, obj, opts={}) - opts[:backtrace] ||= caller - KindOfFailure.assert!(cls, obj, opts) - end -end diff --git a/work/defunct/assertable_module/assertions/match.rb b/work/defunct/assertable_module/assertions/match.rb deleted file mode 100644 index b8c4d4c..0000000 --- a/work/defunct/assertable_module/assertions/match.rb +++ /dev/null @@ -1,44 +0,0 @@ -require 'ae/assertions/compare' - -# -class MatchFailure < CompareFailure - def self.assertion_name - :match - end - - def fail_message(exp, act) - "Expected #{act.inspect} to match #{exp.inspect}" - end - - def fail_message!(exp, act) - "Expected #{act.inspect} NOT to match #{exp.inspect}" - end - - def self.check(exp, act) - act =~ exp - end - - def self.check!(exp, act) - act !~ exp - end -end - -module Assertable - # Passes if string =~ pattern. - # - # assert_match(/\d+/, 'five, 6, seven') - # - def self.match(exp, act, opts={}) - opts[:backtrace] ||= caller - MatchFailure.assert(exp, act, opts) - end - - # Passes if regexp !~ string - # - # assert_no_match(/two/, 'one 2 three') - # - def self.no_match(exp, act, opts={}) - opts[:backtrace] ||= caller - MatchFailure.assert!(exp, act, opts={}) - end -end diff --git a/work/defunct/assertable_module/assertions/nil.rb b/work/defunct/assertable_module/assertions/nil.rb deleted file mode 100644 index d3ca322..0000000 --- a/work/defunct/assertable_module/assertions/nil.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'assertion' -require 'ae/assertable' - -class IsNilFailure < Assertion - def self.assertion_name - :nil - end - - def fail_message(exp) - "Expected #{exp} to be nil" - end - - def fail_message!(exp) - "Expected #{exp} to NOT be nil" - end - - def self.check(obj) - obj.nil? - end -end - -module Assertable - # Passes if object nil? - # - # assert_nil [1, 2].uniq! - # - def self.nil(obj, opts={}) - opts[:backtrace] ||= caller - IsNilFailure.assert(obj, opts) - end - - # Passes if object is not nil? - # - # assert_not_nil '1 two 3'.sub!(/two/, '2') - # - def self.not_nil(obj, opts={}) - opts[:backtrace] ||= caller - IsNilFailure.assert!(obj, opts) - end -end diff --git a/work/defunct/assertable_module/assertions/operator.rb b/work/defunct/assertable_module/assertions/operator.rb deleted file mode 100644 index 072b0ce..0000000 --- a/work/defunct/assertable_module/assertions/operator.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'assertion' -require 'ae/assertable' - -class OperatorFailure < ExecutionFailure - - # Compares the +object1+ with +object2+ using operator. - # - # Passes if object1.send(operator, object2) is true. - # - # assert_operator 5, :>=, 4 - # - def self.operator(o1, op, o2, msg="") - test = o1.__send__(op, o2) - msg = "Expected #{o1}.#{op}(#{o2}) to be true" unless msg - raise Assertion.new(msg, caller) unless test - end - -end diff --git a/work/defunct/assertable_module/assertions/raises.rb b/work/defunct/assertable_module/assertions/raises.rb deleted file mode 100644 index 5de9cc7..0000000 --- a/work/defunct/assertable_module/assertions/raises.rb +++ /dev/null @@ -1,89 +0,0 @@ -require 'ae/assertions/execution' - -class RaiseFailure < ExecutionFailure - def self.assertion_name - :raises - end - - def self.assertion_name! - :not_raised - end - - def self.assert(exp, msg=nil, call=nil) #:yeild: - begin - yield - msg = msg || fail_message(exp) - test = false - rescue Exception => err - msg = msg || fail_message(exp, err) - test = (exp === err) - end - fail new(msg, call||caller) unless test - end - - def self.assert!(exp, msg=nil, call=nil) #:yield: - begin - yield - test = true - rescue Exception => err - msg = msg || fail_message!(exp, err) - test = (exp === err) - end - fail new(msg, call||caller) unless test - end - - def self.fail_message(exp, err=nil) - if err - "Expected #{exp} to be raised, but got #{err.class}" - else - "Expected #{exp} to be raised" - end - end - - def self.fail_message!(exp) - "Expected #{exp} NOT to be raised" - end - - # Note: This is not used by the #assert method. - def self.check(*exp) - begin - yield - false - rescue Exception => e - exp.any?{ |x| x === e } - end - end - - # Note: This is not used by the #assert! method. - def self.check(*exp) - begin - yield - true - rescue Exception => e - !exp.any?{ |x| x === e } - end - end - -end - -module Assertable - # Passes if the block raises a given exceptions. - # - # assert_raises RuntimeError do - # raise 'Boom!!!' - # end - # - def self.raises(exp, msg=nil, call=nil, &blk) #:yeild: - RaiseFailure.assert(exp, msg=nil, call=nil, &blk) - end - - # Passes if the block *does not* raise a given exceptions. - # - # assert_not_raised IOError do - # raise 'Boom!!!' - # end - # - def self.not_raised(exp, msg=nil, call=nil, &blk) #:yeild: - RaiseFailure.assert!(exp, msg, call, &blk) - end -end diff --git a/work/defunct/assertable_module/assertions/respond_to.rb b/work/defunct/assertable_module/assertions/respond_to.rb deleted file mode 100644 index 807bf08..0000000 --- a/work/defunct/assertable_module/assertions/respond_to.rb +++ /dev/null @@ -1,45 +0,0 @@ -require 'ae/assertions/execution' - -class RespondToFailure < ExecutionFailure - def self.assertion_name - :respond_to - end - - def self.assertion_name! - :not_respond_to - end - - def fail_message(reciever, method) - "Expected #{reciever} (#{reciever.class}) to respond to ##{method}" - end - - def fail_message!(reciever, method) - "Expected #{reciever} (#{reciever.class}) to not respond to ##{method}" - end - - def self.check(reciver, method) - #flip = (Symbol === obj) && ! (Symbol === meth) # HACK for specs - #obj, meth = meth, obj if flip - reciever.respond_to?(method) - end -end - -module Assertable - # Passes if +object+ respond_to? +methods+. - # - # assert_respond_to 'bugbear', :slice - # - def assert_respond_to(reciever, method, opts={}) - opts[:backtrace] ||= caller - RespondToFailure.assert(reciever, method, opts) - end - - # Passes if +object+ does not respond_to? +methods+. - # - # assert_not_respond_to 'bugbear', :slice - # - def assert_not_respond_to(reciever, method, opts={}) - opts[:backtrace] ||= caller - RespondToFailure.assert!(reciever, method, opts) - end -end diff --git a/work/defunct/assertable_module/assertions/returns.rb b/work/defunct/assertable_module/assertions/returns.rb deleted file mode 100644 index dec1f67..0000000 --- a/work/defunct/assertable_module/assertions/returns.rb +++ /dev/null @@ -1,83 +0,0 @@ -require 'assertion' -require 'ae/assertable' - -NoArgument = Object.new - -class ReturnFailure < Assertion - - def self.assert(exp, opts={}, &blk) #:yeild: - msg = fail_message(exp) - res = yield - if :"N/A" == exp - chk = (res ? true : false) - else - chk = (exp == res) - msg = msg + ", but was #{res}" - end - fail new(opts[:message]||msg, opts[:backtrace]||caller) unless chk - end - - def self.assert!(exp, opts={}, &blk) # :yield: - msg = fail_message!(exp) - res = yield - if :"N/A" == exp - chk = (res ? false : true) - else - chk = (exp != res) - msg = msg + ", but was #{res}" - end - fail new(opts[:message]||msg, opts[:backtrace]||caller) unless chk - end - - def fail_message(exp) - if :"N/A" == exp - "Expected block to return a value" - else - "Expected block to return #{exp}" - end - end - - def fail_message!(exp) - if :"N/A" == exp - "Expected block not to return a value" - else - "Expected block not to return #{exp}" - end - end - - def check(exp) #:yield: - case exp - when :"N/A" - yield ? true : false - else - exp == yield - end - end - -end - -module Assertable - - # Passes if the block yields a specified value (Compares with #==). - # - # assert_executes "Couldn't do the thing" do - # do_the_thing - # end - # - def assert_returns(exp=:"N/A", opts={}, &blk) # :yield: - opts[:backtrace] ||= caller - ReturnFailure.assert(exp, opts, &blk) - end - - # Passes if the block does not yield a specific value. - # - # assert_not_executing "Couldn't do the thing" do - # do_the_thing - # end - # - def assert_does_not_return(exp=:"N/A", opts={}, &blk) # :yield: - opts[:backtrace] ||= caller - ReturnFailure.assert!(exp, opts, &blk) - end - -end diff --git a/work/defunct/assertable_module/assertions/same.rb b/work/defunct/assertable_module/assertions/same.rb deleted file mode 100644 index fa5caf4..0000000 --- a/work/defunct/assertable_module/assertions/same.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'ae/assertions/compare' - -class SameFailure < CompareFailure - def self.assertion_name - :same - end - - def fail_message(exp, act) - "Expected #{act.inspect} to be the same as #{exp.inspect}" - end - - def fail_message!(exp, act) - "Expected #{act.inspect} to NOT be the same as #{exp.inspect}" - end - - def check(exp, act) - exp.eq?(act) - end -end - -module Assertable - # Passes if +expected+ .eq? +actual+. - # - # Note that the ordering of arguments is important, - # since a helpful error message is generated when this - # one fails that tells you the values of expected and actual. - # - # assert_equal 'MY STRING', 'my string'.upcase - # - def self.same(exp, act, opts={}) - opts[:backtrace] ||= caller - SameFailure.assert(exp, act, opts) - end - - # Passes if not +expected+ .eq? +actual+. - # - # assert_not_equal 'some string', 5 - # - def self.not_the_same(exp, act, opts={}) - opts[:backtrace] ||= caller - SameFailure.assert!(exp, act, opts) - end -end diff --git a/work/defunct/assertable_module/assertions/sends.rb b/work/defunct/assertable_module/assertions/sends.rb deleted file mode 100644 index 9ab65cb..0000000 --- a/work/defunct/assertable_module/assertions/sends.rb +++ /dev/null @@ -1,74 +0,0 @@ -require 'ae/assertions/execution' - -class SendFailure < ExecutionFailure - def self.assertion_name - :sends - end - - def self.assertion_name! - :does_not_send - end - - def self.assert(receiver, methods *args) - msg = fail_message(receiver, method, *args) - fail new(msg, call||caller) unless check(receiver, method, *args) - end - - def self.assert!(receiver, methods *args) - msg = msg || fail_message!(receiver, method, *args) - fail new(msg, call||caller) unless check!(receiver, method, *args) - end - - def self.fail_message(reciever, method, *args) - "Expected #{receiver}.#{method}(*#{args.inspect}) call to return true" - end - - def self.fail_message!(reciever, method, *args) - "Expected #{receiver}.#{method}(*#{args.inspect}) call to return false" - end - - def self.check(receiver, method, *args) - begin - receiver.__send__(method, *args) - true - rescue Excepton #StandardError - false - end - end -end - -module Assertable - # Passes if the method send returns a true value. - # The parameter +send_array+ is composed of: - # - # * receiver - # * method - # * arguments to method - # - # Example: - # - # sends [[1, 2], :include?, 4] - # - # NOTE: You can not change the message for this assertion. - # - def assert_sends(receiver, method, *args) - SendFailure.assert(receiver, method, *args) - end - - # Passes if the method send *does not* returns a true value. - # The parameter +send_array+ is composed of: - # - # * receiver - # * method - # * arguments to method - # - # Example: - # - # sends [[1, 2], :include?, 4] - # - # NOTE: You can not change the message for this assertion. - # - def assert_does_not_send(receiver, method, *args) - SendFailure.assert!(receiver, method, *args) - end -end diff --git a/work/defunct/assertable_module/assertions/throws.rb b/work/defunct/assertable_module/assertions/throws.rb deleted file mode 100644 index ba8688c..0000000 --- a/work/defunct/assertable_module/assertions/throws.rb +++ /dev/null @@ -1,108 +0,0 @@ -require 'ae/assertions/execution' - -class ThrowFailure < ExecutionFailure - def self.assertion_name - :throws - end - - def self.assertion_name! - :not_thown - end - - def self.assert(sym, msg=nil, call=nil) #:yeild: - msg = msg || fail_message(sym) - test = true - catch(sym) do - begin - yield - rescue ArgumentError => err # 1.9 exception - msg += ", not #{err.message.split(/ /).last}" - test = false - rescue NameError => err # 1.8 exception - msg += ", not #{err.name.inspect}" - test = false - end - end - fail new(msg, call||caller) unless test - end - - # FIXME: How to get the opposite? - def self.assert!(sym, msg=nil, call=nil) #:yield: - msg = msg || fail_message(sym) - test = false - catch(sym) do - begin - yield - rescue ArgumentError => err # 1.9 exception - #msg += ", not #{err.message.split(/ /).last}" - test = true - rescue NameError => err # 1.8 exception - #msg += ", not #{err.name.inspect}" - test = true - end - end - fail new(msg, call||caller) unless test - end - - def fail_message(sym) - "Expected #{sym} to have been thrown" - end - - def fail_message!(sym) - "Expected #{sym} NOT to have been thrown" - end - - # Note: This is not used by the #assert method. - def self.check(sym) #:yield: - test = true - catch(sym) do - begin - yield - rescue ArgumentError => err # 1.9 exception - test = false - rescue NameError => err # 1.8 exception - test = false - end - end - test - end - - # Note: This is not used by the #assert! method. - def self.check!(sym) #:yield: - test = false - catch(sym) do - begin - yield - rescue ArgumentError => err # 1.9 exception - test = true - rescue NameError => err # 1.8 exception - test = true - end - end - test - end -end - -module Assertable - # Passes if the block throws expected_symbol - # - # assert_throws :done do - # throw :done - # end - # - def assert_throws(sym, opts, &blk) - opts[:backtrace] ||= caller - ThrowFailure.assert(sym, opts, &blk) - end - - # Passes if the block throws expected_symbol - # - # assert_not_thrown :done do - # throw :chimp - # end - # - def assert_not_thrown(sym, opts, &blk) - opts[:backtrace] ||= caller - ThrowFailure.assert!(sym, opts, &blk) - end -end diff --git a/work/defunct/assertable_module/assertions/true.rb b/work/defunct/assertable_module/assertions/true.rb deleted file mode 100644 index 44f155f..0000000 --- a/work/defunct/assertable_module/assertions/true.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'assertion' -require 'ae/assertable' - -class IsTrueFailure < Assertion - def self.assertion_name - :true - end - - def fail_message(exp) - "Expected #{exp} to be true" - end - - def fail_message!(exp) - "Expected #{exp} NOT to be true" - end - - def self.check(act) - TrueClass === act - end -end - -module Assertable - # Passed if object is +true+. - # - def assert_true(obj, opts) - options[:backtrace] ||= caller - IsTrueFailure.assert(obj, opts) - end - - # Passed if object is not +true+. - # - # assert_not_true(false) - # - def assert_not_true(obj, opts) - opts[:backtrace] ||= caller - IsTrueFailure.assert!(obj, opts) - end -end diff --git a/work/defunct/assertable_module/compare.rb b/work/defunct/assertable_module/compare.rb deleted file mode 100644 index 53b6c63..0000000 --- a/work/defunct/assertable_module/compare.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'assertion' - -class CompareFailure < Assertion - def self.assertion_name - :like - end - - def self.fail_message(exp, act) - "Expected #{act.inspect} to be like #{exp.inspect}" - end - - def self.fail_message!(exp, act) - "Expected #{act.inspect} NOT to be like #{exp.inspect}" - end - - def self.check(exp, act) - exp.equals?(act) || - exp.eq?(act) || - exp.==(act) || - exp.===(act) - end -end - -module Assertable - # Passes if +actual+ .equte? +expected+. - # - # o = Object.new - # assert_like(o, o) - # - def self.like(exp, act, opts={}) - opts[:backtrace] ||= caller - CompareFailure.assert(exp, act, opts) - end - - # Passes if ! actual .equte? expected - # - # assert_not_like(Object.new, Object.new) - # - def self.not_like(exp, act, opts) - opts[:backtrace] ||= caller - CompareFailure.assert(exp, act, opts) - end -end diff --git a/work/defunct/complex_nomenclature_system/nomenclature.rb b/work/defunct/complex_nomenclature_system/nomenclature.rb deleted file mode 100644 index 85c327b..0000000 --- a/work/defunct/complex_nomenclature_system/nomenclature.rb +++ /dev/null @@ -1,83 +0,0 @@ -require 'assertion' -require 'ae/assertable' - -class AE - - # - module Nomenclature - - # Store list of currently active nomenclatures. - ACTIVE = [] - - private - - def self.extended(nomenclature) - setup_nomenclature(nomenclature) - end - - # Setup pre-existing predicates. - # - def self.setup_nomenclature(nomenclature) - ACTIVE << nomenclature - #(@nomenclatures ||= []) << nomenclature - Assertable.private_instance_methods(false).each do |name| - next if :define_predicate == name.to_sym - nomenclature.define_predicate(name) - end - end - - # Converts - def make_subjunctive(name) - name = name.to_s - name = case name - #when /^not_/ then "not_be_#{$'}" - when /^no_/ then "not_have_#{$'}" - when /^is_/ then "be_#{$'}" - when /^in_/ then "be_#{name}" - when /^like_/ then "be_#{name}" - when /^has_/ then "have_been_#{$'}" - when /_of$/ then "be_#{name}" - else name - end - name = name.chomp('s') if /s$/ =~ name - name - end - - # Converts - def make_interjective(name) - name = name.to_s - name = case name - when /^not_be_/ then "not_#{$'}" - when /^not_have_/ then "no_#{$'}" - when /^be_/ then "#{$'}" - #when /^be_in_/ then "in_#{$'}" - #when /^be_like_/ then "like_#{$'}" - when /^have_been_/ then "has_#{$'}" - else name - end - #name = name.chomp('s') if /s$/ =~ name - name - end - - # Predicate definition. This must be overriden - # in nomenclature submodules. - # - def define_predicate(prefix, name, pname) - return if :singleton_method_added == pname.to_sym - return if :make_subjunctive == pname.to_sym - return if :make_interjective == pname.to_sym - return if :define_predicate == pname.to_sym - - puts "Nomenclature#define_predicate(#{prefix.inspect}, #{name.inspect}, #{pname.inspect})" if $DEBUG - - Assertable.module_eval <<-END, __FILE__, __LINE__ - private - def #{prefix}_#{name}(*a,&b) - Assertable.#{pname}(*a,&b) - end - END - end - - end - -end diff --git a/work/defunct/complex_nomenclature_system/nomenclature/assert.rb b/work/defunct/complex_nomenclature_system/nomenclature/assert.rb deleted file mode 100644 index 7d2d0f1..0000000 --- a/work/defunct/complex_nomenclature_system/nomenclature/assert.rb +++ /dev/null @@ -1,48 +0,0 @@ -require 'ae/kernel/assert' -require 'ae/nomenclature' - -class AE - - module Nomenclature - - # = Extended Assert Nomenclature - # - module Assert - # Define predicate +pname+ for this nomenclature. - # - def self.define_predicate(pname) - #puts "Assert::define_predicate(#{pname.inspect})" if $DEBUG - name = make_interjective(pname) - name = case name - when /^is/ then "#{name.sub('is_','')}" - else "#{name}" - end - super('assert', name, pname) - case name - when /^assert_not/ - alias_method "refute_{$'}", name - when /^assert_no/ - alias_method "refute_{$'}", name - end - end - - # Returns the predicate name without the prefix - # phrase that corresponds to this nomenclature. - # If the term doesn't conform to this nomenclature - # then returns nil. - def self.make_neutral(name) - case name - when /^assert_/ then $' - else nil - end - end - - # Assert is a Nomenclature. - # This is done last to prevent any Nomenclature - # callbacks from triggering on the above definitions. - extend Nomenclature - end - - end - -end diff --git a/work/defunct/complex_nomenclature_system/nomenclature/expect.rb b/work/defunct/complex_nomenclature_system/nomenclature/expect.rb deleted file mode 100644 index a5e2fa5..0000000 --- a/work/defunct/complex_nomenclature_system/nomenclature/expect.rb +++ /dev/null @@ -1,42 +0,0 @@ -require 'ae/expect' -require 'ae/nomenclature' - -class AE - - module Nomenclature - - # = Extended Expect Nomenclature - # - module Expect - - # Setup a predicate for this nomenclature. - def self.define_predicate(pname) - name = make_interjective(pname) - name = case name - when /^is/ then "#{name.sub('is_','')}" - else "#{name}" - end - super('expect', name, pname) - end - - # Returns the predicate name without the prefix - # phrase that corresponds to this nomenclature. - # If the term doesn't conform to this nomenclature - # then returns nil. - def self.make_neutral(name) - case name - when /^expect_/ then $' - else nil - end - end - - # Expect is a nomenclature. - # This is done last to prevent any Nomenclature - # callbacks from triggering on the above definitions. - extend Nomenclature - - end #module Expect - - end - -end diff --git a/work/defunct/complex_nomenclature_system/nomenclature/must.rb b/work/defunct/complex_nomenclature_system/nomenclature/must.rb deleted file mode 100644 index ac0716f..0000000 --- a/work/defunct/complex_nomenclature_system/nomenclature/must.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'ae/must' -require 'ae/nomenclature' - -class AE - - module Nomenclature - - # = Extended Must Nomenclature - # - module Must - - # Setup a predicate for this nomenclature. - def self.define_predicate(pname) - name = make_subjunctive(pname) - super('must', name, pname) - end - - # Returns the predicate name without the prefix - # phrase that corresponds to this nomenclature. - # If the term doesn't conform to this nomenclature - # then returns nil. - def self.make_neutral(name) - case name - when /^must_/ then $' - else nil - end - end - - # Must is a nomenclature. - extend Nomenclature - - end - - end - -end diff --git a/work/defunct/complex_nomenclature_system/nomenclature/shall.rb b/work/defunct/complex_nomenclature_system/nomenclature/shall.rb deleted file mode 100644 index b364978..0000000 --- a/work/defunct/complex_nomenclature_system/nomenclature/shall.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'ae/shall' -require 'ae/nomenclature' - -class AE - - module Nomenclature - - # = Extended Shall Nomenclature - # - module Shall - - # Setup a predicate for this nomenclature. - def self.define_predicate(pname) - name = make_subjunctive(pname) - super('shall', name, pname) - end - - # Returns the predicate name without the prefix - # phrase that corresponds to this nomenclature. - # If the term doesn't conform to this nomenclature - # then returns nil. - def self.make_neutral(name) - case name - when /^shall_/ then $' - else nil - end - end - - # Shall is a nomenclature. - extend Nomenclature - - end #module Shall - - end - -end diff --git a/work/defunct/complex_nomenclature_system/nomenclature/should.rb b/work/defunct/complex_nomenclature_system/nomenclature/should.rb deleted file mode 100644 index d637890..0000000 --- a/work/defunct/complex_nomenclature_system/nomenclature/should.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'ae/kernel/should' -require 'ae/nomenclature' - -class AE - - module Nomenclature - - # = Extended Should Nomenclature - # - module Should - - # Setup a predicate for this nomenclature. - def self.define_predicate(pname) - name = make_subjunctive(pname) - super('should', name, pname) - end - - # Returns the predicate name without the prefix - # phrase that corresponds to this nomenclature. - # If the term doesn't conform to this nomenclature - # then returns nil. - def self.make_neutral(name) - case name - when /^should_/ then $' - else nil - end - end - - # Should is a nomenclature. - extend Nomenclature - - end #module Should - - end - -end diff --git a/work/defunct/complex_nomenclature_system/nomenclature/verify.rb b/work/defunct/complex_nomenclature_system/nomenclature/verify.rb deleted file mode 100644 index 34aa3e7..0000000 --- a/work/defunct/complex_nomenclature_system/nomenclature/verify.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'ae/verify' -require 'ae/nomenclature' - -class AE - - module Nomenclature - - # = Extended Verify Nomenclature - # - module Verify - - # Setup a predicate for this nomenclature. - def self.define_predicate(pname) - name = make_interjective(pname) - name = case name - when /^is/ then "#{name.sub('is_','')}" - else "#{name}" - end - super('verify', name, pname) - end - - # Returns the predicate name without the prefix - # phrase that corresponds to this nomenclature. - # If the term doesn't conform to this nomenclature - # then returns nil. - def self.make_neutral(name) - case name - when /^verify_/ then $' - else nil - end - end - - # Verify is a nomenclature. - extend Nomenclature - - end #module Verify - - end - -end diff --git a/work/defunct/complex_nomenclature_system/nomenclature/will.rb b/work/defunct/complex_nomenclature_system/nomenclature/will.rb deleted file mode 100644 index a59684d..0000000 --- a/work/defunct/complex_nomenclature_system/nomenclature/will.rb +++ /dev/null @@ -1,42 +0,0 @@ -require 'ae/will' -require 'ae/nomenclature' - -class AE - - module Nomenclature - - # = Extended Will Nomenclature - # - module Will #:nodoc: - - # Define a predicate for this nomenclature. - def self.define_predicate(pname) - name = make_subjunctive(pname) - super('will', name, pname) - case name - when /^will_not/ - alias_method "wont_{$'}", name - end - end - - # Returns the predicate name without the prefix - # phrase that corresponds to this nomenclature. - # If the term doesn't conform to this nomenclature - # then returns nil. - def self.make_neutral(name) - case name - when /^will_have_been_/ then "has_#{$'}" - when /^will_be_/ then $' - when /^will_/ then $' - else nil - end - end - - # Will is a nomenclature. - extend Nomenclature - - end #module Will - - end - -end diff --git a/work/defunct/object-assays/assay.rb b/work/defunct/object-assays/assay.rb deleted file mode 100644 index 0d18a12..0000000 --- a/work/defunct/object-assays/assay.rb +++ /dev/null @@ -1,71 +0,0 @@ -module Assay - - $ASSERTION_COUNTS = Hash.new{ |h,k| h[k] = 0 } - - def self.[](name) - index[name.to_sym] - end - - def self.index - @index ||= {} - end - - # - # - def self.new(name, error=StandardError, options={}, &condition) - name = name.to_sym - assay = Definition.new(name, error, options, &condition) - index[name] = assay - end - - # - # - class Definition - - def initialize(name, error=StandardError, options={}, &test) - @name = name - @error = error || StandardError - @test = test - end - - def name - @name - end - - def error - @error - end - - # TODO: Better name? - def test - @test - end - - # - def pass?(*args, &blk) - @test.call(*args, &blk) - end - - def assert!(*args, &blk) - if pass?(*args, &blk) - increment_counts(:pass) - else - increment_counts(:fail) - raise @error, message(*args, &blk) - end - end - - # TODO: Better name? - def message(*args, &blk) - "#{name} " + args.inspect - end - - # TODO: Better name? - def increment_counts(which) - $ASSERTION_COUNTS[which] += 1 - $ASSERTION_COUNTS[:total] += 1 - end - - end - -end diff --git a/work/defunct/object-assays/definitions.rb b/work/defunct/object-assays/definitions.rb deleted file mode 100644 index ecec5a5..0000000 --- a/work/defunct/object-assays/definitions.rb +++ /dev/null @@ -1,78 +0,0 @@ -require 'assay/assay' - - -class EqualityError < StandardError - def self.assay(name, options={}, &block) - Assay.new(name, self, options, &block) - end -end - - -#def assay(name, error=StandardError, options={}, &block) -# Assay.new(name, options, &block) -#end - -# -TypeError.assay(:kind_of) do |target, criterion| - target.kind_of?(criterion) -end - -# -TypeError.assay(:instance_of) do |target, criterion| - target.instance_of?(criterion) -end - -# -EqualityError.assay(:identical) do |target, criterion| - criterion.object_id == target.object_id -end - -# -#assay :equal, EqualityError do |target, criterion| -# criterion.equal?(target) -#end - -# -EqualityError.assay :eql do |target, criterion| - criterion.eql?(target) -end - -# -EqualityError.assay :eq, :operator=>:== do |target, criterion| - criterion == target -end - -# -EqualityError.assay :like do |target, criterion| - criterion === target || - criterion.equal?(target) || - criterion.eql?(target) || - criterion.==(target) -end - -# -StandardError.assay :empty do |target| - target.empty? -end - -# -StandardError.assay :include do |target, criterion| - target.include?(criterion) -end - -StandardError.assay :false do |target| - FalseClass = target # target.false? -end - -StandardError.assay :true do |target| - TrueClass = target # target.true? -end - -StandardError.assay :nil do |target| - NilClass = target # target.nil? -end - -NoMethodError.assay :respond_to |target, method| - target.respond_to?(method) -end - diff --git a/work/defunct/oldschool_extensions/is.rb b/work/defunct/oldschool_extensions/is.rb deleted file mode 100644 index f5e0602..0000000 --- a/work/defunct/oldschool_extensions/is.rb +++ /dev/null @@ -1,35 +0,0 @@ -module Assay - - # This module holds the objective "is" methods, which are mixed in to - # all objects. - # - module Expectations - - # - # Meta-programming routine for creating all the subjective methods. - # - def self.bootstrap - Assay.constants.each do |const| - next unless const < Assertion - - name = const.objective_name - - define_method("is_#{name}") do |*args| - const.assert(self, *args) - end - - define_method("is_not_#{name}") do |*args| - const.refute(self, *args) - end - end - end - - # - # Do it! - # - bootstrap - - end - -end - diff --git a/work/defunct/oldschool_matchers/be.rb b/work/defunct/oldschool_matchers/be.rb deleted file mode 100644 index 123ff29..0000000 --- a/work/defunct/oldschool_matchers/be.rb +++ /dev/null @@ -1,31 +0,0 @@ -module Assay - - # This module holds the subject matcher methods, which can be mixin - # to one's testing scope (e.g. World). - # - module Matchers - - # - # Meta-programming routine for creating all the subjective methods. - # - def self.bootstrap - Assay.constants.each do |const| - next unless const < Assertion - - name = const.subjective_name - - define_method("be_#{name}") do |*args| - const.to_matcher(*args) - end - end - end - - # - # Do it! - # - bootstrap - - end - -end - diff --git a/work/defunct/oldschool_matchers/is.rb b/work/defunct/oldschool_matchers/is.rb deleted file mode 100644 index 71fa917..0000000 --- a/work/defunct/oldschool_matchers/is.rb +++ /dev/null @@ -1,31 +0,0 @@ -module Assay - - # This module holds the subject matcher methods, which can be mixin - # to one's testing scope (e.g. World). - # - module Matchers - - # - # Meta-programming routine for creating all the subjective methods. - # - def self.bootstrap - Assay.constants.each do |const| - next unless const < Assertion - - name = const.objective_name - - define_method("is_#{name}") do |*args| - const.to_matcher(*args) - end - end - end - - # - # Do it! - # - bootstrap - - end - -end - diff --git a/work/defunct/static_assertion_methods/assertive/legacy.rb b/work/defunct/static_assertion_methods/assertive/legacy.rb deleted file mode 100644 index ebd873a..0000000 --- a/work/defunct/static_assertion_methods/assertive/legacy.rb +++ /dev/null @@ -1,349 +0,0 @@ -module Assay - - module Nomenclature - - # LegacyAssertions provided assertion methods which are compatable with - # the the traditional TestUnit and MiniTest assertion methods. - # - # NOTE: There may stil be a few descrepencies yet to work out for full compatabilty. - # - module LegacyAssertions - - # - def self.activate - ::Object.__send__(:include, self) - end - - # CompareFailure - - # - # - # assert_alike(criteron, object) - # - def assert_alike(exp, act, msg=nil) - CompareFailure.assert(act, exp, :message=>msg, :backtrace=>caller) - end - - # - # - # refute_alike(criteron, object) - # - def refute_alike(exp, act, msg=nil) - CompareFailure.refute(act, exp, :message=>msg, :backtrace=>caller) - end - - # DeltaFailures - - # Passes if expected and actual are equal within delta tolerance. - # - # assert_in_delta 0.05, (50000.0 / 10**6), 0.00001 - # - def assert_in_delta(exp, act, delta, msg=nil) - DeltaFailure.assert(act, exp, delta, :message=>msg, :backtrace=>caller) - end - - # Passes if expected and actual are equal not within delta tolerance. - # - # assert_not_in_delta 0.05, (50000.0 / 10**6), 0.00001 - # - def refute_in_delta(exp, act, delta, msg=nil) - #opts[:backtrace] ||= caller - DeltaFailure.refute(act, exp, delta, :message=>msg, :backtrace=>caller) - end - - alias_method :assert_not_within_delta, :refute_within_delta - - # EmptyFailure - - # Passes if object is empty. - # - # assert_empty(object) - # - def assert_empty(exp, msg=nil) - EmptyFailure.assert(exp, :message=>msg, :backtrace=>caller) - end - - # Passes if object is not empty. - # - # refute_empty(object) - # - def refute_empty(exp, msg=nil) - #opts[:backtrace] ||= caller - EmptyFailure.refute(exp, :message=>msg, :backtrace=>caller) - end - - alias_method :assert_not_empty, :refute_empty - - # EqualityFailure - - # Passes if expected == +actual. - # - # Note that the ordering of arguments is important, - # since a helpful error message is generated when this - # one fails that tells you the values of expected and actual. - # - # assert_equal 'MY STRING', 'my string'.upcase - # - def assert_equal(exp, act, msg=nil) - EqualityFailure.assert(act, exp, :message=>msg, :backtrace=>caller) - end - - # Passes if expected != actual - # - # assert_not_equal 'some string', 5 - # - def assert_not_equal(exp, act, msg=nil) - EqualityFailure.refute(act, exp, :message=>msg, :backtrace=>caller) - end - - # ExecutionFailure - - # Passes if the block yields successfully. - # - # assert_executes "Couldn't do the thing" do - # do_the_thing - # end - # - def assert_executes(msg=nil, &blk) - ExecutionFailure.assert(:message=>msg, :backtrace=>caller, &prco) - end - - # Passes if the block does not yield successfully. - # - # refute_executes "Couldn't do the thing" do - # do_the_thing - # end - # - def refute_executes(msg=nil, &proc) - ExecutionFailure.refute(:message=>msg, :backtrace=>caller, &proc) - end - - # FalseFailure - - # Passed if object is +false+. - # - def assert_false(exp, msg=nil) - FalseFailure.assert(exp, :message=>msg, :backtrace=>caller) - end - - # Passed if object is not +false+. - # - # refute_false(false) - # - def refute_false(exp, msg=nil) - FalseFailure.refute(exp, :message=>msg, :backtrace=>caller) - end - - alias_method :assert_not_false, :refute_false - - # IdentityFailure - - # Passes if actual is the same exact object as expected. - # - # assert_identical(object, object) - # - def assert_identical(exp, act, msg=nil) - IdentityFailure.assert(act, exp, :message=>msg, :backtrace=>caller) - end - - # Passes if actual is not the same exact object as expected. - # - # refute_identical(object, other) - # - def refute_identical(exp, act, msg=nil) - IdentityFailure.refute(act, exp, :message=>msg, :backtrace=>caller) - end - - alias_method :assert_not_identical, :refute_identical - - # InstanceFailure - - # Passes if object is an instance of class. - # - # assert_instance_of(String, 'foo') - # - def assert_instance_of(cls, obj, msg=nil) - InstanceFailure.assert(obj, cls, :message=>msg, :backtrace=>caller) - end - - # Passes if object is not an instance of class. - # - # assert_instance_of(String, 'foo') - # - def refute_instance_of(cls, obj, msg=nil) - InstanceFailure.refute(obj, cls, :message=>msg, :backtrace=>caller) - end - - alias_method :assert_not_instance_of, :refute_instance_of - - # KindFailure - - # Passes if object .kind_of? klass - # - # assert_kind_of(Object, 'foo') - # - def assert_kind_of(cls, obj, msg=nil) - KindFailure.assert(obj, cls, :message=>msg, :backtrace=>caller) - end - - # Passes if object .kind_of? klass - # - # assert_not_kind_of(Object, 'foo') - # - def refute_kind_of(cls, obj, msg=nil) - KindFailure.refute(obj, cls, :message=>msg, :backtrace=>caller) - end - - alias_method :assert_not_kind_of, :refute_kind_of - - # MatchFailure - - # Passes if object matches pattern using `#=~` method. - # - # assert_match(/\d+/, 'five, 6, seven') - # - def assert_match(exp, act, msg=nil) - MatchFailure.assert(act, exp, :message=>msg, :backtrace=>caller) - end - - # Passes if object does not match pattern using `#=~` method. - # - # refute_match(/two/, 'one 2 three') - # - def refute_match(exp, act, msg=nil) - MatchFailure.refute(act, exp, :message=>msg, :backtrace=>caller) - end - - # NilFailure - - # Passed if object is +nil+. - # - # assert_nil(nil) - # - def assert_nil(exp, msg=nil) - NilFailure.assert(exp, :message=>msg, :backtrace=>caller) - end - - # Passed if object is not +nil+. - # - # refute_nil(true) - # - def refute_nil(exp, msg=nil) - #opts[:backtrace] ||= caller - NilFailure.refute(exp, :message=>msg, :backtrace=>caller) - end - - alias_method :assert_not_nil, :refute_nil - - # RaiseFailure - - # Passes if the block raises a given exception. - # - # assert_raises RuntimeError do - # raise 'Boom!!!' - # end - # - def assert_raises(exp, msg=nil, call=nil, &blk) #:yeild: - RaiseFailure.assert(exp, msg=nil, call=nil, &blk) - end - - # Passes if the block *does not* raise a given exceptions. - # - # assert_not_raised IOError do - # raise 'Boom!!!' - # end - # - def assert_not_raised(exp, msg=nil, call=nil, &blk) #:yeild: - RaiseFailure.refute(exp, msg, call, &blk) - end - - # ResponseFailure - - # Passes if +object+ respond_to? +methods+. - # - # assert_respond_to 'bugbear', :slice - # - def assert_respond_to(reciever, method, msg=nil) - ResponseFailure.assert(reciever, method, :message=>msg, :backtrace=>caller) - end - alias_method :assert_responds_to, :assert_respond_to - - # Passes if +object+ does not respond_to? +methods+. - # - # assert_not_respond_to 'bugbear', :slice - # - def assert_not_respond_to(reciever, method, msg=nil) - ResponseFailure.refute(reciever, method, :message=>msg, :backtrace=>caller) - end - - alias_method :assert_not_responds_to, :assert_not_respond_to - - # SameFailure - - # Passes if +expected+ .eq? +actual+. - # - # Note that the ordering of arguments is important, - # since a helpful error message is generated when this - # one fails that tells you the values of expected and actual. - # - # assert_same 'MY STRING', 'my string'.upcase - # - def assert_same(exp, act, msg=nil) - SameFailure.assert(exp, act, :message=>msg, :backtrace=>caller) - end - - # Passes if not +expected+ .eq? +actual+. - # - # assert_not_the_same 'some string', 5 - # - def refute_same(exp, act, msg=nil) - SameFailure.refute(exp, act, :message=>msg, :backtrace=>caller) - end - - alias_method :assert_not_same, :refute_same - - # ThrowFailure - - # Passes if the block throws expected_symbol - # - # assert_throws :done do - # throw :done - # end - # - def assert_throws(sym, msg=nil, &blk) - ThrowFailure.assert(sym, :message=>msg, :backtrace=>caller, &blk) - end - - # Passes if the block throws expected_symbol - # - # refute_throws :done do - # throw :chimp - # end - # - def refute_throws(sym, msg=nil, &blk) - ThrowFailure.refute(sym, :message=>msg, :backtrace=>caller, &blk) - end - - alias_method :assert_not_thrown, :refute_throws - - # TrueFailure - - # Passed if object is +true+. - # - def assert_true(exp, msg=nil) - TrueFailure.assert(exp, :message=>msg, :backtrace=>caller) - end - - # Passed if object is not +true+. - # - # assert_not_true(false) - # - def assert_not_true(exp, msg=nil) - TrueFailure.refute(exp, :message=>msg, :backtrace=>caller) - end - - end - - end - -end diff --git a/work/defunct/static_assertion_methods/matchers/be.rb b/work/defunct/static_assertion_methods/matchers/be.rb deleted file mode 100644 index b33495c..0000000 --- a/work/defunct/static_assertion_methods/matchers/be.rb +++ /dev/null @@ -1,311 +0,0 @@ -require 'assay/nomenclature/hander/should' - -module Assay - - module Nomenclature - - # Be Matchers provide a set of RSpec-compatible matcher methods. - # These matchers provide all the traditional Rspec matchers, less - # a bit of extraneous verbosity, plus a few additional matchers. - # - module Be - - # - def self.activate - ::Object.__send__(:include, self) - end - - # CompareFailure - - # Passes if the expected and actual are alike. - # - # object.should be_like(criterion) - # - def be_like(exp) - CompareFailure.to_matcher(exp) - end - - # Passes if the expected and actual are alike. - # - # object.assert is_like(criterion) - # - alias_method :is_like, :be_like - - # DeltaFailure - - # Passes if expected and actual are equal within delta tolerance. - # - # value1.should be_within(delta, value2) - # - def is_within(delta, exp) - DeltaFailure.to_matcher(exp, delta) - end - - # Passes if expected and actual are nto equal within delta tolerance. - # - # value1.assert is_within(delta, value2) - # - def be_within(delta, exp) - DeltaFailure.to_matcher(exp, delta) - end - - # EmptyFailure - - # Passes if object is empty. - # - # object.assert is_empty - # - def is_empty - EmptyFailure.to_matcher - end - - # Passes if object is empty. - # - # object.should be_empty - # - def be_empty - EmptyFailure.to_matcher - end - - # EqualityFailure - - # Passes if +expected+ == +actual+. - # - # 'MY STRING'.assert is_equal_to('my string'.upcase) - # 'MY STRING'.refute is_equal_to('another string') - # - def is_equal_to(exp) #, opts={}) - EqualityFailure.to_matcher(exp) - end - - # Passes if +expected+ == +actual+. - # - # 'MY STRING'.should be_equal_to('my string'.upcase) - # 'MY STRING'.should_not be_equal_to('another string') - # - def be_equal_to(exp) - EqualityFailure.to_matcher(exp) - end - - # ExecutionFailure - - # FIXME: Reasonable matcher for ExectuionFailure ? - # - # - # proc.assert is_executed(*args) - # - def is_executed(*args, &block) - ExecutionFailure.to_matcher(args, &block) - end - - # - # - # proc.should be_executed(*args) - # - def be_extecuted(&block) - ExecutionFailure.to_matcher(args, &block) - end - - # FalseFailure - - # Passed if object is +false+. - # - # value.assert is_false - # - def is_false - FalseFailure.to_matcher - end - - # Passed if object is +false+. - # - # value.should be_false - # - def be_false - FalseFailure.to_matcher - end - - # IdentityFailure - - # Passes if actual is the same exact object as expected. - # - # object.assert is_identical_to(object) - # - def is_identical_to(obj) - IdentityFailure.to_matcher(obj) - end - - # Passes if actual is the same exact object as expected. - # - # object.should be_identical_to(object) - # - def be_identical_to(obj) - IdentityFailure.to_matcher(obj) - end - - # InstanceFailure - - # Passes if object is an instance of class. - # - # object.assert is_instance_of(class) - # - def is_instance_of(cls) - InstanceFailure.to_matcher(cls) - end - - # Passes if object is an instance of class. - # - # object.should be_instance_of(class) - # - def be_instance_of(cls) - InstanceFailure.to_matcher(cls) - end - - # KindFailure - - # Passes if object is a kind of class. - # - # object.assert is_a_kind_of(class) - # - def is_kind_of(cls) - KindFailure.to_matcher(cls) - end - - # Passes if object is a kind of class. - # - # object.should be_a_kind_of(class) - # - def be_kind_of(cls) - KindFailure.to_matcher(cls) - end - - # MatchFailure - - # Passes if object matches pattern using `#=~` method. - # - # object.assert is_match_for(regexp) - # - def is_match_for(regexp) - MatchFailure.to_matcher(regexp) - end - - # Passes if object matches pattern using `#=~` method. - # - # object.should be_match_for(regexp) - # - def be_match_for(regexp) - MatchFailure.to_matcher(regexp) - end - - # NilFailure - - # Passed if object is +nil+. - # - # value.assert is_nil - # - def is_nil - NilFailure.to_matcher - end - - # Passed if object is +nil+. - # - # value.should be_nil - # - def be_nil - NilFailure.to_matcher - end - - # RaiseFailure - - # FIXME: Fix raise matchers - # - # Exception.assert is_raised{ ... } - # - def is_raised(&blk) - RaiseFailure.to_matcher(&blk) - end - - # - # - # Exception.should be_raised{ ... } - # - def be_raised(&blk) - RaiseFailure.to_matcher(&blk) - end - - # RespondFailure - - # - # - # object.assert is_responsive_to(:method_symbol) - # - def is_responsive_to(method) - ResponseFailure.to_matcher(method) - end - - # - # - # object.should be_responsive_to(:method_symbol) - # - def be_responsive_to(method) - ResponseFailure.to_matcher(method) - end - - # SameFailure - - # - # - # object1.assert is_same_as(object2) - # - def is_same_as(obj) - SameFailure.to_matcher(obj) - end - - # - # - # object1.should be_same_as(object2) - # - def be_same_as(obj) - SameFailure.to_matcher(obj) - end - - # ThrowFailure - - # - # - # :symbol.assert is_thrown{ ... } - # - def is_thrown(&blk) - ThrowFailure.to_matcher(&blk) - end - - # - # - # :symbol.should be_thrown{ ... } - # - def be_thrown(&blk) - ThrowFailure.to_matcher(&blk) - end - - # TrueFailure - - # Passed if object is +true+. - # - # value.assert is_true - # - def is_true - TrueFailure.to_matcher - end - - # Passed if object is +true+. - # - # value.should be_true - # - def be_true - TrueFailure.to_matcher - end - - end - - end - -end diff --git a/work/defunct/static_assertion_methods/matchers/class.rb b/work/defunct/static_assertion_methods/matchers/class.rb deleted file mode 100644 index f0475a0..0000000 --- a/work/defunct/static_assertion_methods/matchers/class.rb +++ /dev/null @@ -1,36 +0,0 @@ -module Assay - - # Examples - # - # "string".it IsLike[/string/i] - # - # "string".it IsKind[String] - # - # case 10.1 - # when IsInstance[Fixnum] - # when IsWithin[0.2, 10] - # when IsMatch[/\d+\.\d+/] - # end - # - module IsClasses - - IsLike = Assay::CompareFailure - IsWithin = Assay::DeltaFailure - IsEqual = Assay::EqualityFailure - IsExecuted = Assay::ExecutionFailure - IsFalse = Assay::FalseFailure - IsIdentical = Assay::IdentityFailure - IsInstance = Assay::InstanceFailure - IsKind = Assay::KindFailure - IsMatch = Assay::MatchFailure - IsNil = Assay::NilFailure - IsRaised = Assay::RaiseFailure - IsResponsive = Assay::RespondFailure - IsSame = Assay::SameFailure - IsThrown = Assay::ThrowFailure - IsTrue = Assay::TrueFailure - - end - -end - diff --git a/work/defunct/static_assertion_methods/matchers/rspec.rb b/work/defunct/static_assertion_methods/matchers/rspec.rb deleted file mode 100644 index 8ee5ccc..0000000 --- a/work/defunct/static_assertion_methods/matchers/rspec.rb +++ /dev/null @@ -1 +0,0 @@ -require_relative 'be' diff --git a/work/defunct/static_assertion_methods/objective/is.rb b/work/defunct/static_assertion_methods/objective/is.rb deleted file mode 100644 index 35296e5..0000000 --- a/work/defunct/static_assertion_methods/objective/is.rb +++ /dev/null @@ -1,350 +0,0 @@ -module Assay - - module Nomenclature - - # IsObjectives are like MustObjectives, but use `is`as method prefix instead - # of `must`. It also removes extraneous `of`, `to`, `for` and `as` suffixes. - # A few methods use `does` prefix instead, when it more natural to do so. - # - module IsObjectives - - # - def self.activate - ::Object.__send__(:include, self) - end - - # CompareFailure - - # Passes if object is like criterion. - # - # object.is_like(criterion) - # - # See {CompareFailure}. - # - def is_like(exp) - CompareFailure.assert(self, exp, :message=>msg, :backtrace=>caller) - end - - # Passes if object is not like criterion using {CompareFailure}. - # - # object.is_unlike(criterion) - # - # See {CompareFailure}. - # - def is_not_like(exp) - CompareFailure.refute(self, exp, :message=>msg, :backtrace=>caller) - end - - alias_method :is_unlike, :is_not_like - - # DeltaFailure - - # Passes if expected and actual are equal within delta tolerance. - # - # (50000.0 / 10**6).is_within(0.00001, 0.05) - # - # See {DeltaFailure}. - # - def is_within(delta, exp, msg=nil) - DeltaFailure.assert(self, exp, delta, :message=>msg, :backtrace=>caller) - end - - # Passes if expected and actual are equal not within delta tolerance. - # - # (50000.0 / 10**6).is_not_within!(0.00001, 0.05) - # - # See {DeltaFailure}. - # - def is_not_within!(delta, exp, msg=nil) - DeltaFailure.refute(self, exp, delta, :message=>msg, :backtrace=>caller) - end - - # EmptyFailure - - # Passes if object is empty. - # - # object.is_empty - # - def is_empty - EmptyFailure.assert(self, :message=>msg, :backtrace=>caller) - end - - # Passes if object is not empty. - # - # object.is_not_empty - # - def is_not_empty - EmptyFailure.refute(self, :message=>msg, :backtrace=>caller) - end - - # EqualityFailure - - # Passes if expected == +actual. - # - # Note that the ordering of arguments is important, - # since a helpful error message is generated when this - # one fails that tells you the values of expected and actual. - # - # 'MY STRING'.must_equal('my string'.upcase) - # - def is_equal(exp, msg=nil) - EqualityFailure.assert(self, exp, :message=>msg, :backtrace=>caller) - end - - # Passes if expected != actual - # - # 'some string'.is_unequal('some other string') - # - def is_not_equal(exp, msg=nil) - EqualityFailure.refute(self, :message=>msg, :backtrace=>caller) - end - - alias_method :is_unequal, :is_not_equal - - # ExecutionFailure - - # Passes if the block yields successfully. - # - # proc.is_executable("Couldn't do the thing") - # - def is_executable(msg=nil) - ExecutionFailure.assert(:message=>msg, :backtrace=>caller, &self) - end - - # Passes if the block does not yield successfully. - # - # proc.is_not_executable("Couldn't do the thing") - # - def is_not_executable(msg=nil, &blk) - ExecutionFailure.refute(:message=>msg, :backtrace=>caller, &self) - end - - # FalseFailure - - # Passed if object is +false+. - # - def is_false(exp, msg=nil) - FalseFailure.assert(exp, :message=>msg, :backtrace=>caller) - end - - # Passed if object is not +false+. - # - # assert_not_false(false) - # - def is_not_false(exp, msg=nil) - FalseFailure.refute(exp, :message=>msg, :backtrace=>caller) - end - - # IdentityFailure - - # Passes if actual is the same exact object as expected. - # - # object.is_identical(object) - # - def is_identical(exp) - IdentityFailure.assert(self, exp, :message=>msg, :backtrace=>caller) - end - - # Passes if actual is not the same exact object as expected. - # - # object.is_not_identical(other) - # - def is_not_identical(exp) - IdentityFailure.refute(self, exp, :message=>msg, :backtrace=>caller) - end - - # InstanceFailure - - # Passes if object is an instance of class. - # - # 'foo'.is_instance_of(String) - # - def is_instance_of(cls, msg=nil) - InstanceFailure.assert(self, cls, :message=>msg, :backtrace=>caller) - end - - # Passes if object is not an instance of class. - # - # 'foo'.is_not_instance_of(Integer) - # - def is_not_instance_of(cls, msg=nil) - InstanceFailure.refute(self, cls, :message=>msg, :backtrace=>caller) - end - - # KindFailure - - # Passes if object is a kind of class. - # - # object.is_kind(Object) - # - def is_kind(cls, msg=nil) - KindFailure.assert(self, cls, :message=>msg, :backtrace=>caller) - end - - # Passes if object is not a kind of class. - # - # object.is_not_kind(Object) - # - def is_not_kind(cls, msg=nil) - KindFailure.refute(self, cls, :message=>msg, :backtrace=>caller) - end - - # MatchFailure - - # Passes if object matches pattern using `#=~` method. - # - # 'one 2 three'.is_match(/two/) - # - def is_match(exp, msg=nil) - MatchFailure.assert(self, exp, :message=>msg, :backtrace=>caller) - end - - # Passes if object does not match pattern using `#=~` method. - # - # 'one 2 three'.is_not_match(/two/) - # - def is_not_match(exp, msg=nil) - MatchFailure.refute(self, exp, :message=>msg, :backtrace=>caller) - end - - # NilFailure - - # Passed if object is +nil+. - # - # object.is_nil - # - def is_nil(exp, msg=nil) - NilFailure.assert(exp, :message=>msg, :backtrace=>caller) - end - - # Passed if object is not +nil+. - # - # object.is_not_nil - # - def is_not_nil(exp, msg=nil) - NilFailure.refute(exp, :message=>msg, :backtrace=>caller) - end - - # RaiseFailure - - # Passes if the procedure raises a given exception. - # - # RuntimeError.is_raised{ raise 'Boom!!!' } - # - def does_raise(exp, msg=nil, call=nil) - RaiseFailure.assert(exp, msg=nil, call=nil, &self) - end - - # Passes if the procedure *does not* raise a given exceptions. - # - # IOError.is_not_raised{ raise 'Boom!!!' } - # - def does_not_raise(exp, msg=nil, call=nil) - RaiseFailure.refute(exp, msg, call, &self) - end - - # Passes if the procedure raises a given exception. - # - # lambda{ raise 'Boom!!!' }.does_raise(RuntimeError) - # - def is_raised(exp, msg=nil, call=nil, &blk) - RaiseFailure.assert(exp, msg=nil, call=nil, &blk) - end - - # Passes if the procedure *does not* raise a given exceptions. - # - # lambda{ raise 'Boom!!!' }.does_not_raise(IOError) - # - def is_not_raised(exp, msg=nil, call=nil, &blk) - RaiseFailure.refute(exp, msg, call, &blk) - end - - # ResponseFailure - - # Passes if +object+ respond_to? +methods+. - # - # 'bugbear'.does_respond(:slice) - # - def does_respond(method, msg=nil) - ResponseFailure.assert(self, method, :message=>msg, :backtrace=>caller) - end - - # Passes if +object+ does not respond_to? +methods+. - # - # 'bugbear'.does_not_respond(:slice) - # - def does_not_respond(method, msg=nil) - ResponseFailure.refute(self, method, :message=>msg, :backtrace=>caller) - end - - # SameFailure - - # Passes if +expected+ .eql? +actual+. - # - # Note that the ordering of arguments is important, - # since a helpful error message is generated when this - # one fails that tells you the values of expected and actual. - # - # 'MY STRING'.is_same('my string'.upcase) - # - def is_same(exp, msg=nil) - SameFailure.assert(self, exp, :message=>msg, :backtrace=>caller) - end - - alias_method :is_eql, :is_not_same - - # Passes if not +expected+ .eql? +actual+. - # - # 'MY STRING'.is_not_same('some other string') - # - def is_not_same(exp, msg=nil) - SameFailure.refute(self, exp, :message=>msg, :backtrace=>caller) - end - - alias_method :is_not_eql, :is_not_same - - # ThrowFailure - - # Passes if the block throws expected_symbol - # - # :done.is_thrown do - # throw :done - # end - # - def is_thrown(sym, msg=nil, &blk) - ThrowFailure.assert(sym, :message=>msg, :backtrace=>caller, &blk) - end - - # Passes if the block throws expected_symbol - # - # :done.is_not_thrown do - # throw :undone - # end - # - def is_not_thrown(sym, msg=nil, &blk) - ThrowFailure.refute(sym, :message=>msg, :backtrace=>caller, &blk) - end - - # TrueFailure - - # Passed if object is +true+. - # - # object.is_true - # - def is_true(exp, msg=nil) - TrueFailure.assert(exp, :message=>msg, :backtrace=>caller) - end - - # Passed if object is not +true+. - # - # object.is_not_true - # - def is_not_true(exp, msg=nil) - TrueFailure.refute(exp, :message=>msg, :backtrace=>caller) - end - - end - - end - -end diff --git a/work/defunct/static_assertion_methods/objective/must.rb b/work/defunct/static_assertion_methods/objective/must.rb deleted file mode 100644 index e3468ab..0000000 --- a/work/defunct/static_assertion_methods/objective/must.rb +++ /dev/null @@ -1,330 +0,0 @@ -module Assay - - module Nomenclature - - # MiniMust assertion nomenclature is compatible with MiniTest's - # "minispec" Expectaion methods. - # - module MustObjectives - - # - def self.activate - ::Object.__send__(:include, self) - end - - # CompareFailure - - # Passes if object is like criterion. - # - # object.must_be_like(criterion) - # - # See {CompareFailure}. - # - def must_be_like(exp) - CompareFailure.assert(self, exp, :message=>msg, :backtrace=>caller) - end - - # Passes if object is not like criterion using {CompareFailure}. - # - # object.wont_be_like(criterion) - # - # See {CompareFailure}. - # - def wont_be_like(act) - CompareFailure.refute(self, exp, :message=>msg, :backtrace=>caller) - end - - # DeltaFailure - - # Passes if expected and actual are equal within delta tolerance. - # - # assert_in_delta 0.05, (50000.0 / 10**6), 0.00001 - # - # See {DeltaFailure}. - # - def must_be_within_delta(exp, delta, msg=nil) - DeltaFailure.assert(self, exp, delta, :message=>msg, :backtrace=>caller) - end - - # Passes if expected and actual are equal not within delta tolerance. - # - # assert_not_in_delta 0.05, (50000.0 / 10**6), 0.00001 - # - # See {DeltaFailure}. - # - def wont_be_within_delta(exp, delta, msg=nil) - DeltaFailure.refute(self, exp, delta, :message=>msg, :backtrace=>caller) - end - - # EmptyFailure - - # Passes if object is empty. - # - # object.must_be_empty - # - def must_be_empty - EmptyFailure.assert(self, :message=>msg, :backtrace=>caller) - end - - # Passes if object is not empty. - # - # object.wont_be_empty - # - def wont_be_empty - EmptyFailure.refute(self, :message=>msg, :backtrace=>caller) - end - - # EqualityFailure - - # Passes if expected == +actual. - # - # Note that the ordering of arguments is important, - # since a helpful error message is generated when this - # one fails that tells you the values of expected and actual. - # - # 'MY STRING'.must_equal('my string'.upcase) - # - def must_equal(exp, msg=nil) - EqualityFailure.assert(self, exp, :message=>msg, :backtrace=>caller) - end - - # Passes if expected != actual - # - # 'some string'.wont_equal('some other string') - # - def assert_not_equal(exp, msg=nil) - EqualityFailure.refute(self, :message=>msg, :backtrace=>caller) - end - - # ExecutionFailure - - # Passes if the block yields successfully. - # - # proc.must_execute("Couldn't do the thing") - # - def must_execute(msg=nil) - ExecutionFailure.assert(:message=>msg, :backtrace=>caller, &self) - end - - # Passes if the block does not yield successfully. - # - # refute_executes "Couldn't do the thing" do - # do_the_thing - # end - # - def wont_execute(msg=nil, &blk) - ExecutionFailure.refute(:message=>msg, :backtrace=>caller, &self) - end - - # FalseFailure - - # Passed if object is +false+. - # - def must_be_false(exp, msg=nil) - FalseFailure.assert(exp, :message=>msg, :backtrace=>caller) - end - - # Passed if object is not +false+. - # - # assert_not_false(false) - # - def wont_be_false(exp, msg=nil) - FalseFailure.refute(exp, :message=>msg, :backtrace=>caller) - end - - # IdentityFailure - - # Passes if actual is the same exact object as expected. - # - # object.must_be_identical_to(object) - # - def must_be_identical_to(exp) - IdentityFailure.assert(self, exp, :message=>msg, :backtrace=>caller) - end - - # Passes if actual is not the same exact object as expected. - # - # object.wont_be_identical_to(other) - # - def wont_be_identical_to(exp) - IdentityFailure.refute(self, exp, :message=>msg, :backtrace=>caller) - end - - # InstanceFailure - - # Passes if object is an instance of class. - # - # 'foo'.must_be_instance_of(String) - # - def must_be_instance_of(cls, msg=nil) - InstanceFailure.assert(self, cls, :message=>msg, :backtrace=>caller) - end - - # Passes if object is not an instance of class. - # - # 'foo'.wont_be_instance_of(Integer) - # - def wont_be_instance_of(cls, msg=nil) - InstanceFailure.refute(self, cls, :message=>msg, :backtrace=>caller) - end - - # KindFailure - - # Passes if object is a kind of class. - # - # assert_kind_of(Object, 'foo') - # - def must_be_kind_of(cls, msg=nil) - KindFailure.assert(self, cls, :message=>msg, :backtrace=>caller) - end - - # Passes if object is not a kind of class. - # - # assert_not_kind_of(Object, 'foo') - # - def wont_be_kind_of(cls, msg=nil) - KindFailure.refute(self, cls, :message=>msg, :backtrace=>caller) - end - - # MatchFailure - - # Passes if object matches pattern using `#=~` method. - # - # 'one 2 three'.must_match(/two/) - # - def must_match(exp, msg=nil) - MatchFailure.assert(self, exp, :message=>msg, :backtrace=>caller) - end - - # Passes if object does not match pattern using `#=~` method. - # - # 'one 2 three'.wont_match(/two/) - # - def wont_match(exp, msg=nil) - MatchFailure.refute(self, exp, :message=>msg, :backtrace=>caller) - end - - # NilFailure - - # Passed if object is +nil+. - # - def must_be_nil(exp, msg=nil) - NilFailure.assert(exp, :message=>msg, :backtrace=>caller) - end - - # Passed if object is not +nil+. - # - # assert_not_nil(true) - # - def wont_be_nil(exp, msg=nil) - NilFailure.refute(exp, :message=>msg, :backtrace=>caller) - end - - # RaiseFailure - - # Passes if the procedure raises a given exception. - # - # lambda{ raise 'Boom!!!' }.must_raise(RuntimeError) - # - def must_raise(exp, msg=nil, call=nil) - RaiseFailure.assert(exp, msg=nil, call=nil, &self) - end - - # Passes if the procedure *does not* raise a given exceptions. - # - # lambda{ raise 'Boom!!!' }.wont_raise(IOError) - # - def wont_raise(exp, msg=nil, call=nil) #:yeild: - RaiseFailure.refute(exp, msg, call, &self) - end - - # ResponseFailure - - # Passes if +object+ respond_to? +methods+. - # - # 'bugbear'.must_respond_to(:slice) - # - def must_respond_to(method, msg=nil) - ResponseFailure.assert(self, method, :message=>msg, :backtrace=>caller) - end - alias_method :assert_responds_to, :assert_respond_to - - # Passes if +object+ does not respond_to? +methods+. - # - # 'bugbear'.wont_respond_to(:slice) - # - def wont_respond_to(method, msg=nil) - ResponseFailure.refute(self, method, :message=>msg, :backtrace=>caller) - end - - # SameFailure - - # Passes if +expected+ .eql? +actual+. - # - # Note that the ordering of arguments is important, - # since a helpful error message is generated when this - # one fails that tells you the values of expected and actual. - # - # 'MY STRING'.must_be_same_as('my string'.upcase) - # - def must_be_same_as(exp, msg=nil) - SameFailure.assert(self, exp, :message=>msg, :backtrace=>caller) - end - - alias_method :must_eql, :must_be_same_as - - # Passes if not +expected+ .eql? +actual+. - # - # 'MY STRING'.wont_be_same_as('some other string') - # - def wont_be_same_as(exp, msg=nil) - SameFailure.refute(self, exp, :message=>msg, :backtrace=>caller) - end - - alias_method :wont_eql, :wont_be_same_as - - # ThrowFailure - - # Passes if the block throws expected_symbol - # - # assert_throws :done do - # throw :done - # end - # - def must_throw(sym, msg=nil) - ThrowFailure.assert(sym, :message=>msg, :backtrace=>caller, &self) - end - - # Passes if the block throws expected_symbol - # - # refute_throws :done do - # throw :chimp - # end - # - def wont_throw(sym, msg=nil) - ThrowFailure.refute(sym, :message=>msg, :backtrace=>caller, &self) - end - - # TrueFailure - - # Passed if object is +true+. - # - # object.must_be_true - # - def must_be_true(exp, msg=nil) - TrueFailure.assert(exp, :message=>msg, :backtrace=>caller) - end - - # Passed if object is not +true+. - # - # object.wont_be_true - # - def wont_be_true(exp, msg=nil) - TrueFailure.refute(exp, :message=>msg, :backtrace=>caller) - end - - end - - end - -end diff --git a/work/defunct/tobe.rb b/work/defunct/tobe.rb deleted file mode 100644 index b8e1e5d..0000000 --- a/work/defunct/tobe.rb +++ /dev/null @@ -1,56 +0,0 @@ -module Assay - - # This module provides assertion mettods as object extensions in the - # form of bang methods. - # - # Examples - # - # "string".is.instance_of?(String) - # - # "string".is.equal?("string") - # - # "string".should be.not_equal?("another") - # - class ToBe - - NAMES = { - :== => :equal, - :=~ => [:case, :match] - } - - # - def new(target) - @target = target - end - - # - # Meta-programming routine for creating all the subjective methods. - # - def self.bootstrap - Assay.constants.each do |const| - next unless const < Assertion - - name = (const.operator || cont.assertive_name).to_sym - names = [NAMES[name] || name].flatten - - name.each do |name| - define_method("#{name}") do |*args| - const.assert(@target, *args) - end - - define_method("not_#{name}") do |*args| - const.refute(@target, *args) - end - end - end - end - - # - # Do it! - # - bootstrap - - end - -end -