graham 0.0.0 → 0.0.2

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/README.md CHANGED
@@ -5,32 +5,32 @@ Graham is a tiny-yet-useful testing library based on Mallow - in fact it _is_ Ma
5
5
  * TestRocket was too minimal
6
6
  * RSpec was too verbose (not to mention ridiculous overkill)
7
7
 
8
- ## How i graham ##
8
+ ## How does one graham ##
9
9
 
10
- Graham test cases are instance methods on classes defined in Graham's namespace:
10
+ Graham test cases are instance methods on arbitrary classes:
11
11
  ```ruby
12
- class Graham::TestCases
12
+ class TestCases
13
13
  def initialize
14
14
  @number = 1
15
15
  end
16
- def Case1
16
+ def one_squared
17
17
  @number ** 2
18
18
  end
19
- def Case2
19
+ def dividing_one_by_zero
20
20
  @number / 0
21
21
  end
22
- def Case3
22
+ def calling_a_nonexistent_method
23
23
  Graham.this_is_not_a_method
24
24
  end
25
25
  end
26
26
  ```
27
27
  Then test your cases:
28
28
  ```ruby
29
- Graham.test(:TestCases) do |that|
30
- that.Case1.is_such_that { self == 1 }
31
- that.Case2.is_a(Fixnum).such_that {self > 1}
32
- that.Case3.does_not_raise_an_exception
33
- end #=> {:Case1=>true, :Case2=>#<ZeroDivisionError>, :Case3=>false}
29
+ Graham.test(TestCases) do |that|
30
+ that.one_squared.is 1
31
+ that.dividing_by_zero.returns_a(Fixnum).such_that {self > 1}
32
+ that.calling_a_nonexistent_method.does_not_raise_an_exception
33
+ end #=> {:one_squared=>true, :dividing_by_zero=>#<ZeroDivisionError>, :calling_a_nonexistent_method=>false}
34
34
  ```
35
- Calling Graham#pp instead will call Graham#test and run the output through Graham's built-in pretty printer.
35
+ Calling Graham::pp instead will call Graham::test and run the output through Graham's built-in pretty printer.
36
36
 
data/graham.gemspec CHANGED
@@ -3,7 +3,7 @@ require 'rake'
3
3
  require 'graham/version'
4
4
 
5
5
  graham = Gem::Specification.new do |spec|
6
- spec.add_dependency 'mallow'
6
+ spec.add_dependency 'mallow', '>=0.0.4'
7
7
  spec.name = 'graham'
8
8
  spec.version = Graham::VERSION
9
9
  spec.author = 'feivel jellyfish'
data/lib/graham.rb CHANGED
@@ -19,9 +19,6 @@ require 'graham/version'
19
19
  # that.test3.returns_a Numeric
20
20
  # } #=> {:test1=>true, :test2=>false, :test3=>#<ZeroDivisionError>}
21
21
  #
22
- # A side effect of this approach is that you can use RDoc to document your
23
- # tests, gauge coverage, etc.
24
- #
25
22
  # === N.B.
26
23
  # Since a Graham test is basically a Mallow pattern matcher, only the first
27
24
  # test on a case will actually be executed, as subsequent invocations of the
@@ -47,40 +44,24 @@ require 'graham/version'
47
44
  module Graham
48
45
  autoload :PP, 'graham/pp'
49
46
  autoload :RakeTask, 'graham/rake_task'
50
- # Namespace for test cases; see documentation for Graham
51
- class Cases; end
47
+ autoload :DSL, 'graham/dsl'
52
48
  class << self
53
49
  # A convenience method that builds and executes a Graham::Core
54
50
  # in the given namespace (defaults to Cases). See documentation for
55
51
  # Graham for more on usage.
56
- def test(ns=self::Cases, &b)
57
- ns=const_get(ns) if ns.is_a? Symbol
58
- Graham::Core.build(ns, &b).test
52
+ def test(ns, &b)
53
+ DSL.build_core(ns, &b).test
59
54
  end
60
- # A convenience methods that calls ::test and passes the output to a
55
+ # A convenience method that calls ::test and passes the output to a
61
56
  # pretty printer.
62
- def pp(ns=self::Cases, &b)
57
+ def pp(ns, &b)
63
58
  PP.new(test ns,&b).pp
64
59
  end
65
-
66
- def compose(ns=nil, *test_groups)
67
-
68
- end
69
-
70
- alias test_in test
71
-
72
- private
73
- def ns_compose(test_groups)
74
- test_groups.map do |ns, tests|
75
- [ ns, tests.map {|test| test ns, &test} ]
76
- end
77
- end
78
-
79
60
  end
80
61
 
81
62
  class Core < Mallow::Core
82
63
  attr_accessor :cases
83
- def initialize(*args)
64
+ def initialize
84
65
  @cases = []
