nanotest 0.9.2 → 0.9.3

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/Manifest CHANGED
@@ -6,6 +6,7 @@ Rakefile
6
6
  examples.rb
7
7
  gem.watchr
8
8
  lib/nanotest.rb
9
+ nanotest.gemspec
9
10
  specs.watchr
10
11
  test/test_helper.rb
11
12
  test/test_nanotest.rb
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  === Summary
2
2
 
3
- Extremely mynymal test framework. Perfect for DIY lovers. NanoTest provides
3
+ Extremely mynymal test framework. Perfect for DIY lovers. Nanotest provides
4
4
  the bare mynymum needed; for everything else, there's ruby.
5
5
 
6
6
  === Install
@@ -10,23 +10,26 @@ the bare mynymum needed; for everything else, there's ruby.
10
10
  === Examples
11
11
 
12
12
  require 'nanotest'
13
- include NanoTest
13
+ include Nanotest
14
14
 
15
- assert { 1 == 1 }
16
- assert { 1 >= 1 }
17
- assert { 1 == 2 } #line 12
15
+ assert { 1 == 1 }
16
+ assert { 2 > 1 }
17
+ assert { not 1 > 2 }
18
+ assert { 1 == 2 } #line 12
18
19
 
19
20
  outputs:
20
21
 
21
- ..F
22
+ ...F
22
23
  (examples.rb:012) assertion failed
23
24
 
25
+ There's also a real life example at http://github.com/mynyml/phocus/blob/master/test/test_phocus.rb
26
+
24
27
  === API
25
28
 
26
- NanoTest has a single method: #assert. You can either include NanoTest as
29
+ Nanotest has a single method: #assert. You can either include Nanotest as
27
30
  above, or use its method directly:
28
31
 
29
- NanoTest.assert { true }
32
+ Nanotest.assert { true }
30
33
 
31
34
  Its block is expected to return a boolean. If it's false it fails, otherwise
32
35
  it passes. Simple as that.
@@ -42,7 +45,7 @@ fancy, check out the wiki for a few tips and tricks.
42
45
  === Stats
43
46
 
44
47
  $ rake -s loc
45
- lib files contain 15 SLOCs
48
+ lib files contain 18 SLOCs
46
49
 
47
50
  === Links
48
51
 
data/Rakefile CHANGED
@@ -1,39 +1,8 @@
1
- # --------------------------------------------------
2
- # Gem
3
- # --------------------------------------------------
4
- def gemspec
5
- @gemspec ||= Gem::Specification.new do |s|
6
- s.name = "nanotest"
7
- s.summary = "When all you need is #assert"
8
- s.description = "Extremely mynymal test framework. Perfect for DIY lovers. NanoTest provides the bare mynymum needed; for everything else, there's ruby."
9
- s.author = "Martin Aumont"
10
- s.email = "mynyml@gmail.com"
11
- s.homepage = "http://github.com/mynyml/nanotest"
12
- s.rubyforge_project = "nanotest"
13
- s.has_rdoc = false
14
- s.require_path = "lib"
15
- s.version = "0.9.2"
16
- s.files = File.read("Manifest").strip.split("\n")
17
-
18
- s.add_development_dependency 'minitest'
19
- end
20
- end
21
-
22
- desc "Create a Ruby GEM package with the given name and version."
23
- task(:gem) do
24
- file = Gem::Builder.new(gemspec).build
25
- FileUtils.mkdir 'pkg/' unless File.directory? 'pkg'
26
- FileUtils.mv file, "pkg/#{file}", :verbose => true
27
- end
28
-
29
- desc "Create gemspec file"
30
- task(:gemspec) do
31
- open("#{gemspec.name}.gemspec", 'w') {|f| f << YAML.dump(gemspec) }
32
- end
33
-
34
1
  # --------------------------------------------------
35
2
  # Tests
36
3
  # --------------------------------------------------
