nanocontexts 0.9

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,8 @@
1
+ .gitignore
2
+ LICENSE
3
+ Manifest
4
+ Rakefile
5
+ gem.watchr
6
+ lib/nanocontexts.rb
7
+ specs.watchr
8
+ test/test_nanocontexts.rb
data/Rakefile ADDED
@@ -0,0 +1,87 @@
1
+ task(:default => "test:all")
2
+
3
+ # --------------------------------------------------
4
+ # Gem
5
+ # --------------------------------------------------
6
+ def gemspec
7
+ @gemspec ||= Gem::Specification.new do |s|
8
+ s.name = "nanocontexts"
9
+ s.summary = "When all you need is setups"
10
+ s.description = "Extremely mynymal contexts with setups and teardowns. Perfect for DIY lovers. NanoContexts provides the bare mynymum needed; for everything else, there's ruby."
11
+ s.author = "Martin Aumont"
12
+ s.email = "mynyml@gmail.com"
13
+ s.homepage = "http://github.com/mynyml/nanocontexts"
14
+ s.rubyforge_project = "nanotest"
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_development_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
+ File.read(file).each_line do |line|
82
+ loc += 1 unless line.strip.empty? || line.strip =~ /^#/
83
+ end
84
+ end
85
+ puts "lib files contain #{loc} SLOCs"
86
+ end
87
+
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,26 @@
1
+ module NanoContexts
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
data/specs.watchr ADDED
@@ -0,0 +1,37 @@
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( '^examples\.rb' ) { |m| system( "ruby -rubygems -Ilib %s" % m[0] ) }
22
+ watch( '^test.*/test_.*\.rb' ) { |m| run( "ruby -rubygems -Ilib %s" % m[0] ) }
23
+ watch( '^lib/(.*)\.rb' ) { |m| run( "ruby -rubygems -Ilib test/test_%s.rb" % m[1] ) }
24
+ watch( '^test/test_helper\.rb' ) { run_all_tests }
25
+
26
+ # --------------------------------------------------
27
+ # Signal Handling
28
+ # --------------------------------------------------
29
+ # Ctrl-\
30
+ Signal.trap('QUIT') do
31
+ puts " --- Running all tests ---\n\n"
32
+ run_all_tests
33
+ end
34
+
35
+ # Ctrl-C
36
+ Signal.trap('INT') { abort("\n") }
37
+
@@ -0,0 +1,56 @@
1
+ require 'nanotest'
2
+ require 'lib/nanocontexts'
3
+
4
+ include NanoTest
5
+
6
+ # test: API
7
+ assert { NanoContexts.respond_to?(:context) }
8
+ assert { NanoContexts.respond_to?(:setup) }
9
+ assert { NanoContexts.respond_to?(:teardown) }
10
+ assert { NanoContexts.respond_to?(:test) }
11
+
12
+ class API
13
+ include NanoContexts
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 NanoContexts
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
+
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nanocontexts
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-01 01:00:00 -04: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: Extremely mynymal contexts with setups and teardowns. Perfect for DIY lovers. NanoContexts provides the bare mynymum needed; for everything else, there's ruby.
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/nanocontexts.rb
40
+ - specs.watchr
41
+ - test/test_nanocontexts.rb
42
+ has_rdoc: false
43
+ homepage: http://github.com/mynyml/nanocontexts
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
66
+ rubygems_version: 1.3.5
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: When all you need is setups
70
+ test_files: []
71
+