bang 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.index ADDED
@@ -0,0 +1,57 @@
1
+ ---
2
+ type: ruby
3
+ revision: 2013
4
+ sources:
5
+ - var
6
+ - VERSION
7
+ authors:
8
+ - name: Trans
9
+ email: transfire@gmail.com
10
+ organizations:
11
+ - name: Rubyworks
12
+ requirements:
13
+ - name: brass
14
+ - groups:
15
+ - build
16
+ development: true
17
+ name: detroit
18
+ - groups:
19
+ - test
20
+ development: true
21
+ name: qed
22
+ conflicts: []
23
+ alternatives: []
24
+ resources:
25
+ - type: home
26
+ uri: http://rubyworks.github.com/bang
27
+ label: Homepage
28
+ - type: code
29
+ uri: http://github.com/rubyworks/bang
30
+ label: Source Code
31
+ - type: bugs
32
+ uri: http://github.com/rubyworks/bang/issues
33
+ label: Issue Tracker
34
+ - type: mail
35
+ uri: http://groups.google.com/groups/rubyworks-mailinglist
36
+ label: Mailing List
37
+ repositories:
38
+ - name: upstream
39
+ scm: git
40
+ uri: git@github.com:rubyworks/bang.git
41
+ categories: []
42
+ paths:
43
+ load:
44
+ - lib
45
+ copyrights:
46
+ - holder: Rubyworks
47
+ year: '2012'
48
+ license: BSD-2-Clause
49
+ created: '2012-01-26'
50
+ summary: Bang methods for assertions!
51
+ title: Bang! Bang!
52
+ name: bang
53
+ description: ! 'Bang! Bang! provides a dynamic assertions framework utlizing bang
54
+
55
+ methods and built to BRASS standards.'
56
+ version: 0.2.0
57
+ date: '2012-12-21'
@@ -0,0 +1,7 @@
1
+ --title "Bang! Bang!"
2
+ --readme README.md
3
+ --protected
4
+ --private
5
+ lib
6
+ -
7
+ [A-Z]*.*
data/HISTORY.md CHANGED
@@ -1,6 +1,18 @@
1
- # HISTORY
1
+ # RELEASE HISTORY
2
2
 
3
- ## 0.1.0 | 2012-02-09
3
+ ## 0.2.0 / 2012-12-21
4
+
5
+ This release modifies Bang! Bang! to rely on BRASS #assert and #refute
6
+ methods directly. This simplifies the code a bit and takes care of
7
+ tracking assertion counts automatically.
8
+
9
+ Changes:
10
+
11
+ * Use Brass #assert and #refute methods.
12
+ * Access project metadata dynamically via const_missing.
13
+
14
+
15
+ ## 0.1.0 / 2012-02-09
4
16
 
5
17
  This is the initial release of Bang.
6
18
 
@@ -0,0 +1,22 @@
1
+ BSD-2-Clause License
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice,
7
+ this list of conditions and the following disclaimer.
8
+
9
+ 2. Redistributions in binary form must reproduce the above copyright
10
+ notice, this list of conditions and the following disclaimer in the
11
+ documentation and/or other materials provided with the distribution.
12
+
13
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
14
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
15
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
16
+ COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
17
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
20
+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
22
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md CHANGED
@@ -2,34 +2,33 @@
2
2
 