4
+ task(:default => "test:all")
5
+
37
6
  namespace(:test) do
38
7
 
39
8
  desc "Run all tests"
@@ -46,7 +15,7 @@ namespace(:test) do
46
15
 
47
16
  desc "Run all tests on multiple ruby versions (requires rvm)"
48
17
  task(:portability) do
49
- versions = %w( 1.8.6 1.8.7 1.9 1.9.2 jruby jruby\ -v\ 1.4.0RC1 )
18
+ versions = %w( 1.8.6 1.8.7 1.9 1.9.2 jruby )
50
19
  versions.each do |version|
51
20
  system <<-BASH
52
21
  bash -c 'source ~/.rvm/scripts/rvm;
@@ -76,6 +45,7 @@ desc "LOC count"
76
45
  task(:loc) do
77
46
  loc = 0
78
47
  Dir['lib/**/*'].each do |file|
48
+ next if File.directory?(file)
79
49
  File.read(file).each_line do |line|
80
50
  loc += 1 unless line.strip.empty? || line.strip =~ /^#/
81
51
  end
data/lib/nanotest.rb CHANGED
@@ -1,18 +1,22 @@
1
- module NanoTest
1
+ module Nanotest
2
2
  extend self
3
3
 
4
- FAILURES = []
4
+ @@failures, @@dots = [], []
5
5
 
6
- def assert(msg="assertion failed", file=nil, line=nil, &block)
6
+ def assert(msg=nil, file=nil, line=nil, &block)
7
7
  unless block.call
8
8
  file ||= caller.first.split(':')[0]
9
9
  line ||= caller.first.split(':')[1]
10
- FAILURES << "(%s:%0.3d) %s" % [file,line,msg]
11
- print 'F'
10
+ @@failures << "(%s:%0.3d) %s" % [file, line, msg || "assertion failed"]
11
+ @@dots << 'F'
12
12
  else
13
- print '.'
13
+ @@dots << '.'
14
14
  end
15
15
  end
16
16
 
17
- at_exit { puts; FAILURES.each {|f| puts f } }
17
+ def self.results #:nodoc:
18
+ @@dots.join + "\n" + @@failures.join("\n")
19
+ end
20
+
21
+ at_exit { puts results unless results.strip.empty? }
18
22
  end
data/nanotest.gemspec ADDED
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "nanotest"
3
+ s.summary = "When all you need is #assert"
4
+ s.description = "Extremely mynymal test framework. Perfect for DIY lovers. Nanotest provides the bare mynymum needed; for everything else, there's ruby."
5
+ s.author = "Martin Aumont"
6
+ s.email = "mynyml@gmail.com"
7
+ s.homepage = "http://github.com/mynyml/nanotest"
8
+ s.rubyforge_project = "nanotest"
9
+ s.has_rdoc = false
10
+ s.require_path = "lib"
11
+ s.version = "0.9.3"
12
+ s.files = File.read("Manifest").strip.split("\n")
13
+
14
+ s.add_development_dependency 'minitest'
15
+ end
@@ -1,53 +1,80 @@
1
+ require 'minitest/autorun'
1
2
  require 'test/test_helper'
2
3
 
3
- class TestNanoTest < MiniTest::Unit::TestCase
4
+ module Nanotest
5
+ class << self
6
+ def failures() @@failures end
7
+ def dots() @@dots end
8
+ end
9
+
10
+ # don't autorun
11
+ def at_exit() end
12
+ end
13
+ require 'nanotest'
14
+
15
+ # fixture class for nanotest mixin
16
+ class Foo
17
+ include Nanotest
18
+ end
19
+
20
+ class TestNanotest < MiniTest::Unit::TestCase
21
+ def self.test(name, &block)
22
+ define_method("test_#{name.gsub(/\s/,'_')}", &block)
23
+ end
4
24
 
5
25
  def teardown