85
66
  super
86
67
  end
@@ -89,7 +70,7 @@ module Graham
89
70
  [e.name] << begin
90
71
  super e
91
72
  true
92
- rescue Mallow::DeserializationException
73
+ rescue Mallow::MatchException
93
74
  false
94
75
  rescue => err
95
76
  err
@@ -97,82 +78,6 @@ module Graham
97
78
  end
98
79
 
99
80
  def test; Hash[_fluff @cases] end
100
- def self.build(ns, &b); DSL.build ns, &b end
101
- end
102
-
103
- class DSL < Mallow::DSL
104
-
105
- def self.build(ns)
106
- yield(dsl = new(ns))
107
- dsl.finish!
108
- end
109
-
110
- def initialize(ns)
111
- @core, @cases = Core.new, ns.new
112
- reset!
113
- end
114
-
115
- def method_missing(msg, *args, &b)
116
- case msg.to_s
117
- when /^((and|that)_)+(.+)$/
118
- respond_to?($3)? send($3, *args, &b) : super
119
- else
120
- core.cases << (_case = @cases.method msg) rescue super
121
- rule!._this _case
122
- end
123
- end
124
-
125
- def _where(&b); push b, :conditions end
126
- def _this(o); _where {|e|e==o} end
127
- def where(&b); _where {|e| preproc(b)[e.call] } end
128
-
129
- def raises(x=nil)
130
- _where {
131
- begin
132
- call
133
- false
134
- rescue x => e
135
- true
136
- rescue => e
137
- x ? raise(e) : true
138
- end
139
- }
140
- end
141
-
142
- def does_not_raise(x=nil)
143
- _where {
144
- begin
145
- call
146
- true
147
- rescue x => e
148
- false
149
- rescue => e
150
- x ? raise(e) : false
151
- end
152
- }
153
- end
154
-
155
- alias is this
156
- alias returns this
157
-
158
- alias is_such_that where
159
- alias such_that where
160
- alias and where
161
- alias that where
162
-
163
- alias raises_an raises
164
- alias raises_a raises
165
- alias raises_an_exception raises
166
-
167
- alias returns_ does_not_raise
168
- alias does_not_raise_a does_not_raise
169
- alias does_not_raise_an does_not_raise
170
- alias does_not_raise_an_exception does_not_raise
171
-
172
- alias is_a a
173
- alias is_an a
174
- alias returns_a a
175
- alias returns_an a
176
-
177
81
  end
178
82
  end
83
+
data/lib/graham/dsl.rb ADDED
@@ -0,0 +1,77 @@
1
+ module Graham
2
+ class DSL < Mallow::BasicDSL
3
+ include Mallow::DSL::Matchers
4
+ def self.build_core(ns)
5
+ yield(dsl = new(ns))
6
+ dsl.finish!
7
+ end
8
+
9
+ def initialize(ns)
10
+ @core, @ns = Core.new, ns.new
11
+ reset!
12
+ end
13
+
14
+ def method_missing(msg, *args, &b)
15
+ case msg.to_s
16
+ when /^((and|that)_)+(.+)$/
17
+ respond_to?($3)? send($3, *args, &b) : super
18
+ else
19
+ core.cases << (_case = @ns.method msg)
20
+ rule!._where {|e|e==_case}
21
+ end
22
+ end
23
+
24
+ def _where(&b); push b, :conditions end
25
+ def where(&b); _where {|e| preproc(b)[e.call] } end
26
+
27
+ def raises(x=nil)
28
+ _where {
29
+ begin
30
+ call
31
+ false
32
+ rescue x => e
33
+ true
34
+ rescue => e
35
+ x ? raise(e) : true
36
+ end
37
+ }
38
+ end
39
+
40
+ def does_not_raise(x=nil)
41
+ _where {
42
+ begin
43
+ call
44
+ true
45
+ rescue x => e
46
+ false
47
+ rescue => e
48
+ x ? raise(e) : false
49
+ end
50
+ }
51
+ end
52
+
53
+ alias is this
54
+ alias returns this
55
+
56
+ alias is_such_that where
57
+ alias such_that where
58
+ alias that where
59
+ alias and where
60
+
61
+ alias raises_an raises
62
+ alias raises_a raises
63
+ alias raises_an_exception raises
64
+
65
+ alias returns_ does_not_raise
66
+ alias does_not_raise_a does_not_raise
67
+ alias does_not_raise_an does_not_raise
68
+ alias does_not_raise_an_exception does_not_raise
69
+
70
+ alias is_a a
71
+ alias is_an a
72
+ alias returns_a a
73
+ alias returns_an a
74
+
75
+ end
76
+ end
77
+
data/lib/graham/pp.rb CHANGED
@@ -1,6 +1,6 @@
1
- # A trivial pretty printer for test output.
2
- # TODO: replace with something better
3
1
  module Graham
