nanotest_extensions 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  doc/
2
2
  pkg/
3
3
  .yardoc
4
+ *.gem
data/Manifest CHANGED
@@ -6,8 +6,13 @@ README_CONTEXTS.rdoc
6
6
  README_SPEC.rdoc
7
7
  Rakefile
8
8
  lib/nanotest/contexts.rb
9
+ lib/nanotest/focus.rb
9
10
  lib/nanotest/spec.rb
11
+ lib/nanotest/stats.rb
10
12
  nanotest_extensions.gemspec
11
13
  specs.watchr
12
14
  test/test_contexts.rb
15
+ test/test_focus.rb
16
+ test/test_helper.rb
13
17
  test/test_spec.rb
18
+ test/test_stats.rb
data/README.rdoc CHANGED
@@ -1,10 +1,10 @@
1
1
  === Summary
2
2
 
3
3
  Provides a few nano extensions to use with nanotest[http://github.com/mynyml/nanotest].
4
- See each extension's README for examples:
4
+ See each extension's README for details and examples:
5
5
 
6
- nanotest/spec[README_SPEC.rdoc]
7
- nanotest/context[README_CONTEXTS.rdoc]
6
+ * nanotest/spec[http://github.com/mynyml/nanotest_extensions/blob/master/README_SPEC.rdoc]
7
+ * nanotest/contexts[http://github.com/mynyml/nanotest_extensions/blob/master/README_CONTEXTS.rdoc]
8
8
 
9
9
  === Install
10
10
 
data/README_CONTEXTS.rdoc CHANGED
@@ -6,6 +6,7 @@ Provides embeddable contexts with setups and teardowns
6
6
 
7
7
  require 'nanotest'
8
8
  require 'nanotest/contexts'
9
+ include Nanotest
9
10
  include Nanotest::Contexts
10
11
 
11
12
  context do
@@ -14,30 +15,30 @@ Provides embeddable contexts with setups and teardowns
14
15
 
15
16
  # test description
16
17
  test do
17
- @foo #=> 'foo'
18
+ assert { @foo == 'foo' }
18
19
  end
19
20
 
20
21
  context do
21
22
  setup { @bar = 'bar' }
22
23
 
23
24
  test do
24
- @foo #=> 'foo'
25
- @bar #=> 'bar'
25
+ assert { @foo == 'foo' }
26
+ assert { @bar == 'bar' }
26
27
  end
27
28
  end
28
29
  end
29
30
 
30
31
  === API
31
32
 
32
- Contexts provides 4 methods: #context, #setup, #teardown, #test. You can
33
- either include Contexts as above, or use its methods directly:
33
+ Contexts provides 4 methods: #context, #setup, #teardown, #test. To use them,
34
+ you can either mixin the Contexts module as above, or keep them namespaced:
34
35
 
35
- Nanotest::Contexts.context {}
36
- Nanotest::Contexts.setup {}
37
- Nanotest::Contexts.teardown {}
38
- Nanotest::Contexts.test {}
36
+ Nanotest::Contexts.context do
37
+ setup {}
38
+ # ...
39
+ end
39
40
 
40
- If you prefer other method names, simply alias them
41
+ If you prefer other method names, simply alias them:
41
42
 
42
43
  module Nanotest::Contexts
43
44
  alias :describe :context
data/Rakefile CHANGED
@@ -5,14 +5,22 @@ task(:default => "test:all")
5
5
 
6
6
  namespace(:test) do
7
7
 
8
- desc "Run all tests"
9
- task(:all) do
10
- tests = Dir['test/**/test_*.rb'] - ['test/test_helper.rb']
11
- cmd = "ruby -rubygems -I.:lib -e'%w( #{tests.join(' ')} ).each {|file| require file }'"
8
+ def run(cmd)
12
9
  puts(cmd) if ENV['VERBOSE']
13
10
  system(cmd)
14
11
  end
15
12
 
13
+ desc "Run all tests"
14
+ task(:all) do
15
+ # test files must be run separately, or else focus kicks in and stats resets nanotest
16
+ %w(
17
+ test/test_contexts.rb
18
+ test/test_focus.rb
19
+ test/test_spec.rb
20
+ test/test_stats.rb
21
+ ).each {|test| run("ruby -rubygems -I.:lib #{test}") }
22
+ end
23
+
16
24
  desc "Run all tests on multiple ruby versions (requires rvm)"
17
25
  task(:portability) do
18
26
  versions = %w( 1.8.6 1.8.7 1.9 1.9.2 )
@@ -1,3 +1,6 @@
1
+ # "Simplicity means the achievement of maximum effect with minimum means."
2
+ # --Koichi Kawana
3
+
1
4
  module Nanotest::Contexts
2
5
  extend self
3
6
 
@@ -0,0 +1,29 @@
1
+ # "Things should be made as simple as possible, but no simpler."
2
+ # --Albert Einstein
3
+
4
+ module Nanotest
5
+
6
+ @@focused = false
7
+
8
+ def focus
9
+ unless @@focused
10
+ @@focused = true
11
+ @@dots.clear
12
+ @@failures.clear
13
+ end
14
+ @@focus_next = true
15
+ end
16
+
17
+ alias :focus__orig_assert :assert
18
+
19
+ def assert(*args, &block)
20
+ if @@focused
21
+ if @@focus_next
22
+ @@focus_next = false
23
+ focus__orig_assert(*args, &block)
24
+ end
25
+ else
26
+ focus__orig_assert(*args, &block)
27
+ end
28
+ end
29
+ end
data/lib/nanotest/spec.rb CHANGED
@@ -1,3 +1,6 @@
1
+ # "Perfection is achieved, not when there is nothing more to add, but when
2
+ # there is nothing left to take away." --Antoine de Saint Exupéry
3
+
1
4
  class Nanotest::Spec
2
5
  instance_methods.each {|m| undef_method(m) unless m.match(/^__|object_id/) }
3
6
 
@@ -0,0 +1,18 @@
1
+ # "Simplicity is the ultimate sophistication" --Leonardo Da Vinci
2
+
3
+ module Nanotest
4
+ class << self
5
+ alias :stats__orig_results :results
6
+
7
+ def results
8
+ stats = "\n(%f seconds) %d assertions, %d failures" % [Time.now-$nanotest_time, @@dots.size, @@failures.size]
9
+
10
+ # insert stats after failure message if any, or dots otherwise
11
+ lines, pos = stats__orig_results.split(/\n/), nil
12
+ lines.each_with_index {|line, i| pos = i if line =~ /\((.*):\d+\).*$/ || line =~ /(\.|F)+/ }
13
+ lines.insert(pos + 1, stats).join("\n")
14
+ end
15
+ end
16
+ end
17
+
18
+ BEGIN { $nanotest_time = Time.now }
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.homepage = "http://github.com/mynyml/nanotest_extensions"
8
8
  s.rubyforge_project = "nanotest_extensions"
9
9
  s.require_path = "lib"
10
- s.version = "0.5"
10
+ s.version = "0.6"
11
11
  s.files = File.read("Manifest").strip.split("\n")
12
12
 
13
13
  s.add_development_dependency 'nanotest'
@@ -1,7 +1,6 @@
1
- require 'nanotest'
1
+ require 'test/test_helper'
2
2
  require 'nanotest/contexts'
3
-
4
- include Nanotest
3
+ include Nanotest
5
4
 
6
5
  # test: API
7
6
  assert { Contexts.respond_to?(:context) }
@@ -0,0 +1,20 @@
1
+ require 'test/test_helper'
2
+ require 'nanotest/focus'
3
+ include Nanotest
4
+
5
+ # test: retroactively supress assertions when focus is called
6
+ assert("should not be run") { false }
7
+
8
+ # test: only run focused assertions
9
+ focus
10
+ assert { true }
11
+ assert("should not be run") { false }
12
+
13
+ # test: focuses multiple assertions
14
+ focus
15
+ assert { true }
16
+ assert("should not be run") { false }
17
+
18
+ # ensure focused assertions were run
19
+ focus
20
+ assert { Nanotest.send(:class_variable_get, :@@dots).size == 2 }
@@ -0,0 +1,5 @@
1
+ require 'nanotest'
2
+ begin
3
+ require 'redgreen'#gem install mynyml-redgreen
4
+ rescue LoadError, RuntimeError
5
+ end
data/test/test_spec.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'nanotest'
1
+ require 'test/test_helper'
2
2
  require 'nanotest/spec'
3
3
  include Nanotest
4
4
 
@@ -0,0 +1,29 @@
1
+ require 'test/test_helper'
2
+ require 'nanotest/stats'
3
+ include Nanotest
4
+
5
+ 3.times { assert{ true } }
6
+ 2.times { assert{ false } }
7
+
8
+ # capture results/stats for above assertion fixtures
9
+ results = Nanotest.results.strip
10
+ num_assertions = Nanotest.send(:class_variable_get, :@@dots ).size
11
+ num_failures = Nanotest.send(:class_variable_get, :@@failures).size
12
+
13
+ # reset results so we can begin actual tests
14
+ Nanotest.module_eval { @@dots.clear; @@failures.clear }
15
+
16
+ ## functionality
17
+
18
+ expected = Regexp.new '
19
+ \.\.\.FF
20
+ .* assertion failed
21
+ .* assertion failed
22
+
23
+ \((\d|\.)+ \w+\) %d assertions, %d failures
24
+ '.strip % [num_assertions, num_failures]
25
+
26
+ # test results string contains stats
27
+ assert("expected #{expected.inspect} to match #{results.inspect}") {
28
+ results.match(expected)
29
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanotest_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.5"
4
+ version: "0.6"
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-27 00:00:00 -03:00
12
+ date: 2009-11-30 00:00:00 -03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -39,11 +39,16 @@ files:
39
39
  - README_SPEC.rdoc
40
40
  - Rakefile
41
41
  - lib/nanotest/contexts.rb
42
+ - lib/nanotest/focus.rb
42
43
  - lib/nanotest/spec.rb
44
+ - lib/nanotest/stats.rb
43
45
  - nanotest_extensions.gemspec
44
46
  - specs.watchr
45
47
  - test/test_contexts.rb
48
+ - test/test_focus.rb
49
+ - test/test_helper.rb
46
50
  - test/test_spec.rb
51
+ - test/test_stats.rb
47
52
  has_rdoc: true
48
53
  homepage: http://github.com/mynyml/nanotest_extensions
49
54
  licenses: []