├── lib ├── assay-testunit.yml ├── assay │ └── testunit.rb ├── assay-testunit.rb └── assay-testunit │ └── assertions.rb ├── Gemfile ├── demo ├── applique │ ├── setup.rb │ └── helper.rb └── 01_testunit_assertions.md ├── .gitignore ├── .yardopts ├── .travis.yml ├── HISTORY.md ├── Config.rb ├── Manifest.txt ├── Assembly ├── Metadata.yml ├── LICENSE.txt ├── .index ├── README.md ├── assay-testunit.gemspec └── work └── reference └── legacy.rb /lib/assay-testunit.yml: -------------------------------------------------------------------------------- 1 | ../.ruby -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source :rubygems 2 | gemspec 3 | -------------------------------------------------------------------------------- /demo/applique/setup.rb: -------------------------------------------------------------------------------- 1 | require 'assay/testunit' 2 | -------------------------------------------------------------------------------- /lib/assay/testunit.rb: -------------------------------------------------------------------------------- 1 | require 'assay-testunit' 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .reap/digest 2 | .yardoc 3 | log 4 | pkg 5 | tmp 6 | site 7 | web 8 | work/trash 9 | DEMO* 10 | -------------------------------------------------------------------------------- /.yardopts: -------------------------------------------------------------------------------- 1 | --title "Assay TestUnit" 2 | --readme README.rdoc 3 | --protected 4 | --private 5 | lib 6 | - 7 | [A-Z]*.* 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | script: "bundle exec qed" 3 | rvm: 4 | - 1.9.2 5 | - 1.9.3 6 | - rbx-19mode 7 | - jruby-19mode 8 | 9 | -------------------------------------------------------------------------------- /HISTORY.md: -------------------------------------------------------------------------------- 1 | # HISTORY 2 | 3 | ## 0.1.0 / 2012-01-25 4 | 5 | This is the initial release of Assay TestUnit. 6 | 7 | Changes: 8 | 9 | * Happy Birthday! 10 | 11 | -------------------------------------------------------------------------------- /lib/assay-testunit.rb: -------------------------------------------------------------------------------- 1 | require 'assay' 2 | require 'assay-testunit/assertions' 3 | 4 | # This module holds all assertion methods, which can be mixed into 5 | # one's testing scope (e.g. World). 6 | # 7 | module Assay::Assertions 8 | include Assay::TestUnit::Assertions 9 | end 10 | 11 | -------------------------------------------------------------------------------- /Config.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # 4 | # Code coverage profile. 5 | # 6 | profile :cov do 7 | 8 | config :qed do 9 | require 'simplecov' 10 | SimpleCov.start do 11 | coverage_dir 'log/coverage' 12 | #add_group "RSpec", "lib/assay/rspec.rb" 13 | end 14 | end 15 | 16 | end 17 | 18 | -------------------------------------------------------------------------------- /Manifest.txt: -------------------------------------------------------------------------------- 1 | #!mast .index .yardopts bin data demo lib spec test [A-Z]*.* 2 | .index 3 | .yardopts 4 | demo/01_testunit_assertions.md 5 | demo/applique/helper.rb 6 | demo/applique/setup.rb 7 | lib/assay/testunit.rb 8 | lib/assay-testunit/assertions.rb 9 | lib/assay-testunit.rb 10 | lib/assay-testunit.yml 11 | Metadata.yml 12 | LICENSE.txt 13 | HISTORY.md 14 | README.md 15 | DEMOS.md 16 | Config.rb 17 | -------------------------------------------------------------------------------- /Assembly: -------------------------------------------------------------------------------- 1 | --- 2 | github: 3 | gh_pages: web 4 | 5 | gem: 6 | active: true 7 | 8 | dnote: 9 | title: Source Notes 10 | output: log/notes.html 11 | 12 | vclog: 13 | output: 14 | - log/history.html 15 | - log/changes.html 16 | 17 | email: 18 | mailto: 19 | - ruby-talk@ruby-lang.org 20 | - rubyworks-mailinglist@googlegroups.com 21 | 22 | qed: 23 | files: demo/*.md 24 | 25 | qedoc: 26 | files: demo/*.md 27 | output: 28 | - DEMOS.md 29 | - web/demos.html 30 | 31 | -------------------------------------------------------------------------------- /demo/applique/helper.rb: -------------------------------------------------------------------------------- 1 | 2 | # Very simple helper assertion system, so we can test 3 | # Assay without name clashes. 4 | 5 | def assert(truth, msg=nil, trace=nil) 6 | if truth 7 | increment_counts(:pass) 8 | else 9 | increment_counts(:fail) 10 | raise Assertion, msg || "assert failed", trace || caller 11 | end 12 | end 13 | 14 | def refute(truth) 15 | assert(!truth, "refute failed", caller) 16 | end 17 | 18 | def expect(error) 19 | counts = $ASSERTION_COUNTS.dup 20 | begin 21 | yield 22 | $ASSERTION_COUNTS = counts 23 | increment_counts(:fail) 24 | raise Assertion, "#{error} not raised.", caller 25 | rescue error 26 | $ASSERTION_COUNTS = counts 27 | increment_counts(:pass) 28 | end 29 | end 30 | 31 | def increment_counts(which) 32 | case which 33 | when :pass 34 | $ASSERTION_COUNTS[:pass] += 1 35 | when :fail 36 | $ASSERTION_COUNTS[:fail] += 1 37 | end 38 | $ASSERTION_COUNTS[:total] += 1 39 | end 40 | 41 | -------------------------------------------------------------------------------- /Metadata.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: 3 | assay-testunit 4 | 5 | version: 6 | 0.1.0 7 | 8 | title: 9 | Assay TestUnit 10 | 11 | summary: 12 | TestUnit on Assay 13 | 14 | description: 15 | Assay TestUnit defines a set of TestUnit-compatible assertion methods which 16 | depend on Assay's assertion classes. This allows developers to change 17 | test frameworks without having to change a slew of previously 18 | defined assertions. 19 | 20 | resources: 21 | home: http://rubyworks.github.com/assay-testunit 22 | docs: http://rubydoc.info/gems/assay-testunit 23 | code: http://github.com/rubyworks/assay-testunit 24 | mail: http://groups.google.com/groups/rubyworks-mailinglist 25 | 26 | requirements: 27 | - assay 28 | - detroit (build) 29 | - qed (test) 30 | 31 | repositories: 32 | upstream: git@github.com:rubyworks/assay-testunit.git 33 | 34 | organizations: 35 | - Rubyworks 36 | 37 | authors: 38 | - Thomas Sawyer 39 | 40 | copyrights: 41 | - (c) 2012 Thomas Sawyer (BSD-2-Clause) 42 | 43 | created: 44 | 2012-01-18 45 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Assay TestUnit (http://rubyworks.github.com/assay-testunit) 2 | 3 | Copyright (c) 2012 Rubyworks. 4 | 5 | All rights reserved. 6 | 7 | License (spdx) BSD-2-Clause. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions are met: 11 | 12 | 1. Redistributions of source code must retain the above copyright notice, 13 | this list of conditions and the following disclaimer. 14 | 15 | 2. Redistributions in binary form must reproduce the above copyright 16 | notice, this list of conditions and the following disclaimer in the 17 | documentation and/or other materials provided with the distribution. 18 | 19 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 21 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 26 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 28 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /.index: -------------------------------------------------------------------------------- 1 | --- 2 | type: ruby 3 | revision: 2013 4 | sources: 5 | - Metadata.yml 6 | authors: 7 | - name: Thomas Sawyer 8 | email: transfire@gmail.com 9 | organizations: 10 | - name: Rubyworks 11 | requirements: 12 | - name: assay 13 | - groups: 14 | - build 15 | development: true 16 | name: detroit 17 | - groups: 18 | - test 19 | development: true 20 | name: qed 21 | conflicts: [] 22 | alternatives: [] 23 | resources: 24 | - type: home 25 | uri: http://rubyworks.github.com/assay-testunit 26 | label: Homepage 27 | - type: docs 28 | uri: http://rubydoc.info/gems/assay-testunit 29 | label: Documentation 30 | - type: code 31 | uri: http://github.com/rubyworks/assay-testunit 32 | label: Source Code 33 | - type: mail 34 | uri: http://groups.google.com/groups/rubyworks-mailinglist 35 | label: Mailing List 36 | repositories: 37 | - name: upstream 38 | scm: git 39 | uri: git@github.com:rubyworks/assay-testunit.git 40 | categories: [] 41 | load_path: 42 | - lib 43 | copyrights: 44 | - holder: Thomas Sawyer 45 | year: '2012' 46 | license: BSD-2-Clause 47 | name: assay-testunit 48 | title: Assay TestUnit 49 | version: 0.1.0 50 | summary: TestUnit on Assay 51 | description: Assay TestUnit defines a set of TestUnit-compatible assertion methods 52 | which depend on Assay's assertion classes. This allows developers to change test 53 | frameworks without having to change a slew of previously defined assertions. 54 | created: '2012-01-18' 55 | date: '2012-12-08' 56 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Assay TestUnit 2 | 3 | [Homepage](http://rubyworks.github.com/assay-testunit) / 4 | [Report Issue](http://github.com/rubyworks/assay-testunit/issues) / 5 | [Source Code](http://github.com/rubyworks/assay-testunit) / 6 | [Mailing List](http://groups.google.com/group/rubyworks-mailinglist) 7 | 8 |
9 | 10 | Assay TestUnit is a compatibility layer for using TestUnit's assertion 11 | notation with any [BRASS](http://rubyworks.github.com/brass)-compliant 12 | test framwwork. This allows developers to change test frameworks without 13 | having to change a slew of previously defined assertions calls. 14 | 15 | Assay TestUnit is built on top of the [Assay](http://rubyworks.github.com/assay) 16 | assertions framework. Assay TestUnit defines a set of TestUnit-compatible assertion 17 | methods which depend on Assay's assertion classes. Assay defines assertions in the 18 | same way that Ruby defines exceptions. An assertion is nothing more that an extended 19 | Exception subclass. Assay provides a complete set of these assertion classes for all 20 | common assertion needs. See [Assay](http://rubyworks.github.com/assay) 21 | project for more information on this library. 22 | 23 | 24 | ## Synopsis 25 | 26 | Simply require the `assay/testunit` script, and include the `Assay::TestUnit::Assertions` 27 | or `Assay::Assertions` mixin module into your test scope, where your test framework 28 | requires it (which may be as simple as the toplevel namespace). 29 | 30 | require 'assay/testunit' 31 | 32 | include Assay::Assertions 33 | 34 | Now assertions can be made just as if you were using TestUnit. 35 | 36 | assert_equal(10, 5+5) 37 | 38 | assert_kind_of(Integer, 10) 39 | 40 | 41 | ## Limitations 42 | 43 | Compatibility is not 100%, though it is very close. Compatibility will improve 44 | with future releases. Please feel _obligated_ to submit a patch if you need a 45 | missing a feature ;) 46 | 47 | Assay TestUnit is also a Ruby 1.9+ only library. 48 | 49 | 50 | ## Installation 51 | 52 | ### Via RubyGems 53 | 54 | To install with RubyGems simply open a console and type: 55 | 56 | $ gem install assay-testunit 57 | 58 | ### Via Setup.rb (not recommended) 59 | 60 | Site installation with the tarball can be done with Ruby Setup 61 | (`gem install setup)`. See http://rubyworks.github.com/setup. 62 | 63 | 64 | ## License & Copyright 65 | 66 | Copyright (c) 2012 Rubyworks 67 | 68 | This program is distributed under the terms of the *BSD-2-Clause* license. 69 | 70 | See COPYING.rdoc file for details. 71 | 72 | -------------------------------------------------------------------------------- /demo/01_testunit_assertions.md: -------------------------------------------------------------------------------- 1 | # Assertion Methods 2 | 3 | To use the assertion methods, first require the library. 4 | 5 | require 'assay/testunit' 6 | 7 | Then include them into your test scope. 8 | 9 | include ::Assay::Assertions 10 | 11 | ## assert_equal 12 | 13 | assert_equal(1,1) 14 | 15 | expect ::EqualAssay do 16 | assert_equal(1,2) 17 | end 18 | 19 | assert_not_equal(1,2) 20 | 21 | ## assert_true 22 | 23 | assert_true(true) 24 | 25 | expect ::TrueAssay do 26 | assert_true(false) 27 | end 28 | 29 | assert_not_true(false) 30 | assert_not_true(nil) 31 | 32 | ## assert_false 33 | 34 | assert_false(false) 35 | 36 | expect ::FalseAssay do 37 | assert_false(true) 38 | end 39 | 40 | assert_not_false(true) 41 | assert_not_false(nil) 42 | 43 | ## assert_nil 44 | 45 | assert_nil(nil) 46 | 47 | expect ::NilAssay do 48 | assert_nil(true) 49 | end 50 | 51 | assert_not_nil(true) 52 | assert_not_nil(false) 53 | 54 | ## assert_in_delta 55 | 56 | assert_in_delta(1, 1.5, 2) 57 | 58 | expect ::WithinAssay do 59 | assert_in_delta(1, 2.5, 1) 60 | end 61 | 62 | assert_not_in_delta(1, 2, 0.5) 63 | 64 | ## assert_in_epsilon 65 | 66 | assert_in_epsilon(1, 1.5, 2) 67 | assert_in_epsilon(0, 1.5, 2) 68 | 69 | expect ::WithinAssay do 70 | assert_in_epsilon(1, 2.5, 1) 71 | end 72 | 73 | assert_not_in_epsilon(1, 2.5, 1) 74 | assert_not_in_epsilon(0, 2.5, 1) 75 | 76 | ## assert_match 77 | 78 | assert_match(/a/, "abc") 79 | 80 | expect ::MatchAssay do 81 | assert_match(/x/, "abc") 82 | end 83 | 84 | assert_not_match(/a/, "bcd") 85 | 86 | ## assert_no_match 87 | 88 | assert_no_match(/a/, "bcd") 89 | 90 | expect ::NoMatchAssay do 91 | assert_no_match(/a/, "abc") 92 | end 93 | 94 | ## assert_empty 95 | 96 | assert_empty([]) 97 | 98 | expect ::EmptyAssay do 99 | assert_empty([1,2,3]) 100 | end 101 | 102 | assert_not_empty([1,2,3]) 103 | 104 | ## assert_include 105 | 106 | assert_includes([1,2,3], 1) 107 | 108 | expect ::IncludeAssay do 109 | assert_includes([1,2,3], 4) 110 | end 111 | 112 | assert_not_includes([1,2,3], 4) 113 | 114 | ## assert_same 115 | 116 | assert_same(:a, :a) 117 | 118 | expect ::IdentityAssay do 119 | assert_same("a", "a") 120 | end 121 | 122 | assert_not_same(:a, :b) 123 | 124 | ## assert_instance_of 125 | 126 | assert_instance_of(Fixnum, 1) 127 | 128 | expect ::InstanceAssay do 129 | assert_instance_of(String, 1) 130 | end 131 | 132 | assert_not_instance_of(String, 1) 133 | 134 | ## assert_kind_of 135 | 136 | assert_kind_of(Integer, 1) 137 | 138 | expect ::KindAssay do 139 | assert_kind_of(String, 1) 140 | end 141 | 142 | assert_not_kind_of(String, 1) 143 | 144 | ## assert_raise 145 | 146 | assert_raise(ArgumentError){ raise ArgumentError } 147 | 148 | expect ::RaiseAssay do 149 | assert_raise(ArgumentError){ raise TypeError } 150 | end 151 | 152 | assert_not_raised(ArgumentError){ raise TypeError } 153 | 154 | ## assert_raise_kind_of 155 | 156 | assert_raise_kind_of(StandardError){ raise } 157 | 158 | expect ::RescueAssay do 159 | assert_raise_kind_of(ArgumentError){ raise TypeError } 160 | end 161 | 162 | assert_raise_kind_of(Exception){ raise } 163 | 164 | ## assert_nothing_raised 165 | 166 | assert_nothing_raised{ true } 167 | assert_nothing_raised{ nil } 168 | 169 | expect ::RescueAssay do 170 | assert_nothing_raised{ raise } 171 | end 172 | 173 | ## assert_respond_to 174 | 175 | assert_respond_to("string", :upcase) 176 | 177 | expect ::RespondAssay do 178 | assert_respond_to("string", :not_a_method) 179 | end 180 | 181 | assert_not_respond_to("string", :not_a_method) 182 | 183 | ## assert_block 184 | 185 | assert_block{ :ok } 186 | 187 | expect ::ExecutionAssay do 188 | assert_block{ raise } 189 | end 190 | 191 | ## assert_throw 192 | 193 | assert_throw(:foo){ throw :foo } 194 | 195 | expect ::ThrowAssay do 196 | assert_throw(:foo){ throw :bar } 197 | end 198 | 199 | assert_not_thrown(:foo){ throw :bar } 200 | 201 | ## assert_nothing_thrown 202 | 203 | assert_nothing_thrown{ nil } 204 | 205 | expect ::ThrowAssay do 206 | assert_nothing_thrown{ throw :bar } 207 | end 208 | 209 | ## assert_compare 210 | 211 | assert_compare(1, :<, 2) 212 | assert_compare(2, :>, 1) 213 | assert_compare(1, :<=, 1) 214 | assert_compare(1, :>=, 1) 215 | assert_compare(1, :<=, 2) 216 | assert_compare(2, :>=, 1) 217 | assert_compare(1, :==, 1) 218 | 219 | expect ArgumentError do 220 | assert_compare(1, :<=>, 1) 221 | end 222 | 223 | ## assert_operator 224 | 225 | assert_operator([], :<<, 1) 226 | 227 | ## assert_predicate 228 | 229 | assert_predicate(10, :even?) 230 | 231 | assert_not_predicate(10, :odd?) 232 | 233 | ## assert_path_exist 234 | 235 | assert_path_exist(__FILE__) 236 | 237 | assert_path_not_exist(__FILE__ + '.foobar') 238 | 239 | ## assert_boolean 240 | 241 | assert_boolean(true) 242 | assert_boolean(false) 243 | 244 | assert_not_boolean(nil) 245 | 246 | ## assert_alike 247 | 248 | assert_alike(1,1) 249 | assert_alike(1,1.0) 250 | 251 | expect ::LikeAssay do 252 | assert_alike(1,"1") 253 | end 254 | 255 | assert_not_alike(1,"1") 256 | 257 | ## assert_equivalent 258 | 259 | assert_equivalent(1, 1) 260 | 261 | expect ::EqualityAssay do 262 | assert_equivalent(1, 1.0) 263 | end 264 | 265 | assert_not_equivalent(1, 1.0) 266 | 267 | -------------------------------------------------------------------------------- /assay-testunit.gemspec: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | require 'yaml' 4 | require 'pathname' 5 | 6 | module Indexer 7 | 8 | # Convert index data into a gemspec. 9 | # 10 | # Notes: 11 | # * Assumes all executables are in bin/. 12 | # * Does not yet handle default_executable setting. 13 | # * Does not yet handle platform setting. 14 | # * Does not yet handle required_ruby_version. 15 | # * Support for rdoc entries is weak. 16 | # 17 | class GemspecExporter 18 | 19 | # File globs to include in package (unless manifest file exists). 20 | FILES = ".index .ruby .yardopts alt bin ext lib man spec test [A-Z]*.*" unless defined?(FILES) 21 | 22 | # File globs to omit. 23 | OMIT = "Config.rb" unless defined?(OMIT) 24 | 25 | # Standard file patterns. 26 | PATTERNS = { 27 | :root => '{.index,Gemfile}', 28 | :bin => 'bin/*', 29 | :lib => 'lib/{**/}*', #.rb', 30 | :ext => 'ext/{**/}extconf.rb', 31 | :doc => '*.{txt,rdoc,md,markdown,tt,textile}', 32 | :test => '{test,spec}/{**/}*.rb' 33 | } unless defined?(PATTERNS) 34 | 35 | # For which revision of indexer spec is this converter intended? 36 | REVISION = 2013 unless defined?(REVISION) 37 | 38 | # 39 | def self.gemspec 40 | new.to_gemspec 41 | end 42 | 43 | # 44 | attr :metadata 45 | 46 | # 47 | def initialize(metadata=nil) 48 | @root_check = false 49 | 50 | if metadata 51 | root_dir = metadata.delete(:root) 52 | if root_dir 53 | @root = root_dir 54 | @root_check = true 55 | end 56 | metadata = nil if metadata.empty? 57 | end 58 | 59 | @metadata = metadata || YAML.load_file(root + '.index') 60 | 61 | if @metadata['revision'].to_i != REVISION 62 | warn "This gemspec exporter was not designed for this revision of index metadata." 63 | end 64 | end 65 | 66 | # 67 | def has_root? 68 | root ? true : false 69 | end 70 | 71 | # 72 | def root 73 | return @root if @root || @root_check 74 | @root_check = true 75 | @root = find_root 76 | end 77 | 78 | # 79 | def manifest 80 | return nil unless root 81 | @manifest ||= Dir.glob(root + 'manifest{,.txt}', File::FNM_CASEFOLD).first 82 | end 83 | 84 | # 85 | def scm 86 | return nil unless root 87 | @scm ||= %w{git hg}.find{ |m| (root + ".#{m}").directory? }.to_sym 88 | end 89 | 90 | # 91 | def files 92 | return [] unless root 93 | @files ||= \ 94 | if manifest 95 | File.readlines(manifest). 96 | map{ |line| line.strip }. 97 | reject{ |line| line.empty? || line[0,1] == '#' } 98 | else 99 | list = [] 100 | Dir.chdir(root) do 101 | FILES.split(/\s+/).each do |pattern| 102 | list.concat(glob(pattern)) 103 | end 104 | OMIT.split(/\s+/).each do |pattern| 105 | list = list - glob(pattern) 106 | end 107 | end 108 | list 109 | end.select{ |path| File.file?(path) }.uniq 110 | end 111 | 112 | # 113 | def glob_files(pattern) 114 | return [] unless root 115 | Dir.chdir(root) do 116 | Dir.glob(pattern).select do |path| 117 | File.file?(path) && files.include?(path) 118 | end 119 | end 120 | end 121 | 122 | def patterns 123 | PATTERNS 124 | end 125 | 126 | def executables 127 | @executables ||= \ 128 | glob_files(patterns[:bin]).map do |path| 129 | File.basename(path) 130 | end 131 | end 132 | 133 | def extensions 134 | @extensions ||= \ 135 | glob_files(patterns[:ext]).map do |path| 136 | File.basename(path) 137 | end 138 | end 139 | 140 | def name 141 | metadata['name'] || metadata['title'].downcase.gsub(/\W+/,'_') 142 | end 143 | 144 | def homepage 145 | page = ( 146 | metadata['resources'].find{ |r| r['type'] =~ /^home/i } || 147 | metadata['resources'].find{ |r| r['name'] =~ /^home/i } || 148 | metadata['resources'].find{ |r| r['name'] =~ /^web/i } 149 | ) 150 | page ? page['uri'] : false 151 | end 152 | 153 | def licenses 154 | metadata['copyrights'].map{ |c| c['license'] }.compact 155 | end 156 | 157 | def require_paths 158 | metadata['load_path'] || ['lib'] 159 | end 160 | 161 | # 162 | # Convert to gemnspec. 163 | # 164 | def to_gemspec 165 | if has_root? 166 | Gem::Specification.new do |gemspec| 167 | to_gemspec_data(gemspec) 168 | to_gemspec_paths(gemspec) 169 | end 170 | else 171 | Gem::Specification.new do |gemspec| 172 | to_gemspec_data(gemspec) 173 | to_gemspec_paths(gemspec) 174 | end 175 | end 176 | end 177 | 178 | # 179 | # Convert pure data settings. 180 | # 181 | def to_gemspec_data(gemspec) 182 | gemspec.name = name 183 | gemspec.version = metadata['version'] 184 | gemspec.summary = metadata['summary'] 185 | gemspec.description = metadata['description'] 186 | 187 | metadata['authors'].each do |author| 188 | gemspec.authors << author['name'] 189 | 190 | if author.has_key?('email') 191 | if gemspec.email 192 | gemspec.email << author['email'] 193 | else 194 | gemspec.email = [author['email']] 195 | end 196 | end 197 | end 198 | 199 | gemspec.licenses = licenses 200 | 201 | requirements = metadata['requirements'] || [] 202 | requirements.each do |req| 203 | next if req['optional'] 204 | next if req['external'] 205 | 206 | name = req['name'] 207 | groups = req['groups'] || [] 208 | 209 | version = gemify_version(req['version']) 210 | 211 | if groups.empty? or groups.include?('runtime') 212 | # populate runtime dependencies 213 | if gemspec.respond_to?(:add_runtime_dependency) 214 | gemspec.add_runtime_dependency(name,*version) 215 | else 216 | gemspec.add_dependency(name,*version) 217 | end 218 | else 219 | # populate development dependencies 220 | if gemspec.respond_to?(:add_development_dependency) 221 | gemspec.add_development_dependency(name,*version) 222 | else 223 | gemspec.add_dependency(name,*version) 224 | end 225 | end 226 | end 227 | 228 | # convert external dependencies into gemspec requirements 229 | requirements.each do |req| 230 | next unless req['external'] 231 | gemspec.requirements << ("%s-%s" % req.values_at('name', 'version')) 232 | end 233 | 234 | gemspec.homepage = homepage 235 | gemspec.require_paths = require_paths 236 | gemspec.post_install_message = metadata['install_message'] 237 | end 238 | 239 | # 240 | # Set gemspec settings that require a root directory path. 241 | # 242 | def to_gemspec_paths(gemspec) 243 | gemspec.files = files 244 | gemspec.extensions = extensions 245 | gemspec.executables = executables 246 | 247 | if Gem::VERSION < '1.7.' 248 | gemspec.default_executable = gemspec.executables.first 249 | end 250 | 251 | gemspec.test_files = glob_files(patterns[:test]) 252 | 253 | unless gemspec.files.include?('.document') 254 | gemspec.extra_rdoc_files = glob_files(patterns[:doc]) 255 | end 256 | end 257 | 258 | # 259 | # Return a copy of this file. This is used to generate a local 260 | # .gemspec file that can automatically read the index file. 261 | # 262 | def self.source_code 263 | File.read(__FILE__) 264 | end 265 | 266 | private 267 | 268 | def find_root 269 | root_files = patterns[:root] 270 | if Dir.glob(root_files).first 271 | Pathname.new(Dir.pwd) 272 | elsif Dir.glob("../#{ROOT}").first 273 | Pathname.new(Dir.pwd).parent 274 | else 275 | #raise "Can't find root of project containing `#{root_files}'." 276 | warn "Can't find root of project containing `#{root_files}'." 277 | nil 278 | end 279 | end 280 | 281 | def glob(pattern) 282 | if File.directory?(pattern) 283 | Dir.glob(File.join(pattern, '**', '*')) 284 | else 285 | Dir.glob(pattern) 286 | end 287 | end 288 | 289 | def gemify_version(version) 290 | case version 291 | when /^(.*?)\+$/ 292 | ">= #{$1}" 293 | when /^(.*?)\-$/ 294 | "< #{$1}" 295 | when /^(.*?)\~$/ 296 | "~> #{$1}" 297 | else 298 | version 299 | end 300 | end 301 | 302 | end 303 | 304 | end 305 | 306 | Indexer::GemspecExporter.gemspec -------------------------------------------------------------------------------- /work/reference/legacy.rb: -------------------------------------------------------------------------------- 1 | module AE 2 | 3 | module Legacy #:nodoc: 4 | 5 | # = Test::Unit Legacy Assertions 6 | # 7 | # This module provides a compatibility layer for Test::Unit. 8 | # This is an optional module and is intended for providing 9 | # an easier transition from Test::Unit::TestCase to Quarry 10 | # Specifications. 11 | # 12 | # Note that two methods are not provided, +#assert_nothing_raised+, 13 | # and +#assert_nothing_thrown+. 14 | # 15 | module Assertions 16 | 17 | # Private method upon which all of the legacy assertions are based 18 | # (except for #assert itself). 19 | # 20 | def __assert__(test, msg=nil) 21 | msg = "failed assertion (no message given)" unless msg 22 | raise Assertion.new(msg, caller[1..-1]) unless test 23 | end 24 | 25 | private :__assert__ 26 | 27 | # The assertion upon which all other assertions are based. 28 | # 29 | # assert [1, 2].include?(5) 30 | # 31 | def assert(test=nil, msg=nil) 32 | if test 33 | msg = "failed assertion (no message given)" unless msg 34 | raise Assertion.new(msg, caller) unless test 35 | else 36 | Assertor.new(self, :backtrace=>caller) # TODO: Probably remove this! 37 | end 38 | end 39 | 40 | # Passes if the block yields true. 41 | # 42 | # assert_block "Couldn't do the thing" do 43 | # do_the_thing 44 | # end 45 | # 46 | def assert_block(msg=nil) # :yields: 47 | test = ! yield 48 | msg = "assertion failed" unless msg 49 | __assert__(test, msg) 50 | end 51 | 52 | # Passes if expected == +actual. 53 | # 54 | # Note that the ordering of arguments is important, 55 | # since a helpful error message is generated when this 56 | # one fails that tells you the values of expected and actual. 57 | # 58 | # assert_equal 'MY STRING', 'my string'.upcase 59 | # 60 | def assert_equal(exp, act, msg=nil) 61 | test = (exp == act) 62 | msg = "Expected #{act.inspect} to be equal to #{exp.inspect}" unless msg 63 | __assert__(test, msg) 64 | end 65 | 66 | # Passes if expected_float and actual_float are equal within delta tolerance. 67 | # 68 | # assert_in_delta 0.05, (50000.0 / 10**6), 0.00001 69 | # 70 | def assert_in_delta(exp, act, delta, msg=nil) 71 | test = (exp.to_f - act.to_f).abs <= delta.to_f 72 | msg = "Expected #{exp} to be within #{delta} of #{act}" unless msg 73 | __assert__(test, msg) 74 | end 75 | 76 | # Passes if object .instance_of? klass 77 | # 78 | # assert_instance_of String, 'foo' 79 | # 80 | def assert_instance_of(cls, obj, msg=nil) 81 | test = (cls === obj) 82 | msg = "Expected #{obj} to be a #{cls}" unless msg 83 | __assert__(test, msg) 84 | end 85 | 86 | # Passes if object .kind_of? klass 87 | # 88 | # assert_kind_of Object, 'foo' 89 | # 90 | def assert_kind_of(cls, obj, msg=nil) 91 | test = obj.kind_of?(cls) 92 | msg = "Expected #{obj.inspect} to be a kind of #{cls}" unless msg 93 | __assert__(test, msg) 94 | end 95 | 96 | # Passes if string =~ pattern. 97 | # 98 | # assert_match(/\d+/, 'five, 6, seven') 99 | # 100 | def assert_match(exp, act, msg=nil) 101 | test = (act =~ exp) 102 | msg = "Expected #{act.inspect} to match #{exp.inspect}" unless msg 103 | __assert__(test, msg) 104 | end 105 | 106 | # Passes if object is nil. 107 | # 108 | # assert_nil [1, 2].uniq! 109 | # 110 | def assert_nil(obj, msg=nil) 111 | test = obj.nil? 112 | msg = "Expected #{obj.inspect} to be nil" unless msg 113 | __assert__(test, msg) 114 | end 115 | 116 | # Passes if regexp !~ string 117 | # 118 | # assert_no_match(/two/, 'one 2 three') 119 | # 120 | def assert_no_match(exp, act, msg=nil) 121 | test = (act !~ exp) 122 | msg = "Expected #{act.inspect} to match #{exp.inspect}" unless msg 123 | __assert__(test, msg) 124 | end 125 | 126 | # Passes if expected != actual 127 | # 128 | # assert_not_equal 'some string', 5 129 | # 130 | def assert_not_equal(exp, act, msg=nil) 131 | test = (exp != act) 132 | msg = "Expected #{act.inspect} to not be equal to #{exp.inspect}" unless msg 133 | __assert__(test, msg) 134 | end 135 | 136 | # Passes if ! object .nil? 137 | # 138 | # assert_not_nil '1 two 3'.sub!(/two/, '2') 139 | # 140 | def assert_not_nil(obj, msg=nil) 141 | test = ! obj.nil? 142 | msg = "Expected #{obj.inspect} to not be nil" unless msg 143 | __assert__(test, msg) 144 | end 145 | 146 | # Passes if ! actual .equal? expected 147 | # 148 | # assert_not_same Object.new, Object.new 149 | # 150 | def assert_not_same(exp, act, msg=nil) 151 | test = ! exp.equal?(act) 152 | msg = "Expected #{act.inspect} to not be the same as #{exp.inspect}" unless msg 153 | __assert__(test, msg) 154 | end 155 | 156 | # Compares the +object1+ with +object2+ using operator. 157 | # 158 | # Passes if object1.send(operator, object2) is true. 159 | # 160 | # assert_operator 5, :>=, 4 161 | # 162 | def assert_operator(o1, op, o2, msg="") 163 | test = o1.__send__(op, o2) 164 | msg = "Expected #{o1}.#{op}(#{o2}) to be true" unless msg 165 | __assert__(test, msg) 166 | end 167 | 168 | # Passes if the block raises one of the given exceptions. 169 | # 170 | # assert_raise RuntimeError, LoadError do 171 | # raise 'Boom!!!' 172 | # end 173 | # 174 | def assert_raises(*args) 175 | if msg = (Module === args.last ? nil : args.pop) 176 | begin 177 | yield 178 | msg = "Expected #{exp} to be raised" unless msg 179 | __assert__(false, msg) 180 | rescue Exception => e 181 | test = (exp === e) 182 | msg = "Expected #{exp} to be raised, but got #{e.class}" unless msg 183 | __assert__(test, msg) 184 | return e 185 | end 186 | end 187 | 188 | alias_method :assert_raise, :assert_raises 189 | 190 | # Provides a way to assert that a procedure 191 | # does not raise an exception. 192 | # 193 | # refute_raises(StandardError){ raise } 194 | # 195 | #def assert_raises!(exception, &block) 196 | # begin 197 | # block.call(*a) 198 | # rescue exception 199 | # raise Assertion 200 | # end 201 | #end 202 | #alias_method :refute_raises, :assert_raises! 203 | 204 | # Passes if +object+ respond_to? +method+. 205 | # 206 | # assert_respond_to 'bugbear', :slice 207 | # 208 | def assert_respond_to(obj, meth, msg=nil) 209 | msg = "Expected #{obj} (#{obj.class}) to respond to ##{meth}" unless msg 210 | #flip = (Symbol === obj) && ! (Symbol === meth) # HACK for specs 211 | #obj, meth = meth, obj if flip 212 | test = obj.respond_to?(meth) 213 | __assert__(test, msg) 214 | end 215 | 216 | # Passes if +actual+ .equal? +expected+ (i.e. they are the same instance). 217 | # 218 | # o = Object.new 219 | # assert_same(o, o) 220 | # 221 | def assert_same(exp, act, msg=nil) 222 | msg = "Expected #{act.inspect} to be the same as #{exp.inspect}" unless msg 223 | test = exp.equal?(act) 224 | __assert__(test, msg) 225 | end 226 | 227 | # Passes if the method send returns a true value. 228 | # The parameter +send_array+ is composed of: 229 | # 230 | # * A receiver 231 | # * A method 232 | # * Arguments to the method 233 | # 234 | # Example: 235 | # 236 | # assert_send [[1, 2], :include?, 4] 237 | # 238 | def assert_send(send_array, msg=nil) 239 | r, m, *args = *send_array 240 | test = r.__send__(m, *args) 241 | msg = "Expected #{r}.#{m}(*#{args.inspect}) to return true" unless msg 242 | __assert__(test, msg) 243 | end 244 | 245 | # Passes if the block throws expected_symbol 246 | # 247 | # assert_throws :done do 248 | # throw :done 249 | # end 250 | # 251 | def assert_throws(sym, msg=nil) 252 | msg = "Expected #{sym} to have been thrown" unless msg 253 | test = true 254 | catch(sym) do 255 | begin 256 | yield 257 | rescue ArgumentError => e # 1.9 exception 258 | default += ", not #{e.message.split(/ /).last}" 259 | rescue NameError => e # 1.8 exception 260 | default += ", not #{e.name.inspect}" 261 | end 262 | test = false 263 | end 264 | __assert__(test, msg) 265 | end 266 | 267 | # Flunk always fails. 268 | # 269 | # flunk 'Not done testing yet.' 270 | # 271 | def flunk(msg=nil) 272 | __assert__(false, msg) 273 | end 274 | 275 | end #module Assertions 276 | 277 | end #module Legacy 278 | 279 | # This could be in Object, but since they will only be needed in 280 | # the context of a, well, Context... 281 | # 282 | class Context #:nodoc: 283 | include Legacy::Assertions 284 | end 285 | 286 | end 287 | -------------------------------------------------------------------------------- /lib/assay-testunit/assertions.rb: -------------------------------------------------------------------------------- 1 | module Assay; end 2 | module Assay::TestUnit 3 | 4 | # This module holds the Test::Unit assertion methods for Test::Unit 5 | # compatibility. 6 | # 7 | # While it does not provide 100% of Test::Unit assertions at the moment, 8 | # compatibility will improved with upcoming releases. 9 | # 10 | # @see http://test-unit.rubyforge.org/test-unit/en/ 11 | # 12 | # @todo Should we adjust error message to be like Test::Units ? 13 | # 14 | module Assertions 15 | 16 | # 17 | #def assert_alias_method(object, alias_name, original_name, message = nil) 18 | #end 19 | 20 | # 21 | # Passes if actual is like expected, where `like` means satisfyin any one 22 | # of `#===`, `#==`, `#eql?` or `#equal?` calls. 23 | # 24 | # This is not strictly a Test::Unit assertion but is added here to cover 25 | # all of Assay's availabe assertion classes. 26 | # 27 | def assert_alike(exp, act, msg=nil) 28 | LikeAssay.assert!(act, exp, :message=>msg, :backtrace=>caller) 29 | end 30 | 31 | # 32 | # Passes if actual is NOT like expected, where `like` means satisfyin any 33 | # one of `#===`, `#==`, `#eql?` or `#equal?` calls. 34 | # 35 | def assert_not_alike(exp, act, msg=nil) 36 | LikeAssay.refute!(act, exp, :message=>msg, :backtrace=>caller) 37 | end 38 | 39 | # 40 | # 41 | # 42 | def assert_block(message="assert_block failed.", &block) 43 | ExecutionAssay.assert!(:message=>message, &block) 44 | end 45 | 46 | # 47 | # Passes if `boolean` is either `true` or `false`. 48 | # 49 | def assert_boolean(boolean, message=nil) 50 | BooleanAssay.assert!(boolean, :message=>message) 51 | end 52 | 53 | # 54 | # Passes if `boolean` is not either `true` or `false`. 55 | # 56 | def assert_not_boolean(boolean, message=nil) 57 | BooleanAssay.refute!(boolean, :message=>message) 58 | end 59 | 60 | # Passes if `object` satisify compaision by `operator`. 61 | # 62 | def assert_compare(receiver, operator, operand, message=nil) 63 | case operator.to_sym 64 | when :< 65 | LessAssay.assert!(receiver, operand, :message=>message, :backtrace=>caller) 66 | when :<= 67 | LessEqualAssay.assert!(receiver, operand, :message=>message, :backtrace=>caller) 68 | when :> 69 | MoreAssay.assert!(receiver, operand, :message=>message, :backtrace=>caller) 70 | when :>= 71 | MoreEqualAssay.assert!(receiver, operand, :message=>message, :backtrace=>caller) 72 | when :== 73 | EqualAssay.assert!(operand, receiver, :message=>message, :backtrace=>caller) 74 | else 75 | raise ArgumentError, "comparision operator must be one of <, <=, >, >= or '=='" 76 | end 77 | end 78 | 79 | # 80 | # 81 | # 82 | #def assert_const_defined(object, constant_name, message=nil) 83 | #end 84 | 85 | # 86 | # 87 | # 88 | #def assert_not_const_defined(object, constant_name, message=nil) 89 | #end 90 | 91 | # Passes if object is empty. 92 | # 93 | # assert_empty(object) 94 | # 95 | def assert_empty(exp, msg=nil) 96 | EmptyAssay.assert!(exp, :message=>msg, :backtrace=>caller) 97 | end 98 | 99 | # Passes if object is not empty. 100 | # 101 | # refute_empty(object) 102 | # 103 | def assert_not_empty(exp, msg=nil) 104 | EmptyAssay.refute!(exp, :message=>msg, :backtrace=>caller) 105 | end 106 | 107 | # Passes if expected == +actual. 108 | # 109 | # Note that the ordering of arguments is important, 110 | # since a helpful error message is generated when this 111 | # one fails that tells you the values of expected and actual. 112 | # 113 | # assert_equal 'MY STRING', 'my string'.upcase 114 | # 115 | def assert_equal(exp, act, msg=nil) 116 | EqualAssay.assert!(act, exp, :message=>msg, :backtrace=>caller) 117 | end 118 | 119 | # Passes if expected != actual 120 | # 121 | # assert_not_equal 'some string', 5 122 | # 123 | def assert_not_equal(exp, act, msg=nil) 124 | EqualAssay.refute!(act, exp, :message=>msg, :backtrace=>caller) 125 | end 126 | 127 | # 128 | #def assert_fail_assertion(message = nil) 129 | #end 130 | 131 | # 132 | # Passed if object is +false+. 133 | # 134 | # assert_false(false) 135 | # 136 | def assert_false(exp, msg=nil) 137 | FalseAssay.assert!(exp, :message=>msg, :backtrace=>caller) 138 | end 139 | 140 | # 141 | # Passed if object is not +false+. 142 | # 143 | # assert_not_false(false) 144 | # 145 | def assert_not_false(exp, msg=nil) 146 | FalseAssay.refute!(exp, :message=>msg, :backtrace=>caller) 147 | end 148 | 149 | # 150 | # Passes if expected and actual are equal within `delta` absolte tolerance. 151 | # 152 | # assert_in_delta 0.05, (50000.0 / 10**6), 0.00001 153 | # 154 | def assert_in_delta(exp, act, delta, msg=nil) 155 | WithinAssay.assert!(act, exp, delta, :message=>msg, :backtrace=>caller) 156 | end 157 | 158 | # 159 | # Passes if expected and actual are NOT equal within `delta` absolute tolerance. 160 | # 161 | # assert_not_in_delta 0.05, (50000.0 / 10**6), 0.00001 162 | # 163 | def assert_not_in_delta(exp, act, delta, msg=nil) 164 | WithinAssay.refute!(act, exp, delta, :message=>msg, :backtrace=>caller) 165 | end 166 | 167 | # 168 | # Passes if `exp` and `act` are within `epsilon` relative tolerance. 169 | # 170 | def assert_in_epsilon(exp, act, epsilon=0.001, message=nil) 171 | exp = epsilon if exp.zero? # why does minitest do this? 172 | CloseAssay.assert!(act, exp, delta, :message=>message, :backtrace=>caller) 173 | end 174 | 175 | # 176 | # Passes if `exp` and `act` are NOT within `epsilon` relative tolerance. 177 | # 178 | def assert_not_in_epsilon(exp, act, epsilon=0.001, message=nil) 179 | exp = epsilon if exp.zero? 180 | CloseAssay.refute!(act, exp, delta, :message=>message, :backtrace=>caller) 181 | end 182 | 183 | # 184 | # Passes if `collection` contains `member`. 185 | # 186 | def assert_includes(collection, member, message=nil) 187 | IncludeAssay.assert!(collection, member, :message=>message, :backtrace=>caller) 188 | end 189 | 190 | # 191 | # Passes if `collection` does not contain `member`. 192 | # 193 | def assert_not_includes(collection, member, message=nil) 194 | IncludeAssay.refute!(collection, member, :message=>message, :backtrace=>caller) 195 | end 196 | 197 | # 198 | # Passes if object is an instance of class. 199 | # 200 | # assert_instance_of(String, 'foo') 201 | # 202 | def assert_instance_of(cls, obj, msg=nil) 203 | InstanceAssay.assert!(obj, cls, :message=>msg, :backtrace=>caller) 204 | end 205 | 206 | # 207 | # Passes if object is not an instance of class. 208 | # 209 | # assert_not_instance_of(String, 500) 210 | # 211 | def assert_not_instance_of(cls, obj, msg=nil) 212 | InstanceAssay.refute!(obj, cls, :message=>msg, :backtrace=>caller) 213 | end 214 | 215 | # 216 | # Passes if object .kind_of? klass 217 | # 218 | # assert_kind_of(Object, 'foo') 219 | # 220 | def assert_kind_of(cls, obj, msg=nil) 221 | KindAssay.assert!(obj, cls, :message=>msg, :backtrace=>caller) 222 | end 223 | 224 | # 225 | # Passes if object .kind_of? klass 226 | # 227 | # assert_not_kind_of(Object, 'foo') 228 | # 229 | def assert_not_kind_of(cls, obj, msg=nil) 230 | KindAssay.refute!(obj, cls, :message=>msg, :backtrace=>caller) 231 | end 232 | 233 | # Passes if object matches pattern using `#=~` method. 234 | # 235 | # assert_match(/\d+/, 'five, 6, seven') 236 | # 237 | def assert_match(pattern, string, msg=nil) 238 | MatchAssay.assert!(string, pattern, :message=>msg, :backtrace=>caller) 239 | end 240 | 241 | # Passes if object does not match pattern using `#=~` method. 242 | # 243 | # assert_no_match(/two/, 'one 2 three') 244 | # 245 | def assert_not_match(pattern, string, msg=nil) 246 | MatchAssay.refute!(string, pattern, :message=>msg, :backtrace=>caller) 247 | end 248 | 249 | # Passes if object has no match pattern using `#!~` method. 250 | # 251 | # assert_no_match(/two/, 'one 2 three') 252 | # 253 | def assert_no_match(pattern, string, msg=nil) 254 | NoMatchAssay.assert!(string, pattern, :message=>msg, :backtrace=>caller) 255 | end 256 | 257 | ## Passes if object has a match pattern using `#!~` method. 258 | ## 259 | ## assert_not_no_match(/two/, 'one two three') 260 | ## 261 | #def assert_not_no_match(pattern, string, msg=nil) 262 | # NoMatchAssay.refute!(string, pattern, :message=>msg, :backtrace=>caller) 263 | #end 264 | 265 | # Passed if object is +nil+. 266 | # 267 | # assert_nil(nil) 268 | # 269 | def assert_nil(exp, msg=nil) 270 | NilAssay.assert!(exp, :message=>msg, :backtrace=>caller) 271 | end 272 | 273 | # Passed if object is not +nil+. 274 | # 275 | # assert_not_nil(true) 276 | # 277 | def assert_not_nil(exp, msg=nil) 278 | NilAssay.refute!(exp, :message=>msg, :backtrace=>caller) 279 | end 280 | 281 | # 282 | # 283 | # 284 | def assert_predicate(object, predicate, message = nil) 285 | ExecutionAssay.assert!(:message=>message) do 286 | object.__send__(predicate) 287 | end 288 | end 289 | 290 | # 291 | # 292 | # 293 | def assert_not_predicate(object, predicate, message = nil) 294 | ExecutionAssay.refute!(:message=>message) do 295 | object.__send__(predicate) 296 | end 297 | end 298 | 299 | # 300 | # Passes if +object+ respond_to? +methods+. 301 | # 302 | # assert_respond_to 'bugbear', :slice 303 | # 304 | def assert_respond_to(reciever, method, msg=nil) 305 | RespondAssay.assert!(reciever, method, :message=>msg, :backtrace=>caller) 306 | end 307 | alias_method :assert_responds_to, :assert_respond_to 308 | 309 | # 310 | # Passes if +object+ does not respond_to? +methods+. 311 | # 312 | # assert_not_respond_to 'bugbear', :slice 313 | # 314 | def assert_not_respond_to(reciever, method, msg=nil) 315 | RespondAssay.refute!(reciever, method, :message=>msg, :backtrace=>caller) 316 | end 317 | 318 | # Passes if +expected+ .eql? +actual+. 319 | # 320 | # Note that the ordering of arguments is important, 321 | # since a helpful error message is generated when this 322 | # one fails that tells you the values of expected and actual. 323 | # 324 | # assert_equivalent 'MY STRING', 'my string'.upcase 325 | # 326 | def assert_equivalent(exp, act, msg=nil) 327 | EqualityAssay.assert!(act, exp, :message=>msg, :backtrace=>caller) 328 | end 329 | 330 | # Passes if +criterion+ is NOT equivalent to +actual+ as tested using `#eql?`. 331 | # 332 | # assert_not_equivalent 1, 1.0 333 | # 334 | def assert_not_equivalent(criterion, act, msg=nil) 335 | EqualityAssay.refute!(act, criterion, :message=>msg, :backtrace=>caller) 336 | end 337 | 338 | # 339 | # 340 | # TODO: Is this supposed to be restricted in some way? 341 | def assert_operator(receiver, operator, operand, message=nil) 342 | ExecutionAssay.assert!(:message=>message, :backtrace=>caller) do 343 | receiver.__send__(operator, operand) 344 | end 345 | end 346 | 347 | # 348 | # 349 | # 350 | def assert_path_exist(path, message=nil) 351 | PathAssay.assert!(path, :message=>message, :backtrace=>caller) 352 | end 353 | 354 | # 355 | # 356 | # 357 | def assert_path_not_exist(path, message=nil) 358 | PathAssay.refute!(path, :message=>message, :backtrace=>caller) 359 | end 360 | 361 | # 362 | # Passes if the block raises a given exception. 363 | # 364 | # assert_raise RuntimeError do 365 | # raise 'Boom!!!' 366 | # end 367 | # 368 | def assert_raise(exception, message=nil, &block) 369 | RaiseAssay.assert!(exception, :message=>message, :backtrace=>caller, &block) 370 | end 371 | 372 | alias_method :assert_raises, :assert_raise 373 | 374 | # 375 | # Passes if the block *does not* raise a given exceptions. 376 | # 377 | # assert_not_raised IOError do 378 | # raise 'Boom!!!' 379 | # end 380 | # 381 | def assert_not_raised(exception, message=nil, &block) #:yeild: 382 | RaiseAssay.refute!(exception, :message=>message, :backtrace=>caller, &block) 383 | end 384 | 385 | # 386 | # Passes if the block yields successfully. 387 | # 388 | # assert_nothing_raised "Couldn't do the thing" do 389 | # do_the_thing 390 | # end 391 | # 392 | def assert_nothing_raised(message=nil, &block) 393 | RescueAssay.refute!(Exception, :message=>message, :backtrace=>caller, &block) 394 | end 395 | 396 | # 397 | # Passes if the block raises a given exception. 398 | # 399 | # assert_raise_kind_of RuntimeError do 400 | # raise 'Boom!!!' 401 | # end 402 | # 403 | def assert_raise_kind_of(exception_class, message=nil, &block) 404 | RescueAssay.assert!(exception_class, :message=>message, :backtrace=>caller, &block) 405 | end 406 | 407 | # 408 | #def assert_raise_message(*args, &block) 409 | #end 410 | 411 | # 412 | # Passes if actual is the same exact object as expected. 413 | # 414 | # assert_same(object, object) 415 | # 416 | def assert_same(exp, act, msg=nil) 417 | IdentityAssay.assert!(act, exp, :message=>msg, :backtrace=>caller) 418 | end 419 | 420 | # 421 | # Passes if actual is not the same exact object as expected. 422 | # 423 | # assert_not_same(object, other) 424 | # 425 | def assert_not_same(exp, act, msg=nil) 426 | IdentityAssay.refute!(act, exp, :message=>msg, :backtrace=>caller) 427 | end 428 | 429 | # 430 | # 431 | # 432 | #def assert_send(send_array, message=nil) 433 | #end 434 | 435 | # 436 | # Passes if the block throws `expected` object. 437 | # 438 | # assert_throw :done do 439 | # throw :done 440 | # end 441 | # 442 | def assert_throw(expected, msg=nil, &blk) 443 | ThrowAssay.assert!(expected, :message=>msg, :backtrace=>caller, &blk) 444 | end 445 | 446 | alias_method :assert_throws, :assert_throw 447 | 448 | # 449 | # Passes if the block does not throws `expected` object. 450 | # 451 | # assert_not_thrown :done do 452 | # throw :chimp 453 | # end 454 | # 455 | def assert_not_thrown(expected, msg=nil, &blk) 456 | ThrowAssay.refute!(expected, :message=>msg, :backtrace=>caller, &blk) 457 | end 458 | 459 | # 460 | # 461 | # 462 | def assert_nothing_thrown(message=nil, &blk) 463 | ThrowAssay.refute!(nil, :message=>message, &blk) 464 | end 465 | 466 | # 467 | # Passed if object is +true+. 468 | # 469 | def assert_true(exp, msg=nil) 470 | TrueAssay.assert!(exp, :message=>msg, :backtrace=>caller) 471 | end 472 | 473 | # 474 | # Passed if object is not +true+. 475 | # 476 | # assert_not_true(false) 477 | # 478 | def assert_not_true(exp, msg=nil) 479 | TrueAssay.refute!(exp, :message=>msg, :backtrace=>caller) 480 | end 481 | 482 | end 483 | 484 | end 485 | --------------------------------------------------------------------------------