brass-1.2.1/0000755000000000000000000000000012406704614011327 5ustar rootrootbrass-1.2.1/COPYING.rdoc0000644000000000000000000000300312406704614013304 0ustar rootroot= COPYRIGHT == NOTICES === Brass Copyright:: (c) 2012 RubyWorks License:: (r) BSD-2-Clause Website:: http://rubyworks.github.com/brass == LICENSES === BSD-2-Clause License Brass Copyright (c) 2012 Rubyworks. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. brass-1.2.1/metadata.yml0000644000000000000000000000433212406704614013634 0ustar rootroot--- !ruby/object:Gem::Specification name: brass version: !ruby/object:Gem::Version version: 1.2.1 prerelease: platform: ruby authors: - Thomas Sawyer autorequire: bindir: bin cert_chain: [] date: 2012-02-09 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: detroit requirement: &16492980 !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: *16492980 - !ruby/object:Gem::Dependency name: lemon requirement: &16492280 !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: *16492280 - !ruby/object:Gem::Dependency name: rubytest requirement: &16491100 !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: *16491100 description: ! 'BRASS stands for Bare-Metal Ruby Assertion System Standard. It is a very basic foundational assertions framework for other assertion and test frameworks to make use so they can all work together harmoniously.' email: - transfire@gmail.com executables: [] extensions: [] extra_rdoc_files: - HISTORY.rdoc - COPYING.rdoc - README.md files: - .ruby - .yardopts - lib/brass/adapters/minitest.rb - lib/brass/adapters/testunit.rb - lib/brass/adapters/testunit1.rb - lib/brass/expect.rb - lib/brass.rb - test/case_brass.rb - HISTORY.rdoc - README.md - COPYING.rdoc homepage: http://rubyworks.github.com/brass licenses: - BSD-2-Clause post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 1.8.11 signing_key: specification_version: 3 summary: Bare-Metal Ruby Assertion System Standard test_files: [] brass-1.2.1/HISTORY.rdoc0000644000000000000000000000170212406704614013341 0ustar rootroot= HISTORY == 1.2.1 | 2012-02-09 This release adds framework adapters for MiniTest and TestUnit, which allows those frameworks to recognize BRASS assertions as "failures" rather than as "errors". Changes: * Add framework adapters for MiniTest and TestUnit. == 1.2.0 | 2012-01-26 The default error is `RuntimeError` rather than `StandardError` to match Ruby's default exception when no arguments are passed to `raise`. Changes: * Change default error to RuntimeError. == 1.1.0 | 2012-01-25 Quick fix for issue with parsing arguments of #assert and #refute methods. Also added #fail! method to dry-up code. Changes: * Fix arguments parsing for assert/refute. * Add #fail! method to dry-up code. == 1.0.0 | 2012-01-24 This is the initial release of BRASS. It is given a 1.0.0 version despite being such a new project because it is very simple and the code is derived from other system that have used it for some time. Changes: * Happy Birthday! brass-1.2.1/test/0000755000000000000000000000000012406704614012306 5ustar rootrootbrass-1.2.1/test/case_brass.rb0000644000000000000000000000026212406704614014740 0ustar rootrootcovers 'brass' testcase Kernel do method :assert do test do assert(true) end end method :refute do test do refute(false) end end end brass-1.2.1/.yardopts0000644000000000000000000000011012406704614013165 0ustar rootroot--title "BRASS" --readme README.md --protected --private lib - [A-Z]*.* brass-1.2.1/.ruby0000644000000000000000000000211712406704614012312 0ustar rootroot--- source: - meta authors: - name: Thomas Sawyer email: transfire@gmail.com copyrights: - holder: Rubyworks year: '2012' license: BSD-2-Clause replacements: [] alternatives: [] requirements: - name: detroit groups: - build development: true - name: lemon groups: - test development: true - name: rubytest groups: - test development: true dependencies: [] conflicts: [] repositories: - uri: git@github.com:rubyworks/brass.git scm: git name: upstream resources: home: http://rubyworks.github.com/brass docs: http://rubydoc.info/gems/brass code: http://github.com/rubyworks/brass mail: http://groups.google.com/groups/rubyworks-mailinglist extra: {} load_path: - lib revision: 0 created: '2012-01-24' summary: Bare-Metal Ruby Assertion System Standard title: BRASS version: 1.2.1 name: brass description: ! 'BRASS stands for Bare-Metal Ruby Assertion System Standard. It is a very basic foundational assertions framework for other assertion and test frameworks to make use so they can all work together harmoniously.' organization: Rubyworks date: '2012-02-09' brass-1.2.1/README.md0000644000000000000000000000557512406704614012622 0ustar rootroot# BRASS [Website](http://rubyworks.github.com/brass) / [Report Issue](http://github.com/rubyworks/brass/issues) / [Development](http://github.com/rubyworks/brass) [![Build Status](https://secure.travis-ci.org/rubyworks/brass.png)](http://travis-ci.org/rubyworks/brass) # DESCRIPTION BRASS is a standard assertions framework, framework's framework, or even a framework's framework's framework, depending on where you're staking out your assertions keister. In other words, BRASS provides a standard rudimentary assertions framework that all other assertion and test frameworks can use, or at least comply with, and then everyone gets on swimingly. Now, you may be thinking, "No thanks, I do it my way." But when you see how stupid simple BRASS is, you'll realize that, "Yea, that actually make sense." And then maybe feel a bit stupid yourself for doing exactly what this paragrah just said you would do. Yea, well, we've all been there. But enough with the fluff. BRASS defines two Kernel methods: `assert` and `refute`: assert(truthiness, *fail_arguments) refute(truthiness, *fail_arguments) Where `truthiness` is any object evaluated for it's truth value (`false` and `nil` are `false`, everything else is `true`), and `fail_arguments` are exactly the same as those we would pass to the `fail` or `raise` methods. The `assert` (and likewise `refute`) method does three things. First it tests the `truthiness`, then it ticks up the appropriate counts in the global assertions counter, and lastly, if truthiness came up short, it raises an error. This error is either `RuntimeError` or the one specified by the `fail_arguments`. The global assertions counter is `$ASSERTION_COUNTS`. It is simply a Hash formally defined as: $ASSERTIONS_COUNTS = Hash.new{|h,k| h[k] = 0} And though it is open to any key, the keys should be symbols. Three keys in particular and standard: `:pass`, `:fail` and `:total`. Whenever an assertion passes, the `:pass` and `:total` counts are incremented, and whenever an assertion fails the `:fail` and `:total` counts are incremented. You might wonder why there is a total entry when the sum of the other two would do just as well. Well, other frameworks might want to add other counts, such as `:skip`. So to ensure we still get the proper total despite this, we keep a separate tally. Moving on.... Okay, last thing. When `assert` or `refute` raises an error, it marks the error as an assertion via the `#set_assertion` method. This is a method extension to the Exception class along with the `#assertion?` method which any test framework can use to distinguish an assertion error from an ordinarily error. And that's all there is to it. If you *capice* then consider yourself top brass. Love, Peace and Brass Knuckles ## COPYING Copyright (c) 2010 Rubyworks. All rights reserved. Distribute in accordance with the **BSD-2-Clause** license. See COPYING.md file for details. brass-1.2.1/lib/0000755000000000000000000000000012406704614012075 5ustar rootrootbrass-1.2.1/lib/brass/0000755000000000000000000000000012406704614013207 5ustar rootrootbrass-1.2.1/lib/brass/adapters/0000755000000000000000000000000012406704614015012 5ustar rootrootbrass-1.2.1/lib/brass/adapters/minitest.rb0000644000000000000000000000155012406704614017174 0ustar rootrootmodule 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" end @report << x x[0, 1] end end end brass-1.2.1/lib/brass/adapters/testunit1.rb0000644000000000000000000000230612406704614017300 0ustar rootrootmodule 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 end end end brass-1.2.1/lib/brass/adapters/testunit.rb0000644000000000000000000000217112406704614017217 0ustar rootrootmodule Test #:nodoc: module Unit #:nodoc: module BrassAssertionHandler class << self def included(base) base.exception_handler(:handle_brass_assertion_failed_error) end end private def handle_brass_assertion_failed_error(exception) return false unless exception.assertion? problem_occurred #parameters = exception.parameters # TODO: assertion parameters add_brass_failure exception.message, exception.backtrace, #:expected => exception.expected, #:actual => exception.actual, #:inspected_expected => exception.inspected_expected, #:inspected_actual => exception.inspected_actual, :user_message => exception.message #exception.user_message true end def add_brass_failure(message, backtrace, options={}) failure = Failure.new(name, filter_backtrace(backtrace), message, options) current_result.add_failure(failure) end end class TestCase #:nodoc: include BrassAssertionHandler end end end brass-1.2.1/lib/brass/expect.rb0000644000000000000000000000116712406704614015031 0ustar rootrootmodule Kernel # TODO: Should `#expect` method be part of standard? # Executate a block asserting that a type of error will be raised. # # Presently this is not part of brass by default, as whether it should # be is under debate. So this file must be required separately: # # require 'brass/expect' # def expect(error_class) #:yield: begin yield assert(false, error_class, "#{error_class} expected but none thrown") rescue error_class assert(true) rescue Exception => err assert(false, error_class, "#{error_class} expected but #{err.class} was thrown") end end end brass-1.2.1/lib/brass.rb0000644000000000000000000000505212406704614013536 0ustar rootrootclass Exception # Is the exception an assertion error? def assertion? @assertion end # Set the the exception's assertion flag. def set_assertion(boolean) @assertion = boolean # ? true : false end # Set message. # (not strictly needed here, but can be useful anyway). # # @todo Does the message have to be a string? def set_message(msg) @mesg = msg.to_str end # TODO: Consider assertion parameters for future vresion. ## #def parameters # @parameters #end # ## Set exception parameters. These are used to store specific information ## relavent to a particular exception or assertion. Unlike the message, ## which is a String, this is a Hash. #def set_parameters(parameters) # @parameters = parameters.to_hash #end end module Kernel # Track assertions counts. $ASSERTION_COUNTS ||= Hash.new{ |h,k| h[k] = 0 } # # Universal assertion method. # def assert(truth, *raise_arguments) $ASSERTION_COUNTS[:total] += 1 if truth $ASSERTION_COUNTS[:pass] += 1 else $ASSERTION_COUNTS[:fail] += 1 # if fail set assertion=true then just, # fail *raise_arguments # but alas ... fail! *raise_arguments end end module_function :assert # # Universal refutation method (opposite of `#assert`). # def refute(truth, *raise_arguments) $ASSERTION_COUNTS[:total] += 1 if truth $ASSERTION_COUNTS[:fail] += 1 # if fail set assertion=true then just, # fail *raise_arguments # but alas ... fail! *raise_arguments else $ASSERTION_COUNTS[:pass] += 1 end end module_function :refute # # Alternate for #fail that also sets assertion flag to +true+. # def fail!(*raise_arguments) backtrace = case raise_arguments.last when Array raise_arguments.pop else nil end exception = case raise_arguments.first when Exception raise_arguments.shift when Class raise ArgumentError unless Exception > raise_arguments.first error_class = raise_arguments.shift error_class.new(*raise_arguments) else error_class = $! || RuntimeError error_class.new(*raise_arguments) end exception.set_backtrace(backtrace) if backtrace exception.set_assertion(true) fail exception end module_function :fail! private :assert private :refute private :fail! end