brass 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.ruby +53 -0
- data/COPYING.rdoc +38 -0
- data/HISTORY.rdoc +12 -0
- data/README.md +71 -0
- data/lib/brass.rb +78 -0
- data/lib/brass/expect.rb +24 -0
- data/test/case_brass.rb +22 -0
- metadata +94 -0
data/.ruby
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
---
|
2
|
+
source:
|
3
|
+
- meta
|
4
|
+
authors:
|
5
|
+
- name: Thomas Sawyer
|
6
|
+
email: transfire@gmail.com
|
7
|
+
copyrights:
|
8
|
+
- holder: Rubyworks
|
9
|
+
year: '2012'
|
10
|
+
license: BSD-2-Clause
|
11
|
+
replacements: []
|
12
|
+
alternatives: []
|
13
|
+
requirements:
|
14
|
+
- name: detroit
|
15
|
+
groups:
|
16
|
+
- build
|
17
|
+
development: true
|
18
|
+
- name: lemon
|
19
|
+
groups:
|
20
|
+
- test
|
21
|
+
development: true
|
22
|
+
- name: rubytest
|
23
|
+
groups:
|
24
|
+
- test
|
25
|
+
development: true
|
26
|
+
dependencies: []
|
27
|
+
conflicts: []
|
28
|
+
repositories:
|
29
|
+
- uri: git@github.com:rubyworks/brass.git
|
30
|
+
scm: git
|
31
|
+
name: upstream
|
32
|
+
resources:
|
33
|
+
home: http://rubyworks.github.com/brass
|
34
|
+
docs: http://rubydoc.info/gems/brass
|
35
|
+
code: http://github.com/rubyworks/brass
|
36
|
+
mail: http://groups.google.com/groups/rubyworks-mailinglist
|
37
|
+
extra: {}
|
38
|
+
load_path:
|
39
|
+
- lib
|
40
|
+
revision: 0
|
41
|
+
created: '2012-01-24'
|
42
|
+
summary: Bare-Metal Ruby Assertion System Standard
|
43
|
+
title: BRASS
|
44
|
+
version: 1.0.0
|
45
|
+
name: brass
|
46
|
+
description: ! 'BRASS stands for Bare-Metal Ruby Assertion System Standard. It is
|
47
|
+
a very basic
|
48
|
+
|
49
|
+
foundational assertions framework for other assertion and test frameworks
|
50
|
+
|
51
|
+
to make use so they can all work together harmoniously.'
|
52
|
+
organization: Rubyworks
|
53
|
+
date: '2012-01-24'
|
data/COPYING.rdoc
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
= COPYRIGHT
|
2
|
+
|
3
|
+
== NOTICES
|
4
|
+
|
5
|
+
=== Brass
|
6
|
+
|
7
|
+
Copyright:: (c) 2012 RubyWorks
|
8
|
+
License:: (r) BSD-2-Clause
|
9
|
+
Website:: http://rubyworks.github.com/brass
|
10
|
+
|
11
|
+
== LICENSES
|
12
|
+
|
13
|
+
=== BSD-2-Clause License
|
14
|
+
|
15
|
+
Brass
|
16
|
+
|
17
|
+
Copyright (c) 2012 Rubyworks. All rights reserved.
|
18
|
+
|
19
|
+
Redistribution and use in source and binary forms, with or without
|
20
|
+
modification, are permitted provided that the following conditions are met:
|
21
|
+
|
22
|
+
1. Redistributions of source code must retain the above copyright notice,
|
23
|
+
this list of conditions and the following disclaimer.
|
24
|
+
|
25
|
+
2. Redistributions in binary form must reproduce the above copyright
|
26
|
+
notice, this list of conditions and the following disclaimer in the
|
27
|
+
documentation and/or other materials provided with the distribution.
|
28
|
+
|
29
|
+
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
30
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
31
|
+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
32
|
+
COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
33
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
34
|
+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
35
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
36
|
+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
37
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
38
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/HISTORY.rdoc
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
= HISTORY
|
2
|
+
|
3
|
+
== 1.0.0 | 2012-01-24
|
4
|
+
|
5
|
+
This is the initial release of BRASS. It is given a 1.0.0 version
|
6
|
+
despite being such a new project because it is very simple and
|
7
|
+
the code is derived from other system that have used it for some time.
|
8
|
+
|
9
|
+
Changes:
|
10
|
+
|
11
|
+
* Happy Birthday!
|
12
|
+
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# BRASS
|
2
|
+
|
3
|
+
[Website](http://rubyworks.github.com/brass) /
|
4
|
+
[Report Issue](http://github.com/rubyworks/brass/issues) /
|
5
|
+
[Development](http://github.com/rubyworks/brass)
|
6
|
+
|
7
|
+
[](http://travis-ci.org/rubyworks/brass)
|
8
|
+
|
9
|
+
|
10
|
+
# DESCRIPTION
|
11
|
+
|
12
|
+
BRASS is a standard assertions framework, framework's framework, or even
|
13
|
+
a framework's framework's framework, depending on where you're staking
|
14
|
+
out your assertions keister.
|
15
|
+
|
16
|
+
In other words, BRASS provides a standard rudimentary assertions framework
|
17
|
+
that all other assertion and/or test framework can use, or at least comply
|
18
|
+
with, and then everyone gets on swell.
|
19
|
+
|
20
|
+
Now, you may be thinking, "No thanks, I do it my way." But when you see
|
21
|
+
how stupid simple BRASS is, you'll realize that, "Yea, that actually
|
22
|
+
make sense." And feel a bit like a ass yourself for jumping to
|
23
|
+
quick judgment.
|
24
|
+
|
25
|
+
Now, enough fluffery.
|
26
|
+
|
27
|
+
BRASS defines two Kernel methods: `assert` and `refute`
|
28
|
+
|
29
|
+
assert(truthiness, *fail_arguments)
|
30
|
+
refute(truthiness, *fail_arguments)
|
31
|
+
|
32
|
+
Where `truthiness` is any object evaluated for it's truth value (`false` and `nil`
|
33
|
+
are `false`, everything else is `true`), and `fail_arguments` are exactly the same
|
34
|
+
as those we would pass to the `fail` or `raise` methods.
|
35
|
+
|
36
|
+
The `assert` and `refute` methods do three things. First they test the `truthiness`,
|
37
|
+
then they tick up the counts in the global assertions counter, and if truthiness fails,
|
38
|
+
they raise an error. This error is either `StandardError` or the one specified
|
39
|
+
by the `fail_arguments`.
|
40
|
+
|
41
|
+
The global assertions counter is `$ASSERTION_COUNTS`. If is simply a Hash formally
|
42
|
+
defined as:
|
43
|
+
|
44
|
+
$ASSERTIONS_COUNTS = Hash.new{|h,k| h[k] = 0}
|
45
|
+
|
46
|
+
And though it is open to any key, they should be symbols and three in particular
|
47
|
+
and standard `:pass`, `:fail` and `:total`. Whenever an assertion passes,
|
48
|
+
the `:total` and `:pass` counts are incremented, and whenever an assertion
|
49
|
+
fails the `:total` and `:fail` counts are incremented. You might wonder why
|
50
|
+
there is a total entry when the sum of the other two would do just as well.
|
51
|
+
Well, other frameworks might want to add some other counts, e.g. a `:skip`
|
52
|
+
count, and to ensure we still get the proper total despite this, we keep
|
53
|
+
a separate tally. Moving on....
|
54
|
+
|
55
|
+
Okay, last thing. When `assert` or `refute` raises an error, it marks the error
|
56
|
+
as an assertion via the `Exception#set_assertion` method. This is a method extension
|
57
|
+
to the Exception class along with the `Exception#assertion?` method which any
|
58
|
+
test framework can use to distinguish an assertion error from an ordinarily error.
|
59
|
+
|
60
|
+
That's all, bro. Consider your brass ass informed.
|
61
|
+
|
62
|
+
|
63
|
+
## COPYING
|
64
|
+
|
65
|
+
Copyright (c) 2010 Rubyworks
|
66
|
+
|
67
|
+
All rights reserved.
|
68
|
+
|
69
|
+
Distribute in accordance with the **BSD-2-Clause** license.
|
70
|
+
|
71
|
+
See COPYING.md file for details.
|
data/lib/brass.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
class Exception
|
2
|
+
|
3
|
+
# Is the exception an assertion error?
|
4
|
+
def assertion?
|
5
|
+
@assertion
|
6
|
+
end
|
7
|
+
|
8
|
+
# Set the the exception's assertion flag.
|
9
|
+
def set_assertion(boolean)
|
10
|
+
@assertion = boolean # ? true : false
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
module Kernel
|
16
|
+
|
17
|
+
# Track assertions counts.
|
18
|
+
$ASSERTION_COUNTS ||= Hash.new{ |h,k| h[k] = 0 }
|
19
|
+
|
20
|
+
#
|
21
|
+
# Universal assertion method.
|
22
|
+
#
|
23
|
+
def assert(truth, *raise_arguments)
|
24
|
+
$ASSERTION_COUNTS[:total] += 1
|
25
|
+
if truth
|
26
|
+
$ASSERTION_COUNTS[:pass] += 1
|
27
|
+
else
|
28
|
+
$ASSERTION_COUNTS[:fail] += 1
|
29
|
+
# if fail set assertion=true then just,
|
30
|
+
# fail *raise_arguments
|
31
|
+
# but alas ...
|
32
|
+
if Exception === raise_arguments.first
|
33
|
+
error = raise_arguments.shift
|
34
|
+
else
|
35
|
+
if Exception > raise_arguments.first
|
36
|
+
error_class = raise_arguments.shift
|
37
|
+
else
|
38
|
+
error_class = StandardError
|
39
|
+
end
|
40
|
+
error = error_class.new(*raise_arguments)
|
41
|
+
end
|
42
|
+
error.set_assertion(true)
|
43
|
+
raise error
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
module_function :assert
|
48
|
+
|
49
|
+
#
|
50
|
+
# Universal refutation method (opposite of `#assert`).
|
51
|
+
#
|
52
|
+
def refute(truth, *raise_arguments)
|
53
|
+
$ASSERTION_COUNTS[:total] += 1
|
54
|
+
if truth
|
55
|
+
$ASSERTION_COUNTS[:fail] += 1
|
56
|
+
# if fail set assertion=true then just,
|
57
|
+
# fail *raise_arguments
|
58
|
+
# but alas ...
|
59
|
+
if Exception === raise_arguments.first
|
60
|
+
error = raise_arguments.shift
|
61
|
+
else
|
62
|
+
if Exception > raise_arguments.first
|
63
|
+
error_class = raise_arguments.shift
|
64
|
+
else
|
65
|
+
error_class = StandardError
|
66
|
+
end
|
67
|
+
error = error_class.new(*raise_arguments)
|
68
|
+
end
|
69
|
+
error.set_assertion(true)
|
70
|
+
raise error
|
71
|
+
else
|
72
|
+
$ASSERTION_COUNTS[:pass] += 1
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
module_function :refute
|
77
|
+
|
78
|
+
end
|
data/lib/brass/expect.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Kernel
|
2
|
+
|
3
|
+
# TODO: Should `#expect` method be part of standard?
|
4
|
+
|
5
|
+
# Executate a block asserting that a type of error will be raised.
|
6
|
+
#
|
7
|
+
# Presently this is not part of brass by default, as whether it should
|
8
|
+
# be is under debate. So this file must be required separately:
|
9
|
+
#
|
10
|
+
# require 'brass/expect'
|
11
|
+
#
|
12
|
+
def expect(error_class) #:yield:
|
13
|
+
begin
|
14
|
+
yield
|
15
|
+
assert(false, error_class, "#{error_class} expected but none thrown")
|
16
|
+
rescue error_class
|
17
|
+
assert(true)
|
18
|
+
rescue Exception => err
|
19
|
+
assert(false, error_class, "#{error_class} expected but #{err} was thrown")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
data/test/case_brass.rb
ADDED
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: brass
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thomas Sawyer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: detroit
|
16
|
+
requirement: &26437340 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *26437340
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: lemon
|
27
|
+
requirement: &26436120 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *26436120
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rubytest
|
38
|
+
requirement: &26460580 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *26460580
|
47
|
+
description: ! 'BRASS stands for Bare-Metal Ruby Assertion System Standard. It is
|
48
|
+
a very basic
|
49
|
+
|
50
|
+
foundational assertions framework for other assertion and test frameworks
|
51
|
+
|
52
|
+
to make use so they can all work together harmoniously.'
|
53
|
+
email:
|
54
|
+
- transfire@gmail.com
|
55
|
+
executables: []
|
56
|
+
extensions: []
|
57
|
+
extra_rdoc_files:
|
58
|
+
- HISTORY.rdoc
|
59
|
+
- COPYING.rdoc
|
60
|
+
- README.md
|
61
|
+
files:
|
62
|
+
- .ruby
|
63
|
+
- lib/brass/expect.rb
|
64
|
+
- lib/brass.rb
|
65
|
+
- test/case_brass.rb
|
66
|
+
- HISTORY.rdoc
|
67
|
+
- README.md
|
68
|
+
- COPYING.rdoc
|
69
|
+
homepage: http://rubyworks.github.com/brass
|
70
|
+
licenses:
|
71
|
+
- BSD-2-Clause
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 1.8.10
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: Bare-Metal Ruby Assertion System Standard
|
94
|
+
test_files: []
|