nanotest 0.9

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.
@@ -0,0 +1,2 @@
1
+ doc/
2
+ pkg/
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright © 2009 Martin Aumont (mynyml)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,11 @@
1
+ .gitignore
2
+ LICENSE
3
+ Manifest
4
+ README.rdoc
5
+ Rakefile
6
+ examples.rb
7
+ gem.watchr
8
+ lib/nanotest.rb
9
+ specs.watchr
10
+ test/test_helper.rb
11
+ test/test_nanotest.rb
File without changes
@@ -0,0 +1,61 @@
1
+ begin
2
+ require 'yard'
3
+ rescue LoadError, RuntimeError
4
+ end
5
+
6
+ # --------------------------------------------------
7
+ # Gem
8
+ # --------------------------------------------------
9
+ def gemspec
10
+ @gemspec ||= Gem::Specification.new do |s|
11
+ s.name = "nanotest"
12
+ s.summary = "Out of my way, test framework!"
13
+ s.description = "Most. Miminal. Test Framework. Ever! Perfect for DIY lovers."
14
+ s.author = "Martin Aumont"
15
+ s.email = "mynyml@gmail.com"
16
+ s.homepage = "http://github.com/mynyml/nanotest"
17
+ s.rubyforge_project = "nanotest"
18
+ s.has_rdoc = false
19
+ s.require_path = "lib"
20
+ s.version = "0.9"
21
+ s.files = File.read("Manifest").strip.split("\n")
22
+
23
+ s.add_development_dependency 'minitest'
24
+ end
25
+ end
26
+
27
+ desc "Create a Ruby GEM package with the given name and version."
28
+ task(:gem) do
29
+ file = Gem::Builder.new(gemspec).build
30
+ FileUtils.mkdir 'pkg/' unless File.directory? 'pkg'
31
+ FileUtils.mv file, "pkg/#{file}", :verbose => true
32
+ end
33
+
34
+ desc "Create gemspec file"
35
+ task(:gemspec) do
36
+ open("#{gemspec.name}.gemspec", 'w') {|f| f << YAML.dump(gemspec) }
37
+ end
38
+
39
+ # --------------------------------------------------
40
+ # Tests
41
+ # --------------------------------------------------
42
+ namespace(:test) do
43
+
44
+ desc "Run all tests"
45
+ task(:all) do
46
+ tests = Dir['test/**/test_*.rb'] - ['test/test_helper.rb']
47
+ cmd = "ruby -rubygems -Ilib -e'%w( #{tests.join(' ')} ).each {|file| require file }'"
48
+ puts(cmd) if ENV['VERBOSE']
49
+ system(cmd)
50
+ end
51
+ end
52
+
53
+ # --------------------------------------------------
54
+ # Docs
55
+ # --------------------------------------------------
56
+ if defined? YARD
57
+ YARD::Rake::YardocTask.new do |t|
58
+ t.files = %w( lib/**/*.rb )
59
+ t.options = %w( -o doc/yard --readme README.rdoc --files LICENSE )
60
+ end
61
+ end
@@ -0,0 +1,31 @@
1
+ require 'nanotest'
2
+
3
+ include NanoTest
4
+
5
+ class Foo
6
+ attr_accessor :a
7
+ end
8
+
9
+ @foo = Foo.new
10
+
11
+ assert { @foo.is_a?(Foo) }
12
+ assert { @foo.respond_to?(:a) }
13
+ assert { @foo.a.nil? }
14
+
15
+ @foo.a = 'a'
16
+ @foo.a << 'b'
17
+
18
+ assert { @foo.a == 'ab' }
19
+
20
+ @foo.a = nil
21
+
22
+ assert { @foo.a == 'a' }
23
+ assert('boom') { false }
24
+
25
+ __END__
26
+ output:
27
+
28
+ ....FF
29
+ (examples.rb:22) assertion failed
30
+ (examples.rb:23) boom
31
+
@@ -0,0 +1,36 @@
1
+ # Run me with:
2
+ #
3
+ # $ watchr gem.watchr
4
+ #
5
+ # Manifest file can be automatically generated with:
6
+ #
7
+ # $ cat .git/hooks/post-commit
8
+ # #!bin/sh
9
+ # git ls-files > Manifest
10
+ #
11
+
12
+ # --------------------------------------------------
13
+ # Helpers
14
+ # --------------------------------------------------
15
+ def build
16
+ system "rake -s gem"; puts
17
+ end
18
+
19
+ # --------------------------------------------------
20
+ # Watchr Rules
21
+ # --------------------------------------------------
22
+ watch( '^Rakefile$' ) { build }
23
+ watch( '^Manifest$' ) { build }
24
+
25
+ # --------------------------------------------------
26
+ # Signal Handling
27
+ # --------------------------------------------------
28
+ # Ctrl-\
29
+ Signal.trap('QUIT') do
30
+ puts " --- Building Gem ---\n\n"
31
+ build
32
+ end
33
+
34
+ # Ctrl-C
35
+ Signal.trap('INT') { abort("\n") }
36
+
@@ -0,0 +1,18 @@
1
+ module NanoTest
2
+ extend self
3
+
4
+ FAILURES = []
5
+
6
+ def assert(msg="assertion failed",file=nil,line=nil,&block)
7
+ if block.call == false
8
+ file ||= caller.first.split(':')[0]
9
+ line ||= caller.first.split(':')[1]
10
+ FAILURES << "(#{file}:#{line}) #{msg}"
11
+ print 'F'
12
+ else
13
+ print '.'
14
+ end
15
+ end
16
+
17
+ at_exit { puts; FAILURES.each {|f| puts f } }
18
+ end
@@ -0,0 +1,37 @@
1
+ # Run me with:
2
+ #
3
+ # $ watchr specs.watchr
4
+
5
+ # --------------------------------------------------
6
+ # Helpers
7
+ # --------------------------------------------------
8
+ def run(cmd)
9
+ puts(cmd)
10
+ system(cmd)
11
+ end
12
+
13
+ def run_all_tests
14
+ # see Rakefile for the definition of the test:all task
15
+ system( "rake -s test:all VERBOSE=true" )
16
+ end
17
+
18
+ # --------------------------------------------------
19
+ # Watchr Rules
20
+ # --------------------------------------------------
21
+ watch( '^examples\.rb' ) { |m| run( "ruby -rubygems -Ilib %s" % m[0] ) }
22
+ watch( '^test.*/test_.*\.rb' ) { |m| run( "ruby -rubygems -Ilib %s" % m[0] ) }
23
+ watch( '^lib/(.*)\.rb' ) { |m| run( "ruby -rubygems -Ilib test/test_%s.rb" % m[1] ) }
24
+ watch( '^test/test_helper\.rb' ) { run_all_tests }
25
+
26
+ # --------------------------------------------------
27
+ # Signal Handling
28
+ # --------------------------------------------------
29
+ # Ctrl-\
30
+ Signal.trap('QUIT') do
31
+ puts " --- Running all tests ---\n\n"
32
+ run_all_tests
33
+ end
34
+
35
+ # Ctrl-C
36
+ Signal.trap('INT') { abort("\n") }
37
+
@@ -0,0 +1,8 @@
1
+ require 'minitest/autorun'
2
+ require 'nanotest'
3
+
4
+ class MiniTest::Unit::TestCase
5
+ def self.test(name, &block)
6
+ define_method("test_#{name.gsub(/\s/,'_').downcase}", &block)
7
+ end
8
+ end
@@ -0,0 +1,45 @@
1
+ require 'test/test_helper'
2
+
3
+ class TestNanoTest < MiniTest::Unit::TestCase
4
+
5
+ def teardown
6
+ NanoTest::FAILURES.clear
7
+ end
8
+
9
+ test "api" do
10
+ class Foo; include NanoTest end
11
+ assert_respond_to Foo.new, :assert
12
+ assert_respond_to NanoTest, :assert
13
+ end
14
+
15
+ test "assertion passes" do
16
+ out, err = capture_io do
17
+ NanoTest.assert { true }
18
+ end
19
+ assert_equal '.', out
20
+ assert_empty NanoTest::FAILURES
21
+ end
22
+
23
+ test "assertion fails" do
24
+ out, err = capture_io do
25
+ NanoTest.assert { false }
26
+ end
27
+ assert_equal 'F', out
28
+ refute_empty NanoTest::FAILURES
29
+ end
30
+
31
+ test "failure message" do
32
+ capture_io do
33
+ @line = __LINE__; NanoTest.assert { false }
34
+ end
35
+ assert_equal 1, NanoTest::FAILURES.size
36
+ assert_includes NanoTest::FAILURES, "(#{__FILE__}:#{@line}) assertion failed"
37
+ end
38
+
39
+ test "custom failure message, file, line" do
40
+ capture_io do
41
+ NanoTest.assert('foo','bar',2) { false }
42
+ end
43
+ assert_includes NanoTest::FAILURES, "(bar:2) foo"
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nanotest
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.9"
5
+ platform: ruby
6
+ authors:
7
+ - Martin Aumont
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-28 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: minitest
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Most. Miminal. Test Framework. Ever! Perfect for DIY lovers.
26
+ email: mynyml@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - .gitignore
35
+ - LICENSE
36
+ - Manifest
37
+ - README.rdoc
38
+ - Rakefile
39
+ - examples.rb
40
+ - gem.watchr
41
+ - lib/nanotest.rb
42
+ - specs.watchr
43
+ - test/test_helper.rb
44
+ - test/test_nanotest.rb
45
+ has_rdoc: false
46
+ homepage: http://github.com/mynyml/nanotest
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options: []
51
+
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project: nanotest
69
+ rubygems_version: 1.3.5
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Out of my way, test framework!
73
+ test_files: []
74
+