nanotest_extensions 0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ doc/
2
+ pkg/
3
+ .yardoc
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
@@ -0,0 +1,13 @@
1
+ .gitignore
2
+ LICENSE
3
+ Manifest
4
+ README.rdoc
5
+ README_CONTEXTS.rdoc
6
+ README_SPEC.rdoc
7
+ Rakefile
8
+ lib/nanotest/contexts.rb
9
+ lib/nanotest/spec.rb
10
+ nanotest_extensions.gemspec
11
+ specs.watchr
12
+ test/test_contexts.rb
13
+ test/test_spec.rb
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ === Summary
2
+
3
+ Provides a few nano extensions to use with nanotest[http://github.com/mynyml/nanotest].
4
+ See each extension's README for examples:
5
+
6
+ nanotest/spec[README_SPEC.rdoc]
7
+ nanotest/context[README_CONTEXTS.rdoc]
8
+
9
+ === Install
10
+
11
+ gem install nanotest_extensions --source http://gemcutter.org
12
+
13
+ === Links
14
+
15
+ source:: http://github.com/mynyml/nanotest_extensions
16
+ docs:: http://rdoc.info/projects/mynyml/nanotest_extensions
17
+ wiki:: http://wiki.github.com/mynyml/nanotest_extensions
18
+ bugs:: http://github.com/mynyml/nanotest_extensions/issues
19
+
@@ -0,0 +1,47 @@
1
+ === Summary
2
+
3
+ Provides embeddable contexts with setups and teardowns
4
+
5
+ === Examples
6
+
7
+ require 'nanotest'
8
+ require 'nanotest/contexts'
9
+ include Nanotest::Contexts
10
+
11
+ context do
12
+ setup { @foo = 'foo' }
13
+ teardown { @foo = nil }
14
+
15
+ # test description
16
+ test do
17
+ @foo #=> 'foo'
18
+ end
19
+
20
+ context do
21
+ setup { @bar = 'bar' }
22
+
23
+ test do
24
+ @foo #=> 'foo'
25
+ @bar #=> 'bar'
26
+ end
27
+ end
28
+ end
29
+
30
+ === API
31
+
32
+ Contexts provides 4 methods: #context, #setup, #teardown, #test. You can
33
+ either include Contexts as above, or use its methods directly:
34
+
35
+ Nanotest::Contexts.context {}
36
+ Nanotest::Contexts.setup {}
37
+ Nanotest::Contexts.teardown {}
38
+ Nanotest::Contexts.test {}
39
+
40
+ If you prefer other method names, simply alias them
41
+
42
+ module Nanotest::Contexts
43
+ alias :describe :context
44
+ alias :before :setup
45
+ alias :after :teardown
46
+ end
47
+
data/README_SPEC.rdoc ADDED
@@ -0,0 +1,38 @@
1
+ === Summary
2
+
3
+ Allows assertions with .must and .wont
4
+
5
+ === Examples
6
+
7
+ require 'nanotest'
8
+ require 'nanotest/spec'
9
+ include Nanotest
10
+
11
+ 'foo'.size.must == 3
12
+ 'bar'.size.wont <= 1
13
+
14
+ [1,2,3].must.include?(1)
15
+ [1,2,3].wont.include?(4)
16
+
17
+ # assertions can also be chained
18
+ [1,2,3].must.include?(1).
19
+ must.include?(2).
20
+ must.include?(3).
21
+ wont.include?(4)
22
+
23
+ # must/wont are full assertion proxies, so methods sent to it work as
24
+ # expected (i.e. they accept args and blocks)
25
+ [1,2,3].must.detect {|i| i == 2 }
26
+
27
+ === API
28
+
29
+ Provides two methods, Object#must and Object#wont.
30
+ The words "must" and "wont" for assertions follow minitest/spec's convention.
31
+
32
+ If you prefer other words, simply alias must/wont
33
+
34
+ class Object
35
+ alias :should :must
36
+ alias :should_not :wont
37
+ end
38
+
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ # --------------------------------------------------
2
+ # Tests
3
+ # --------------------------------------------------
4
+ task(:default => "test:all")
5
+
6
+ namespace(:test) do
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 }'"
12
+ puts(cmd) if ENV['VERBOSE']
13
+ system(cmd)
14
+ end
15
+
16
+ desc "Run all tests on multiple ruby versions (requires rvm)"
17
+ task(:portability) do
18
+ versions = %w( 1.8.6 1.8.7 1.9 1.9.2 )
19
+ versions.each do |version|
20
+ system <<-BASH
21
+ bash -c 'source ~/.rvm/scripts/rvm;
22
+ rvm #{version};
23
+ echo "--------- #{version} ----------";
24
+ rake -s test:all'
25
+ BASH
26
+ end
27
+ end
28
+ end
29
+
30
+ # --------------------------------------------------
31
+ # Docs
32
+ # --------------------------------------------------
33
+ desc "Generate YARD Documentation"
34
+ task :yardoc do
35
+ require 'yard'
36
+ files = %w( lib/**/*.rb )
37
+ options = %w( -o doc/yard --readme README.rdoc --files LICENSE )
38
+ YARD::CLI::Yardoc.run *(options + files)
39
+ end
40
+
41
+ # --------------------------------------------------
42
+ # Stats
43
+ # --------------------------------------------------
44
+ desc "LOC count"
45
+ task(:loc) do
46
+ loc = 0
47
+ Dir['lib/**/*'].each do |file|
48
+ next if File.directory?(file)
49
+ File.read(file).each_line do |line|
50
+ loc += 1 unless line.strip.empty? || line.strip =~ /^#/
51
+ end
52
+ end
53
+ puts "lib files contain #{loc} SLOCs"
54
+ end
55
+
@@ -0,0 +1,26 @@
1
+ module Nanotest::Contexts
2
+ extend self
3
+
4
+ Context = Struct.new(:setup, :teardown)
5
+
6
+ def context(&block)
7
+ @_contexts ||= []
8
+ @_contexts << Context.new
9
+ instance_eval(&block)
10
+ @_contexts.pop
11
+ end
12
+
13
+ def setup(&block)
14
+ @_contexts.last.setup = block
15
+ end
16
+
17
+ def teardown(&block)
18
+ @_contexts.last.teardown = block
19
+ end
20
+
21
+ def test(&block)
22
+ @_contexts.map {|c| c.setup }.compact.each {|s| s.call }
23
+ block.call
24
+ @_contexts.map {|c| c.teardown }.compact.each {|s| s.call }
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ class Nanotest::Spec
2
+ instance_methods.each {|m| undef_method(m) unless m.match(/^__|object_id/) }
3
+
4
+ def initialize(obj, positive=true)
5
+ @obj, @positive = obj, positive
6
+ end
7
+
8
+ def method_missing(method, *args, &block)
9
+ file, line = caller.first.split(':')[0..1]
10
+ bool = @obj.__send__(method, *args, &block)
11
+ bool = !bool unless @positive
12
+ Nanotest.assert(nil, file, line) { bool }
13
+ @obj
14
+ end
15
+ end
16
+
17
+ class Object
18
+ def must
19
+ Nanotest::Spec.new(self)
20
+ end
21
+ def wont
22
+ Nanotest::Spec.new(self, false)
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "nanotest_extensions"
3
+ s.summary = "Nano extensions for nanotest"
4
+ s.description = "Nano extensions for nanotest."
5
+ s.author = "Martin Aumont"
6
+ s.email = "mynyml@gmail.com"
7
+ s.homepage = "http://github.com/mynyml/nanotest_extensions"
8
+ s.rubyforge_project = "nanotest_extensions"
9
+ s.require_path = "lib"
10
+ s.version = "0.5"
11
+ s.files = File.read("Manifest").strip.split("\n")
12
+
13
+ s.add_development_dependency 'nanotest'
14
+ end
data/specs.watchr ADDED
@@ -0,0 +1,36 @@
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
+ watch( '^test/test_helper\.rb' ) { run_all_tests }
24
+
25
+ # --------------------------------------------------
26
+ # Signal Handling
27
+ # --------------------------------------------------
28
+ # Ctrl-\
29
+ Signal.trap('QUIT') do
30
+ puts " --- Running all tests ---\n\n"
31
+ run_all_tests
32
+ end
33
+
34
+ # Ctrl-C
35
+ Signal.trap('INT') { abort("\n") }
36
+
@@ -0,0 +1,56 @@
1
+ require 'nanotest'
2
+ require 'nanotest/contexts'
3
+
4
+ include Nanotest
5
+
6
+ # test: API
7
+ assert { Contexts.respond_to?(:context) }
8
+ assert { Contexts.respond_to?(:setup) }
9
+ assert { Contexts.respond_to?(:teardown) }
10
+ assert { Contexts.respond_to?(:test) }
11
+
12
+ class API
13
+ include Contexts
14
+ end
15
+ assert { API.new.respond_to?(:context) }
16
+ assert { API.new.respond_to?(:setup) }
17
+ assert { API.new.respond_to?(:teardown) }
18
+ assert { API.new.respond_to?(:test) }
19
+
20
+
21
+ # the rest of the tests are self-hosted, for great justice
22
+ include Contexts
23
+
24
+ context do
25
+ setup do
26
+ @parent = 'parent'
27
+ end
28
+ test do
29
+ # test: simple setup
30
+ assert { @parent == 'parent' }
31
+ end
32
+ context do
33
+ setup do
34
+ @child = 'child'
35
+ end
36
+ teardown do
37
+ @child = nil; @sibling = 'sibling'
38
+ end
39
+ test do
40
+ # test: parent setups are called
41
+ assert { @parent == 'parent' }
42
+ # test: descendent setups are also called
43
+ assert { @child == 'child' }
44
+ end
45
+ end
46
+ context do
47
+ test do
48
+ # test: teardown
49
+ assert { @sibling == 'sibling' }
50
+ # test: setups from sibling contexts are discarted
51
+ # (setup from sibling context would set @child)
52
+ assert { @child.nil? }
53
+ end
54
+ end
55
+ end
56
+
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,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nanotest_extensions
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.5"
5
+ platform: ruby
6
+ authors:
7
+ - Martin Aumont
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-27 00:00:00 -03:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: nanotest
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: Nano extensions for nanotest.
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
+ - README_CONTEXTS.rdoc
39
+ - README_SPEC.rdoc
40
+ - Rakefile
41
+ - lib/nanotest/contexts.rb
42
+ - lib/nanotest/spec.rb
43
+ - nanotest_extensions.gemspec
44
+ - specs.watchr
45
+ - test/test_contexts.rb
46
+ - test/test_spec.rb
47
+ has_rdoc: true
48
+ homepage: http://github.com/mynyml/nanotest_extensions
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options: []
53
+
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project: nanotest_extensions
71
+ rubygems_version: 1.3.5
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Nano extensions for nanotest
75
+ test_files: []
76
+