fluidity 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.ruby ADDED
@@ -0,0 +1,51 @@
1
+ ---
2
+ source:
3
+ - meta
4
+ - .ruby
5
+ authors:
6
+ - name: Thomas Sawyer
7
+ email: transfire@gmail.com
8
+ copyrights:
9
+ - holder: Thomas Sawyer
10
+ year: '2012'
11
+ license: BSD-2-Clause
12
+ replacements: []
13
+ alternatives: []
14
+ requirements:
15
+ - name: assay
16
+ - name: detroit
17
+ groups:
18
+ - build
19
+ development: true
20
+ - name: qed
21
+ groups:
22
+ - test
23
+ development: true
24
+ dependencies: []
25
+ conflicts: []
26
+ repositories:
27
+ - uri: git@github.com:rubyworks/fluidity.git
28
+ scm: git
29
+ name: upstream
30
+ resources:
31
+ home: http://rubyworks.github.com/fluidity
32
+ docs: http://rubydoc.info/gems/fluidity
33
+ code: http://github.com/rubyworks/fluidity
34
+ mail: http://groups.google.com/groups/rubyworks-mailinglist
35
+ extra: {}
36
+ load_path:
37
+ - lib
38
+ revision: 0
39
+ created: '2012-01-18'
40
+ summary: Fluid Validity
41
+ title: Fluidity
42
+ version: 0.1.0
43
+ name: fluidity
44
+ description: ! 'Fluidity is an assertions grammer built on top of the Assay assertions
45
+ framework.
46
+
47
+ It defines a set of methods which provide a fluid notation for specifying
48
+
49
+ test assertions.'
50
+ organization: Rubyworks
51
+ date: '2012-01-27'
@@ -0,0 +1,6 @@
1
+ require 'fluidity/about'
2
+ require 'fluidity/grammer'
3
+ require 'fluidity/should'
4
+ require 'fluidity/must'
5
+ require 'fluidity/assert'
6
+
@@ -0,0 +1,51 @@
1
+ ---
2
+ source:
3
+ - meta
4
+ - .ruby
5
+ authors:
6
+ - name: Thomas Sawyer
7
+ email: transfire@gmail.com
8
+ copyrights:
9
+ - holder: Thomas Sawyer
10
+ year: '2012'
11
+ license: BSD-2-Clause
12
+ replacements: []
13
+ alternatives: []
14
+ requirements:
15
+ - name: assay
16
+ - name: detroit
17
+ groups:
18
+ - build
19
+ development: true
20
+ - name: qed
21
+ groups:
22
+ - test
23
+ development: true
24
+ dependencies: []
25
+ conflicts: []
26
+ repositories:
27
+ - uri: git@github.com:rubyworks/fluidity.git
28
+ scm: git
29
+ name: upstream
30
+ resources:
31
+ home: http://rubyworks.github.com/fluidity
32
+ docs: http://rubydoc.info/gems/fluidity
33
+ code: http://github.com/rubyworks/fluidity
34
+ mail: http://groups.google.com/groups/rubyworks-mailinglist
35
+ extra: {}
36
+ load_path:
37
+ - lib
38
+ revision: 0
39
+ created: '2012-01-18'
40
+ summary: Fluid Validity
41
+ title: Fluidity
42
+ version: 0.1.0
43
+ name: fluidity
44
+ description: ! 'Fluidity is an assertions grammer built on top of the Assay assertions
45
+ framework.
46
+
47
+ It defines a set of methods which provide a fluid notation for specifying
48
+
49
+ test assertions.'
50
+ organization: Rubyworks
51
+ date: '2012-01-27'
@@ -0,0 +1,17 @@
1
+ module Fluidity
2
+
3
+ # Access to metadata.
4
+ def self.metadata
5
+ @metadata ||= (
6
+ require 'yaml'
7
+ YAML.load(File.new(File.dirname(__FILE__) + '/../fluidity.yml'))
8
+ )
9
+ end
10
+
11
+ # Access to project metadata as constants.
12
+ def self.const_missing(name)
13
+ key = name.to_s.downcase
14
+ metadata[key] || super(name)
15
+ end
16
+
17
+ end
@@ -0,0 +1,24 @@
1
+ require 'fluidity/grammer'
2
+
3
+ class Object
4
+
5
+ # Use `assert` nomenclature for assertions.
6
+ #
7
+ # 10.assert.kind_of?(Integer)
8
+ #
9
+ def assert(matcher=nil, *args)
10
+ if matcher
11
+ return super(matcher, *args) unless matcher.respond_to?(:===) # not good enough!!!
12
+ matcher =~ self
13
+ else
14
+ ::Fluidity::Grammer::Assert.new(self)
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+
21
+ module Kernel
22
+ public :assert
23
+ public :refute
24
+ end
@@ -0,0 +1,121 @@
1
+ require 'assay'
2
+
3
+ module Fluidity
4
+
5
+ module Grammer
6
+
7
+ class Base
8
+
9
+ def initialize(target, negate=false)
10
+ @target = target
11
+ @negate = negate
12
+ end
13
+
14
+ # Have to override the ususal `#==` method to support this.
15
+ def ==(other)
16
+ if @negate
17
+ ::EqualAssay.refute!(@target, other, :backtrace=>caller)
18
+ else
19
+ ::EqualAssay.assert!(@target, other, :backtrace=>caller)
20
+ end
21
+ end
22
+
23
+ #private
24
+
25
+ def method_missing(s, *a, &b)
26
+ if assay = (::Assertion.by_name(s) || ::Assertion.by_operator(s))
27
+ if @negate
28
+ assay.refute!(@target, *a, &b)
29
+ else
30
+ assay.assert!(@target, *a, &b)
31
+ end
32
+ else
33
+ q = (s.to_s.end_with?('?') ? s : (s.to_s+'?'))
34
+ if @target.respond_to?(q)
35
+ assert(false, "#{q} failed", caller) unless @target.send(q, *a, &b)
36
+ else
37
+ super(s, *a, &b)
38
+ end
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+ #
45
+ class Assert < Base
46
+
47
+ #def method_missing(s, *a, &b)
48
+ # call(s, *a, &b)
49
+ #end
50
+
51
+ def not
52
+ Assert.new(@target, !@negate)
53
+ end
54
+
55
+ end
56
+
57
+ #
58
+ class Be < Base
59
+
60
+ #def method_missing(s, *a, &b)
61
+ # call(s, *a, &b)
62
+ #end
63
+
64
+ #
65
+ def a
66
+ self
67
+ end
68
+
69
+ #
70
+ def an
71
+ self
72
+ end
73
+
74
+ end
75
+
76
+ #
77
+ class Is < Be
78
+
79
+ def not
80
+ Is.new(@target, !@negate)
81
+ end
82
+
83
+ end
84
+
85
+ #
86
+ class Must < Base
87
+
88
+ #def method_missing(s, *a, &b)
89
+ # call(s, *a, &b)
90
+ #end
91
+
92
+ def be
93
+ Be.new(@target, @negate)
94
+ end
95
+
96
+ def not
97
+ Must.new(@target, !@negate)
98
+ end
99
+
100
+ end
101
+
102
+ #
103
+ class Should < Base
104
+
105
+ #def method_missing(s, *a, &b)
106
+ # call(s, *a, &b)
107
+ #end
108
+
109
+ def be
110
+ Be.new(@target, @negate)
111
+ end
112
+
113
+ def not
114
+ Should.new(@target, !@negate)
115
+ end
116
+
117
+ end
118
+
119
+ end
120
+
121
+ end
@@ -0,0 +1,18 @@
1
+ require 'fluidity/grammer'
2
+
3
+ class Object #BasicObject
4
+
5
+ # Use `is` nomenclature for assertions.
6
+ #
7
+ # 10.is.kind_of?(Integer)
8
+ #
9
+ def is(matcher=nil)
10
+ if matcher
11
+ matcher === self
12
+ else
13
+ ::Fluidity::Grammer::Is.new(self)
14
+ end
15
+ end
16
+
17
+ end
18
+
@@ -0,0 +1,32 @@
1
+ require 'fluidity/grammer'
2
+
3
+ # TODO: What about BasicObject ?
4
+
5
+ class Object #BasicObject
6
+
7
+ # Use `must` nomenclature for assertions.
8
+ #
9
+ # 10.must.be.kind_of(Integer)
10
+ #
11
+ def must(matcher=nil)
12
+ if matcher
13
+ matcher =~ self
14
+ else
15
+ ::Fluidity::Grammer::Must.new(self)
16
+ end
17
+ end
18
+
19
+ # Also, `must_not` nomenclature for assertions.
20
+ #
21
+ # 10.must_not.be.kind_of?(Integer)
22
+ #
23
+ def must_not(matcher=nil)
24
+ if matcher
25
+ matcher !~ self
26
+ else
27
+ ::Fluidity::Grammer::Must.new(self, true)
28
+ end
29
+ end
30
+
31
+ end
32
+
@@ -0,0 +1,30 @@
1
+ require 'fluidity/grammer'
2
+
3
+ class Object #BasicObject
4
+
5
+ # Use `should` nomenclature for assertions.
6
+ #
7
+ # 10.should.be.kind_of(Integer)
8
+ #
9
+ def should(matcher=nil)
10
+ if matcher
11
+ matcher =~ self
12
+ else
13
+ ::Fluidity::Grammer::Should.new(self)
14
+ end
15
+ end
16
+
17
+ # Also, `should_not` nomenclature for assertions.
18
+ #
19
+ # 10.should_not.be.kind_of?(Integer)
20
+ #
21
+ def should_not(matcher=nil)
22
+ if matcher
23
+ matcher !~ self
24
+ else
25
+ ::Fluidity::Grammer::Should.new(self, true)
26
+ end
27
+ end
28
+
29
+ end
30
+
@@ -0,0 +1,52 @@
1
+ == Should
2
+
3
+ require 'fluidity/should'
4
+
5
+ Now we have a fluent notation with which to make assertions.
6
+
7
+ true.should.be.true
8
+ false.should.be.false
9
+
10
+ (5 + 5).should.equal 10
11
+
12
+ [1,2,3].should.include(2)
13
+
14
+ We can also use the associated operator (Ruby's built-in query method name).
15
+
16
+ false.should.be.false?
17
+ true.should.be.true?
18
+
19
+ (5 + 5).should == 10
20
+
21
+ Indefinite article `a` and `an` are suppored.
22
+
23
+ 12.should.be.a.kind_of?(Integer)
24
+
25
+ As is `not` for negation.
26
+
27
+ 12.should.not.equal(20)
28
+
29
+ We should also make sure such assertions can fail.
30
+
31
+ IncludeAssay.should.be.raised do
32
+ [1,2,3].should.include(4)
33
+ end
34
+
35
+ FalseAssay.should.be.raised do
36
+ true.should.be.false
37
+ end
38
+
39
+ EqualAssay.should.be.raised do
40
+ (5 + 5).should == 11
41
+ end
42
+
43
+ Matcher notation is also supported, if you have any matcher classes
44
+ to use. Assay classes can be converted to matchers, so we can use
45
+ one of those to try this out.
46
+
47
+ be_sixteen = EqualAssay[16.0]
48
+
49
+ 16.should be_sixteen
50
+
51
+ 15.should_not be_sixteen
52
+
@@ -0,0 +1,58 @@
1
+ == Must
2
+
3
+ require 'fluidity/must'
4
+
5
+ Now we have a fluent notation with which to make assertions.
6
+
7
+ true.must.be.true
8
+ false.must.be.false
9
+
10
+ (5 + 5).must.equal 10
11
+
12
+ [1,2,3].must.include(2)
13
+
14
+ We can also use the associated operator (Ruby's built-in query method name).
15
+
16
+ false.must.be.false?
17
+ true.must.be.true?
18
+
19
+ (5 + 5).must == 10
20
+
21
+ Indefinite article `a` and `an` are suppored.
22
+
23
+ 12.must.be.a.kind_of?(Integer)
24
+
25
+ 12.must.be.an.instance_of?(Fixnum)
26
+
27
+ As is `not` for negation.
28
+
29
+ 12.must.not.equal(20)
30
+
31
+ Or `must_not` can also be used.
32
+
33
+ 12.must_not.equal(20)
34
+
35
+ We must also make sure such assertions can fail.
36
+
37
+ IncludeAssay.must.be.raised do
38
+ [1,2,3].must.include(4)
39
+ end
40
+
41
+ FalseAssay.must.be.raised do
42
+ true.must.be.false
43
+ end
44
+
45
+ EqualAssay.must.be.raised do
46
+ (5 + 5).must == 11
47
+ end
48
+
49
+ Matcher notation is also supported, if you have any matcher classes
50
+ to use. Assay classes can be converted to matchers, so we can use
51
+ one of those to try this out.
52
+
53
+ be_sixteen = EqualAssay[16.0]
54
+
55
+ 16.must be_sixteen
56
+
57
+ 15.must_not be_sixteen
58
+
@@ -0,0 +1,56 @@
1
+ = Grammer
2
+
3
+ require 'fluidity/assert'
4
+
5
+ Now we have a fluent notation with which to make assertions.
6
+
7
+ true.assert.true
8
+ false.assert.false
9
+
10
+ (5 + 5).must.equal 10
11
+
12
+ [1,2,3].must.include(2)
13
+
14
+ We can also use the associated operator (Ruby's built-in query method name).
15
+
16
+ false.assert.false?
17
+ true.assert.true?
18
+
19
+ (5 + 5).assert == 10
20
+
21
+ (9 + 9).assert.not == 10
22
+
23
+ 12.assert.kind_of?(Integer)
24
+
25
+ As is `not` for negation.
26
+
27
+ 12.assert.not.equal(20)
28
+
29
+ Or `should_not` can also be used.
30
+
31
+ 12.should_not.equal(20)
32
+
33
+ We must also make sure such assertions can fail. Since #assert is special
34
+ method to assay classes, we can use it as on these as part of our test
35
+ grmmer. So we use the raw `#assert!` method to handle the test.
36
+
37
+ RaiseAssay.assert!(IncludeAssay) do
38
+ [1,2,3].assert.include(4)
39
+ end
40
+
41
+ RaiseAssay.assert!(FalseAssay) do
42
+ true.assert.false
43
+ end
44
+
45
+ RaiseAssay.assert!(EqualityAssay) do
46
+ (5 + 5).assert == 11
47
+ end
48
+
49
+ Matcher notation is also supported, if you have any matcher classes
50
+ to use. Assay classes can be converted to matchers, so we can use
51
+ one of those to try this out.
52
+
53
+ is_sixteen = EqualityAssay[16.0]
54
+
55
+ 16.assert is_sixteen
56
+
@@ -0,0 +1,24 @@
1
+ == Other Stuff
2
+
3
+ What if there is an assertion made for which no Assay class exists?
4
+ If the target object has a query method defined by the same name,
5
+ that is, one ending in a `?` mark, then that mehtod will be used
6
+ to test the assertion.
7
+
8
+ c = Class.new do
9
+ def initialize(truth)
10
+ @truth = truth
11
+ end
12
+ def yes?
13
+ @truth
14
+ end
15
+ def no?
16
+ !@truth
17
+ end
18
+ end
19
+
20
+ x = c.new(true)
21
+
22
+ x.should.be.yes
23
+
24
+ x.should_not.be.no
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluidity
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Thomas Sawyer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: assay
16
+ requirement: &21870300 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *21870300
25
+ - !ruby/object:Gem::Dependency
26
+ name: detroit
27
+ requirement: &21869760 !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: *21869760
36
+ - !ruby/object:Gem::Dependency
37
+ name: qed
38
+ requirement: &21869260 !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: *21869260
47
+ description: ! 'Fluidity is an assertions grammer built on top of the Assay assertions
48
+ framework.
49
+
50
+ It defines a set of methods which provide a fluid notation for specifying
51
+
52
+ test assertions.'
53
+ email:
54
+ - transfire@gmail.com
55
+ executables: []
56
+ extensions: []
57
+ extra_rdoc_files: []
58
+ files:
59
+ - .ruby
60
+ - lib/fluidity/about.rb
61
+ - lib/fluidity/assert.rb
62
+ - lib/fluidity/grammer.rb
63
+ - lib/fluidity/is.rb
64
+ - lib/fluidity/must.rb
65
+ - lib/fluidity/should.rb
66
+ - lib/fluidity.rb
67
+ - lib/fluidity.yml
68
+ - spec/01_should.rdoc
69
+ - spec/02_must.rdoc
70
+ - spec/03_assert.rdoc
71
+ - spec/04_other.rdoc
72
+ homepage: http://rubyworks.github.com/fluidity
73
+ licenses:
74
+ - BSD-2-Clause
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 1.8.10
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Fluid Validity
97
+ test_files: []