2
+ # A trivial pretty printer for test output.
3
+ # TODO: replace with something better
4
4
  class PP
5
5
  attr_reader :results
6
6
  attr_accessor :bt, :out, :color
@@ -1,3 +1,3 @@
1
1
  module Graham
2
- VERSION = '0.0.0'
2
+ VERSION = '0.0.2'
3
3
  end
data/test/case/control.rb CHANGED
@@ -1,10 +1,10 @@
1
- class Graham::Cases
2
- def NinetyNine; 99 end
3
- def NameError; raise Asdf.qwer.ty / 0 end
1
+ class Cases
2
+ def the_number_99; 99 end
3
+ def raising_a_name_error; raise Asdf.qwer.ty / 0 end
4
4
  end
5
5
 
6
- Graham.pp {|that|
7
- that.NinetyNine.returns_a(Fixnum).such_that {self==99}.and_that_is 99
8
- that.NameError.raises.and_raises_a NameError
6
+ Graham.pp(Cases) {|that|
7
+ that.the_number_99.returns_a(Fixnum).such_that {self==99}.and_that_is 99
8
+ that.raising_a_name_error.raises.and_raises_a NameError
9
9
  }
10
10
 
data/test/case/test.rb CHANGED
@@ -1,12 +1,12 @@
1
- class Graham::Cases
1
+ class Cases
2
2
  def DocTest1; 4 + 5 end
3
3
  def DocTest2; 'test'.upcase end
4
4
  def DocTest3; 1/0 end
5
- def RDocExample
6
- Graham.test { |that|
5
+ def rdoc_example
6
+ Graham.test(Cases) { |that|
7
7
  that.DocTest1.returns_a(Fixnum).such_that {self < 100}
8
8
  that.DocTest2.returns 'TeST'
9
- that.DocTest3.returns_a Numeric
9
+ that.DocTest3.returns_a(Numeric)
10
10
  }
11
11
  end
12
12
 
@@ -22,8 +22,8 @@ class Graham::Cases
22
22
  def ReadmeCase3
23
23
  Graham.this_is_not_a_method
24
24
  end
25
- def ReadmeExample
26
- Graham.test do |that|
25
+ def readme_example
26
+ Graham.test(Cases) do |that|
27
27
  that.ReadmeCase1.is_such_that { self == 1 }
28
28
  that.ReadmeCase2.is_a(Fixnum).such_that {self > 1}
29
29
  that.ReadmeCase3.does_not_raise_an_exception
@@ -31,27 +31,27 @@ class Graham::Cases
31
31
  end
32
32
  end
33
33
 
34
- class Graham::Namespace
35
- def Namespacing; self end
34
+ class Namespace
35
+ def namespacing; self end
36
36
  end
37
37
 
38
- Graham.pp do |that|
39
- that.RDocExample.returns_a(Hash).of_size(3).such_that {
38
+ Graham.pp(Cases) do |that|
39
+ that.rdoc_example.returns_a(Hash).of_size(3).such_that {
40
40
  self[:DocTest1] == true and
41
41
  self[:DocTest2] == false and
42
42
  self[:DocTest3].is_a? ZeroDivisionError
43
43
  }
44
- that.ReadmeExample.returns_a(Hash).of_size(3).such_that {
44
+ that.readme_example.returns_a(Hash).of_size(3).such_that {
45
45
  self[:ReadmeCase1] == true and
46
46
  self[:ReadmeCase2].is_a? ZeroDivisionError and
47
47
  self[:ReadmeCase3] == false
48
48
  }
49
49
  end
50
50
 
51
- Graham.pp(:Namespace) do |that|
52
- that.Namespacing.is_such_that {
53
- self.class == Graham::Namespace
54
- }.and {!respond_to? :DocExample
55
- }.and { respond_to? :Namespacing}
51
+ Graham.pp(Namespace) do |that|
52
+ that.namespacing.is_such_that {
53
+ self.class == Namespace
54
+ }.and {!respond_to? :rdoc_example
55
+ }.and { respond_to? :namespacing}
56
56
  end
57
57
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graham
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-25 00:00:00.000000000 Z
12
+ date: 2012-11-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mallow
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 0.0.4
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: 0.0.4
30
30
  description: Miniature test engine based on Mallow
31
31
  email: feivel@sdf.org
32
32
  executables: []
@@ -39,6 +39,7 @@ files:
39
39
  - lib/graham/rake_task.rb
40
40
  - lib/graham/pp.rb
41
41
  - lib/graham/version.rb
42
+ - lib/graham/dsl.rb
42
43
  - Rakefile
43
44
  - test/case/control.rb
44
45
  - test/case/test.rb