jay_unit 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ *~
6
+ #*
7
+ *#
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in jay_unit.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/jay_unit.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "jay_unit/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "jay_unit"
7
+ s.version = JayUnit::VERSION
8
+ s.authors = ["Jason Knight"]
9
+ s.email = ["jason@jason-knight-martin.com"]
10
+ s.homepage = "http://jolierouge.net"
11
+ s.summary = %q{Dead simple unit testing framework}
12
+ s.description = %q{Seriously simple testing.}
13
+
14
+ s.rubyforge_project = "jay_unit"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
@@ -0,0 +1,3 @@
1
+ module JayUnit
2
+ VERSION = "0.0.1"
3
+ end
data/lib/jay_unit.rb ADDED
@@ -0,0 +1,166 @@
1
+ require "jay_unit/version"
2
+
3
+ module JayUnit
4
+ def self.succeed(str)
5
+ $ses += 1
6
+ s = %Q[SUCCESS: #{str}]
7
+ puts s
8
+ end
9
+ def self.phail(str)
10
+ $fls += 1
11
+ s = %Q[PHAILURE: #{str}]
12
+ raise s
13
+ exit
14
+ end
15
+ def self.note(str)
16
+ puts "......#{str}"
17
+ end
18
+ def self.mock
19
+ return JayUnit::Mock.new
20
+ end
21
+ def self._run_test(name)
22
+ cls = Kernel.const_get(name)
23
+ if cls then
24
+ inst = cls.new
25
+ end
26
+ end
27
+ def self.run(test_name=nil)
28
+ Dir.glob("#{::Rails.root.to_s}/test/unit/*_unit.rb").each do |f|
29
+ require f
30
+ name = f.split('/').last
31
+ name.gsub!(/^(\w)/) {$1.upcase}
32
+ name.gsub!(/_(\w)/) {$1.upcase}
33
+ name.gsub!(/\.rb/,'')
34
+ if test_name.nil? then
35
+ puts "JayUnit: Running #{name}."
36
+ JayUnit._run_test name
37
+ puts "JayUnit: #{name} complete."
38
+ elsif test_name == name then
39
+ puts "JayUnit: Running #{name}."
40
+ JayUnit._run_test name
41
+ puts "JayUnit: #{name} complete."
42
+ end
43
+ end
44
+ end
45
+ # This is the class you inherit from. And define a method called test
46
+ # can also override setup so that you can have some instance vars around
47
+ class Test
48
+ def initialize
49
+ $ses = 0
50
+ $fls = 0
51
+ _setup
52
+ setup
53
+ _start
54
+ run
55
+ end
56
+ def setup
57
+ # You must override this method
58
+ end
59
+ def run
60
+ raise "You must override the run function in your class!"
61
+ end
62
+ #proxy methods
63
+ def note arg
64
+ JayUnit.note arg
65
+ end
66
+ def succeed arg
67
+ JayUnit.succeed arg
68
+ end
69
+ def phail arg
70
+ JayUnit.phail arg
71
+ end
72
+ def section name,&block
73
+ puts "------* [#{name}] *------"
74
+ yield
75
+ report
76
+ end
77
+ def report
78
+ s = %Q[
79
+ --------------- RESULTS ------------------
80
+ SUCCESSES: #{$ses} PHAILURES:#{$fls}
81
+ ------------------------------------------
82
+ ]
83
+ puts s
84
+ end # end report
85
+ protected
86
+ # If you place a file called setup.rb in test/ this will pick it up
87
+ def _setup
88
+ if File.exists? "#{::Rails.root.to_s}/test/setup.rb" then
89
+ File.open "#{::Rails.root.to_s}/test/setup.rb" do |f|
90
+ eval f.read
91
+ end
92
+ end
93
+ end
94
+ def _start
95
+ Object.class_eval do
96
+ # We define some very simple methods on all types that
97
+ # descend from Object, i.e. everything :)
98
+ # the basic idea is, you simply make an assertion of is or is_not,
99
+ # success and failure is based on this
100
+ def is?(val,label='')
101
+ if self == val then
102
+ JayUnit.succeed "#{label}[#{self.class}] is #{val}"
103
+ else
104
+ JayUnit.phail "#{label}[#{self.class}] is not #{val}"
105
+ end
106
+ end
107
+ def is_not?(val,label='')
108
+ if not self == val then
109
+ JayUnit.succeed "#{label}[#{self.class}] is not #{val}"
110
+ else
111
+ JayUnit.phail "#{label}[#{self.class}] is #{val}"
112
+ end
113
+ end
114
+ def lt? arg,label
115
+ if not self < arg then
116
+ JayUnit.succeed "#{label}[#{self.class}] is not #{arg}"
117
+ else
118
+ JayUnit.phail "#{label}[#{self.class}] is #{arg}"
119
+ end
120
+ end
121
+ def gt? arg,label
122
+ if not self > arg then
123
+ JayUnit.succeed "#{label}[#{self.class}] is not #{arg}"
124
+ else
125
+ JayUnit.phail "#{label}[#{self.class}] is #{arg}"
126
+ end
127
+ end
128
+ def not_lt? arg,label
129
+ if not self < arg then
130
+ JayUnit.succeed "#{label}[#{self.class}] is not #{arg}"
131
+ else
132
+ JayUnit.phail "#{label}[#{self.class}] is #{arg}"
133
+ end
134
+ end
135
+ def not_gt? arg,label
136
+ if not self > arg then
137
+ JayUnit.succeed "#{label}[#{self.class}] is not #{arg}"
138
+ else
139
+ JayUnit.phail "#{label}[#{self.class}] is #{arg}"
140
+ end
141
+ end
142
+ end #end object.class_eval
143
+ end #end start
144
+ end
145
+ class Mock
146
+ @_msgs
147
+ def self.method_missing(sym,*args,&block)
148
+ @_msgs << ['Singleton',sym,args,block]
149
+ end
150
+ def method_missing(sym,*args,&block)
151
+ @_msgs << ['Instance',sym,args,block]
152
+ end
153
+ def received? sym
154
+ @_msgs.each do |m|
155
+ return true if m[1] == sym
156
+ end
157
+ return false
158
+ end
159
+ def arg? value
160
+ @_msgs.each do |m|
161
+ return true if m[2].class == Array and m[2].include?(value)
162
+ end
163
+ return false
164
+ end
165
+ end
166
+ end
@@ -0,0 +1,6 @@
1
+ namespace :jay_unit do
2
+ task :run => [:environment] do
3
+ require "#{RAILS_ROOT}/lib/jay_unit.rb"
4
+ JayUnit.run ENV['test']
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jay_unit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jason Knight
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-11 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Seriously simple testing.
15
+ email:
16
+ - jason@jason-knight-martin.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - Rakefile
24
+ - jay_unit.gemspec
25
+ - lib/jay_unit.rb
26
+ - lib/jay_unit/version.rb
27
+ - lib/tasks/jayunit.rake
28
+ homepage: http://jolierouge.net
29
+ licenses: []
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project: jay_unit
48
+ rubygems_version: 1.8.10
49
+ signing_key:
50
+ specification_version: 3
51
+ summary: Dead simple unit testing framework
52
+ test_files: []