6
- NanoTest::FAILURES.clear
26
+ Nanotest::dots.clear
27
+ Nanotest::failures.clear
7
28
  end
8
29
 
9
30
  test "api" do
10
- class Foo; include NanoTest end
11
31
  assert_respond_to Foo.new, :assert
12
- assert_respond_to NanoTest, :assert
32
+ assert_respond_to Nanotest, :assert
13
33
  end
14
34
 
15
35
  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
36
+ Nanotest.assert { true }
37
+ assert_equal '.', Nanotest::dots.last
38
+ assert_empty Nanotest::failures
21
39
  end
22
40
 
23
41
  test "assertion fails (false)" do
24
- out, err = capture_io do
25
- NanoTest.assert { false }
26
- end
27
- assert_equal 'F', out
28
- refute_empty NanoTest::FAILURES
42
+ Nanotest.assert { false }
43
+ assert_equal 'F', Nanotest::dots.last
44
+ refute_empty Nanotest::failures
29
45
  end
30
46
 
31
47
  test "assertion fails (nil)" do
32
- out, err = capture_io do
33
- NanoTest.assert { nil }
34
- end
35
- assert_equal 'F', out
36
- refute_empty NanoTest::FAILURES
48
+ Nanotest.assert { nil }
49
+ assert_equal 'F', Nanotest::dots.last
50
+ refute_empty Nanotest::failures
37
51
  end
38
52
 
39
53
  test "failure message" do
40
- capture_io do
41
- @line = __LINE__; NanoTest.assert { false }
42
- end
43
- assert_equal 1, NanoTest::FAILURES.size
44
- assert_includes NanoTest::FAILURES, "(%s:%0.3d) assertion failed" % [__FILE__, @line]
54
+ @line = __LINE__; Nanotest.assert { false }
55
+ assert_equal 1, Nanotest::failures.size
56
+ assert_includes Nanotest::failures, "(%s:%0.3d) assertion failed" % [__FILE__, @line]
45
57
  end
46
58
 
47
59
  test "custom failure message, file, line" do
48
- capture_io do
49
- NanoTest.assert('foo','bar',2) { false }
50
- end
51
- assert_includes NanoTest::FAILURES, "(bar:002) foo"
60
+ Nanotest.assert('foo','bar',2) { false }
61
+ assert_includes Nanotest::failures, "(bar:002) foo"
62
+ end
63
+
64
+ test "displays results" do
65
+ Nanotest.assert { true }
66
+ Nanotest.assert { false }; line1 = __LINE__
67
+ Nanotest.assert { false }; line2 = __LINE__
68
+ expected = <<-OUT.gsub(/^\s*/,'').strip % [__FILE__, line1, __FILE__, line2]
69
+ .FF
70
+ (%s:%0.3d) assertion failed
71
+ (%s:%0.3d) assertion failed
72
+ OUT
73
+ assert_equal expected, Nanotest.results
74
+ end
75
+
76
+ test "displays results with no assertions" do
77
+ assert_empty Nanotest.results.strip
52
78
  end
53
79
  end
80
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanotest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Aumont
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-03 00:00:00 -05:00
12
+ date: 2009-11-27 00:00:00 -03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,7 +22,7 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
24
  version:
25
- description: Extremely mynymal test framework. Perfect for DIY lovers. NanoTest provides the bare mynymum needed; for everything else, there's ruby.
25
+ description: Extremely mynymal test framework. Perfect for DIY lovers. Nanotest provides the bare mynymum needed; for everything else, there's ruby.
26
26
  email: mynyml@gmail.com
27
27
  executables: []
28
28
 
@@ -39,6 +39,7 @@ files:
39
39
  - examples.rb
40
40
  - gem.watchr
41
41
  - lib/nanotest.rb
42
+ - nanotest.gemspec
42
43
  - specs.watchr
43
44
  - test/test_helper.rb
44
45
  - test/test_nanotest.rb