nanotest_extensions 0.5 → 0.6
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 +1 -0
- data/Manifest +5 -0
- data/README.rdoc +3 -3
- data/README_CONTEXTS.rdoc +11 -10
- data/Rakefile +12 -4
- data/lib/nanotest/contexts.rb +3 -0
- data/lib/nanotest/focus.rb +29 -0
- data/lib/nanotest/spec.rb +3 -0
- data/lib/nanotest/stats.rb +18 -0
- data/nanotest_extensions.gemspec +1 -1
- data/test/test_contexts.rb +2 -3
- data/test/test_focus.rb +20 -0
- data/test/test_helper.rb +5 -0
- data/test/test_spec.rb +1 -1
- data/test/test_stats.rb +29 -0
- metadata +7 -2
data/.gitignore
CHANGED
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/
|
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
|
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
|
25
|
-
@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.
|
33
|
-
either
|
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
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
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 )
|
data/lib/nanotest/contexts.rb
CHANGED
@@ -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
@@ -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 }
|
data/nanotest_extensions.gemspec
CHANGED
@@ -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.
|
10
|
+
s.version = "0.6"
|
11
11
|
s.files = File.read("Manifest").strip.split("\n")
|
12
12
|
|
13
13
|
s.add_development_dependency 'nanotest'
|
data/test/test_contexts.rb
CHANGED
data/test/test_focus.rb
ADDED
@@ -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 }
|
data/test/test_helper.rb
ADDED
data/test/test_spec.rb
CHANGED
data/test/test_stats.rb
ADDED
@@ -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.
|
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-
|
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: []
|