3
3
  [Website](http://rubyworks.github.com/bang) /
4
4
  [Report Issue](http://github.com/rubyworks/bang/issues) /
5
- [Mailing List](http://groups.google.com/groups/rubyworks-mailinglist) /
6
- [Source Code](http://github.com/rubyworks/bang) /
7
- IRC #rubyworks
5
+ [Source Code](http://github.com/rubyworks/bang)
6
+ ( [![Build Status](https://secure.travis-ci.org/rubyworks/bang.png)](http://travis-ci.org/rubyworks/bang) )
8
7
 
9
- [![Build Status](https://secure.travis-ci.org/rubyworks/bang.png)](http://travis-ci.org/rubyworks/bang)
8
+ <br/>
10
9
 
10
+ Bang! Bang! is a [BRASS](http://rubyworks.github.com/brass) compliant assertions
11
+ framework with a very clever design that translates any bang call, e.g. `#foo!`
12
+ into an assertion based on the corresponding query call if it exists, e.g. `#foo?`.
13
+ In practice the framework is similar to MiniTest's spec methods,
14
+ e.g. `#must_equal`, but the dynamic nature of Bang! Bang! makes it much more
15
+ flexible, as it is not limited to a finite set of assertion methods.
11
16
 
12
- ## Description
17
+ It's also pretty interesting idea that bang methods would be assertion methods.
18
+ In general practice bang methods are usually used for methods that change the
19
+ state of an object *in-place*. But this isn't particularly necessary and
20
+ is just as well handled by non-bang methods, e.g. `#update` vs `#merge!`.
13
21
 
14
- Bang! Bang! is an assertions framework with a very clever design that translates
15
- any bang call, e.g. `#foo!` into an assertion based on the corresponding query
16
- call, `#foo?` (if it exists). In practice the framework is similar to MiniTest's
17
- spec expectation methods, e.g. `#must_equal`, but the dynamic nature of Bang!
18
- Bang! makes it much more flexible, as it is not limited to a finite set of
19
- assertion methods.
20
22
 
21
- It's also pretty interesting idea that bang methods are asseriton methods.
22
- In usual Ruby code, bang methods ususually aren't particularly necessary and
23
- could just as well be handled by non-bang methods, e.g. `#update` vs `#merge!`.
24
-
25
-
26
- ## Instruction
23
+ ## Instructions
27
24
 
28
25
  Usage is pretty straight forward.
29
26
 
27
+ ```ruby
30
28
  require 'bang'
31
29
 
32
30
  "This string".equals!("That string") #=> raises Bang::Assertion
31
+ ```
33
32
 
34
33
  To use Bang! Bang! most effectively with common test frameworks, you may need
35
34
  to load an adapter to ensure the framework recognizes the assertions as
@@ -37,27 +36,50 @@ such rather than as ordinary errors.
37
36
 
38
37
  For MiniTest use:
39
38
 
39
+ ```ruby
40
40
  require 'bang/minitest'`
41
+ ```
41
42
 
42
43
  For TestUnit use:
43
44
 
45
+ ```ruby
44
46
  require 'bang/testunit'
47
+ ```
45
48
 
46
49
  An RSpec adapter is in the works.
47
50
 
48
- Cucumber does not require an adapter as it does not differntiate errors
51
+ Cucumber does not require an adapter as it does not differentiate errors
49
52
  from assertions.
50
53
 
51
54
  Note, these adapters simply require the `brass/adapters/minitest` and
52
- `brass/adapters/testunit` respecitvely along with `bang`. So that's another
55
+ `brass/adapters/testunit` respectively along with `bang`. So that's another
53
56
  way to do it too.
54
57
 
55
58
 
59
+ ## On Robustness
60
+
61
+ Bang! Bang! works via a set of core extensions. There may be some concern
62
+ about this approach for a test framework. I can assure you that the fear
63
+ of the inaptly named "monkey patch" is very much overwrought.
64
+
65
+ Even though Bang! Bang! adds a `#method_missing` call to the Object class, it is
66
+ almost always okay to use because it does not get called if an object already has
67
+ a bang method defined for it's own use. And when it does get called it only applies
68
+ if a corresponding query (e.g. `foo?`) method exists.
69
+
70
+ The other core extensions it adds are simply convenience methods that make testing
71
+ easier. Because these are only additions and not overrides, it is perfectly safe to
72
+ use in all but the most esoteric cases (such a heavy meta-programming). In fact, if
73
+ a program doesn't work because of these core extensions, that's usually a good
74
+ indication that something isn't being done right in the program itself.
75
+
76
+
56
77
  ## Copyrights
57
78
 
58
- Bang Bang is Copyright (c) 2012 Rubyworks
79
+ Bang Bang is copyrighted open source software.
59
80
 
60
- You can redistribute it in accordance to the *BSD-2-Clause* license.
81
+ Copyright (c) 2012 Rubyworks
61
82
 
62
- Please see the included COPYING.md file for license details.
83
+ You can redistribute it in accordance to the [BSD-2-Clause](http://spdx.org/licenses/BSD-2-Clause) license.
63
84
 
85
+ See the included LICENSE.txt file for details.
@@ -0,0 +1,180 @@
1
+ # Bangers
2
+
3
+ require 'bang'
4
+
5
+ ## true!
6
+
7
+ true.true!
8
+
9
+ expect Bang::Assertion do
10
+ false.true!
11
+ end
12
+
13
+ false.not_true!
14
+
15
+ ## false!
16
+
17
+ false.false!
18
+
19
+ expect Bang::Assertion do
20
+ true.false!
21
+ end
22
+
23
+ true.not_false!
24
+
25
+ ## nil!
26
+
27
+ nil.nil!
28
+
29
+ expect Bang::Assertion do
30
+ true.nil!
31
+ end
32
+
33
+ true.not_nil!
34
+
35
+ ## equal!
36
+
37
+ 1.equal!(1)
38
+
39
+ expect Bang::Assertion do
40
+ 1.equal!(2)
41
+ end
42
+
43
+ 1.not_equal!(2)
44
+
45
+ ## eql!
46
+
47
+ 1.eql!(1)
48
+
49
+ expect Bang::Assertion do
50
+ 1.eql!(1.0)
51
+ end
52
+
53
+ 1.not_eql!(1.0)
54
+
55
+ ## identical!
56
+
57
+ Ruby's built-in query method for this is `#equal?`, but obviously that conflicts
58
+ with our use of `#equal!` to test quality using `###`. So instead we use `#identical!`
59
+ which makes more sense really.
60
+
61
+ :a.identical!(:a)
62
+
63
+ expect Bang::Assertion do
64
+ "a".identical!("a")
65
+ end
66
+
67
+ :a.not_identical!('a')
68
+
69
+ ## instance_of!
70
+
71
+ 1.instance_of!(Fixnum)
72
+
73
+ expect Bang::Assertion do
74
+ 1.instance_of!(String)
75
+ end
76
+
77
+ 1.not_instance_of!(String)
78
+
79
+ ## kind_of!
80
+
81
+ 1.kind_of!(Integer)
82
+
83
+ expect Bang::Assertion do
84
+ 1.kind_of!(String)
85
+ end
86
+
87
+ 1.not_kind_of!(String)
88
+
89
+ ## within!
90
+
91
+ 1.within!(2, 1.5)
92
+
93
+ expect Bang::Assertion do
94
+ 1.within!(2, 0.5)
95
+ end
96
+
97
+ 1.not_within!(2, 0.5)
98
+
99
+ ## close!
100
+
101
+ 1.close!(2, 1.5)
102
+
103
+ expect Bang::Assertion do
104
+ 1.close!(1.2, 0.5)
105
+ end
106
+
107
+ 1.not_close!(5, 0.5)
108
+
109
+ ## match!
110
+
111
+ "abc".match!(/a/)
112
+
113
+ expect Bang::Assertion do
114
+ "abc".match!(/x/)
115
+ end
116
+
117
+ "abc".not_match!(/g/)
118
+
119
+ ## respond_to!
120
+
121
+ "string".respond_to!(:upcase)
122
+
123
+ expect Bang::Assertion do
124
+ "string".respond_to!(:not_a_method)
125
+ end
126
+
127
+ "string".not_respond_to!(:not_a_method)
128
+
129
+ ## satisfy!
130
+
131
+ 5.satisfy!{ |x| x > 3 }
132
+
133
+ expect Bang::Assertion do
134
+ 5.satisfy!{ |x| x < 3 }
135
+ end
136
+
137
+ 5.not_satisfy!{ |x| x < 3 }
138
+
139
+ ## raises!
140
+
141
+ ::ArgumentError.raised!{ raise ::ArgumentError }
142
+
143
+ An extension to Proc class can also be used.
144
+
145
+ procedure = lambda{ raise ::ArgumentError }
146
+
147
+ procedure.raises!(::ArgumentError)
148
+
149
+ expect Bang::Assertion do
150
+ procedure.raises!(::TypeError)
151
+ end
152
+
153
+ ## rescues!
154
+
155
+ ::TypeError.rescued!{ raise ::TypeError }
156
+
157
+ An extension to Proc class can also be used.
158
+
159
+ procedure = lambda{ raise ::TypeError }
160
+
161
+ procedure.rescues!(::StandardError)
162
+
163
+ expect Bang::Assertion do
164
+ procedure.rescues!(::IOError)
165
+ end
166
+
167
+ ## throws!
168
+
169
+ :foo.thrown!{ throw :foo }
170
+
171
+ An extension to Proc class can also be used.
172
+
173
+ procedure = lambda{ throw :foo }
174
+
175
+ procedure.throws!(:foo)
176
+
177
+ expect Bang::Assertion do
178
+ procedure.throws!(:bar)
179
+ end
180
+
File without changes
@@ -1,18 +1,33 @@
1
1
  module Bang
2
2
 
3
- if RUBY_VERSION < '1.9'
4
- require 'bang/version'
5
- else
6
- require_relative 'bang/version'
3
+ # Bang has brass balls.
4
+ require 'brass'
5
+
6
+ #
7
+ # If constant is missing check for value in project metadata.
8
+ # e.g. `Bang::VERSION`.
9
+ #
10
+ def self.const_missing(const_name)
11
+ index[const_name.to_s.downcase] || super(const_name)
12
+ end
13
+
14
+ #
15
+ # Access project metadata.
16
+ #
17
+ def self.index
18
+ @index ||= (
19
+ require 'yaml'
20
+ YAML.load_file(File.dirname(__FILE__) + '/bang.yml')
21
+ )
7
22
  end
8
23
 
9
- # Bang's assertion class. Follows standard set by Brass project,
24
+ # Bang's assertion class. Follows standard set by BRASS project,
10
25
  # defining `#assertion?` method which return `true`.
11
26
  #
12
27
  class Assertion < ::Exception
13
28
 
14
29
  #
15
- # Price together an Assetion error give the message used to
30
+ # Piece together an Assetion error give the message used to
16
31
  # cause the assertion failure.
17
32
  #
18
33
  # @return [Assertion] Assertion instance.
@@ -72,8 +87,10 @@ module Bang
72
87
 
73
88
  result = meth.call(*a, &b)
74
89
 
75
- if !(neg ^ result)
76
- raise Bang::Assertion.piece(s, a, b, caller)
90
+ if neg
91
+ refute(result, Bang::Assertion.piece(s, a, b, caller))
92
+ else
93
+ assert(result, Bang::Assertion.piece(s, a, b, caller))
77
94
  end
78
95
  end
79
96
 
@@ -100,7 +117,7 @@ module Bang
100
117
  #
101
118
  # @return [true,false] Whether `self` is equal to `other`.
102
119
  #
103
- def equal_to?
120
+ def equal_to?(other)
104
121
  other == self
105
122
  end
106
123
 
@@ -0,0 +1,57 @@
1
+ ---
2
+ type: ruby
3
+ revision: 2013
4
+ sources:
5
+ - var
6
+ - VERSION
7
+ authors:
8
+ - name: Trans
9
+ email: transfire@gmail.com
10
+ organizations:
11
+ - name: Rubyworks
12
+ requirements:
13
+ - name: brass
14
+ - groups:
15
+ - build
16
+ development: true
17
+ name: detroit
18
+ - groups:
19
+ - test
20
+ development: true
21
+ name: qed
22
+ conflicts: []
23
+ alternatives: []
24
+ resources:
25
+ - type: home
26
+ uri: http://rubyworks.github.com/bang
27
+ label: Homepage
28
+ - type: code
29
+ uri: http://github.com/rubyworks/bang
30
+ label: Source Code
31
+ - type: bugs
32
+ uri: http://github.com/rubyworks/bang/issues
33
+ label: Issue Tracker
34
+ - type: mail
35
+ uri: http://groups.google.com/groups/rubyworks-mailinglist
36
+ label: Mailing List
37
+ repositories:
38
+ - name: upstream
39
+ scm: git
40
+ uri: git@github.com:rubyworks/bang.git
41
+ categories: []
42
+ paths:
43
+ load:
44
+ - lib
45
+ copyrights:
46
+ - holder: Rubyworks
47
+ year: '2012'
48
+ license: BSD-2-Clause
49
+ created: '2012-01-26'
50
+ summary: Bang methods for assertions!
51
+ title: Bang! Bang!
52
+ name: bang
53
+ description: ! 'Bang! Bang! provides a dynamic assertions framework utlizing bang
54
+
55
+ methods and built to BRASS standards.'
56
+ version: 0.2.0
57
+ date: '2012-12-21'
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - Thomas Sawyer
8
+ - Trans
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-09 00:00:00.000000000 Z
12
+ date: 2012-12-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: brass
16
- requirement: &23786500 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *23786500
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: detroit
27
- requirement: &23785960 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *23785960
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: qed
38
- requirement: &23785460 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,25 +53,35 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *23785460
47
- description: Bang! Bang! provides a dynamic assertions framework utlizing bang methods
48
- and built to BRASS standards.
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: ! 'Bang! Bang! provides a dynamic assertions framework utlizing bang
63
+
64
+ methods and built to BRASS standards.'
49
65
  email:
50
66
  - transfire@gmail.com
51
67
  executables: []
52
68
  extensions: []
53
69
  extra_rdoc_files:
54
- - COPYING.md
70
+ - LICENSE.txt
55
71
  - HISTORY.md
56
72
  - README.md
57
73
  files:
74
+ - .index
75
+ - .yardopts
76
+ - demo/01_bang.md
77
+ - demo/applique/brass.rb
58
78
  - lib/bang/minitest.rb
59
79
  - lib/bang/testunit.rb
60
80
  - lib/bang.rb
61
- - spec/applique/brass.rb
62
- - COPYING.md
81
+ - lib/bang.yml
63
82
  - HISTORY.md
64
83
  - README.md
84
+ - LICENSE.txt
65
85
  homepage: http://rubyworks.github.com/bang
66
86
  licenses:
67
87
  - BSD-2-Clause
@@ -83,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
103
  version: '0'
84
104
  requirements: []
85
105
  rubyforge_project:
86
- rubygems_version: 1.8.11
106
+ rubygems_version: 1.8.23
87
107
  signing_key:
88
108
  specification_version: 3
89
109
  summary: Bang methods for assertions!
data/COPYING.md DELETED
@@ -1,36 +0,0 @@
1
- # COPYRIGHT
2
-
3
- ## NOTICES
4
-
5
- ### Assay
6
-
7
- | Project | Bang |
8
- |-----------|-----------------------------------|
9
- | Copyright | (c) 2012 Rubyworks |
10
- | License | (r) BSD-2-Clause |
11
- | Website | http://rubyworks.github.com/bang |
12
-
13
- ## LICENSES
14
-
15
- ### BSD-2-Clause License
16
-
17
- Redistribution and use in source and binary forms, with or without
18
- modification, are permitted provided that the following conditions are met:
19
-
20
- 1. Redistributions of source code must retain the above copyright notice,
21
- this list of conditions and the following disclaimer.
22
-
23
- 2. Redistributions in binary form must reproduce the above copyright
24
- notice, this list of conditions and the following disclaimer in the
25
- documentation and/or other materials provided with the distribution.
26
-
27
- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
28
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
29
- FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30
- COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32
- NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
34
- OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
36
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.