nanotest_spec 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.
- data/.gitignore +3 -0
- data/LICENSE +19 -0
- data/Manifest +8 -0
- data/Rakefile +88 -0
- data/gem.watchr +36 -0
- data/lib/nanotest/spec.rb +28 -0
- data/specs.watchr +35 -0
- data/test/test_spec.rb +28 -0
- metadata +71 -0
data/.gitignore
ADDED
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.
|
data/Manifest
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
task(:default => "test:all")
|
2
|
+
|
3
|
+
# --------------------------------------------------
|
4
|
+
# Gem
|
5
|
+
# --------------------------------------------------
|
6
|
+
def gemspec
|
7
|
+
@gemspec ||= Gem::Specification.new do |s|
|
8
|
+
s.name = "nanotest_spec"
|
9
|
+
s.summary = "nanotest extension that allows asserting using obj.must / obj.wont"
|
10
|
+
s.description = "nanotest extension that allows asserting using obj.must / obj.wont."
|
11
|
+
s.author = "Martin Aumont"
|
12
|
+
s.email = "mynyml@gmail.com"
|
13
|
+
s.homepage = "http://github.com/mynyml/nanotest_spec"
|
14
|
+
s.rubyforge_project = "nanotest_spec"
|
15
|
+
s.has_rdoc = false
|
16
|
+
s.require_path = "lib"
|
17
|
+
s.version = "0.9"
|
18
|
+
s.files = File.read("Manifest").strip.split("\n")
|
19
|
+
|
20
|
+
s.add_dependency 'nanotest'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Create a Ruby GEM package with the given name and version."
|
25
|
+
task(:gem) do
|
26
|
+
file = Gem::Builder.new(gemspec).build
|
27
|
+
FileUtils.mkdir 'pkg/' unless File.directory? 'pkg'
|
28
|
+
FileUtils.mv file, "pkg/#{file}", :verbose => true
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "Create gemspec file"
|
32
|
+
task(:gemspec) do
|
33
|
+
open("#{gemspec.name}.gemspec", 'w') {|f| f << YAML.dump(gemspec) }
|
34
|
+
end
|
35
|
+
|
36
|
+
# --------------------------------------------------
|
37
|
+
# Tests
|
38
|
+
# --------------------------------------------------
|
39
|
+
namespace(:test) do
|
40
|
+
|
41
|
+
desc "Run all tests"
|
42
|
+
task(:all) do
|
43
|
+
tests = Dir['test/**/test_*.rb'] - ['test/test_helper.rb']
|
44
|
+
cmd = "ruby -rubygems -I.:lib -e'%w( #{tests.join(' ')} ).each {|file| require file }'"
|
45
|
+
puts(cmd) if ENV['VERBOSE']
|
46
|
+
system(cmd)
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "Run all tests on multiple ruby versions (requires rvm)"
|
50
|
+
task(:portability) do
|
51
|
+
versions = %w( 1.8.6 1.8.7 1.9 1.9.2 jruby )
|
52
|
+
versions.each do |version|
|
53
|
+
system <<-BASH
|
54
|
+
bash -c 'source ~/.rvm/scripts/rvm;
|
55
|
+
rvm use #{version};
|
56
|
+
echo "--------- #{version} ----------";
|
57
|
+
rake -s test:all'
|
58
|
+
BASH
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# --------------------------------------------------
|
64
|
+
# Docs
|
65
|
+
# --------------------------------------------------
|
66
|
+
desc "Generate YARD Documentation"
|
67
|
+
task :yardoc do
|
68
|
+
require 'yard'
|
69
|
+
files = %w( lib/**/*.rb )
|
70
|
+
options = %w( -o doc/yard --readme README.rdoc --files LICENSE )
|
71
|
+
YARD::CLI::Yardoc.run *(options + files)
|
72
|
+
end
|
73
|
+
|
74
|
+
# --------------------------------------------------
|
75
|
+
# Stats
|
76
|
+
# --------------------------------------------------
|
77
|
+
desc "LOC count"
|
78
|
+
task(:loc) do
|
79
|
+
loc = 0
|
80
|
+
Dir['lib/**/*'].each do |file|
|
81
|
+
next if File.directory?(file)
|
82
|
+
File.read(file).each_line do |line|
|
83
|
+
loc += 1 unless line.strip.empty? || line.strip =~ /^#/
|
84
|
+
end
|
85
|
+
end
|
86
|
+
puts "lib files contain #{loc} SLOCs"
|
87
|
+
end
|
88
|
+
|
data/gem.watchr
ADDED
@@ -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,28 @@
|
|
1
|
+
require 'nanotest'
|
2
|
+
|
3
|
+
module NanoTest
|
4
|
+
class Spec
|
5
|
+
instance_methods.each {|m| undef_method(m) unless m.match(/^__|object_id/) }
|
6
|
+
|
7
|
+
def initialize(obj, positive=true)
|
8
|
+
@obj, @positive = obj, positive
|
9
|
+
end
|
10
|
+
|
11
|
+
def method_missing(method, *args, &block)
|
12
|
+
file, line = caller.first.split(':')[0..1]
|
13
|
+
bool = @obj.__send__(method, *args, &block)
|
14
|
+
bool = !bool unless @positive
|
15
|
+
NanoTest.assert("assertion failed", file, line) { bool }
|
16
|
+
@obj
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Object
|
22
|
+
def must
|
23
|
+
NanoTest::Spec.new(self)
|
24
|
+
end
|
25
|
+
def wont
|
26
|
+
NanoTest::Spec.new(self, false)
|
27
|
+
end
|
28
|
+
end
|
data/specs.watchr
ADDED
@@ -0,0 +1,35 @@
|
|
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( '^test.*/test_.*\.rb' ) { |m| run( "ruby -rubygems -I.:lib %s" % m[0] ) }
|
22
|
+
watch( '^lib/nanotest/(.*)\.rb' ) { |m| run( "ruby -rubygems -I.:lib test/test_%s.rb" % m[1] ) }
|
23
|
+
|
24
|
+
# --------------------------------------------------
|
25
|
+
# Signal Handling
|
26
|
+
# --------------------------------------------------
|
27
|
+
# Ctrl-\
|
28
|
+
Signal.trap('QUIT') do
|
29
|
+
puts " --- Running all tests ---\n\n"
|
30
|
+
run_all_tests
|
31
|
+
end
|
32
|
+
|
33
|
+
# Ctrl-C
|
34
|
+
Signal.trap('INT') { abort("\n") }
|
35
|
+
|
data/test/test_spec.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'nanotest'
|
2
|
+
require 'nanotest/spec'
|
3
|
+
include NanoTest
|
4
|
+
|
5
|
+
# test: object assertion
|
6
|
+
'abc'.size.must == 3
|
7
|
+
|
8
|
+
# test: class assertion
|
9
|
+
String.must.respond_to?(:new)
|
10
|
+
|
11
|
+
# test: module assertion
|
12
|
+
Enumerable.must.is_a?(Module)
|
13
|
+
|
14
|
+
# test: handles blocks
|
15
|
+
[1,2,3].must.detect {|i| i == 2 }
|
16
|
+
|
17
|
+
# test: negative assertions
|
18
|
+
[1,2,3].wont.include?(4)
|
19
|
+
|
20
|
+
# test: chaining, for great justice
|
21
|
+
[1,2,3].must.include?(1).
|
22
|
+
must.include?(2).
|
23
|
+
must.include?(3)
|
24
|
+
|
25
|
+
# test: mixed positive/negative assertion chaining
|
26
|
+
[1,2,3].must.include?(1).
|
27
|
+
wont.include?(4)
|
28
|
+
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nanotest_spec
|
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-11-03 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: nanotest
|
17
|
+
type: :runtime
|
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: nanotest extension that allows asserting using obj.must / obj.wont.
|
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
|
+
- Rakefile
|
38
|
+
- gem.watchr
|
39
|
+
- lib/nanotest/spec.rb
|
40
|
+
- specs.watchr
|
41
|
+
- test/test_spec.rb
|
42
|
+
has_rdoc: false
|
43
|
+
homepage: http://github.com/mynyml/nanotest_spec
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project: nanotest_spec
|
66
|
+
rubygems_version: 1.3.5
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: nanotest extension that allows asserting using obj.must / obj.wont
|
70
|
+
test_files: []
|
71
|
+
|