citrusbyte-contest 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/LICENSE +19 -0
  2. data/README.markdown +80 -0
  3. data/Rakefile +35 -0
  4. data/lib/contest.rb +38 -0
  5. data/test/all_test.rb +41 -0
  6. metadata +57 -0
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2009 Damian Janowski
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all 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
19
+ THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,80 @@
1
+ Contest
2
+ =======
3
+
4
+ Contexts for Test::Unit.
5
+
6
+ Description
7
+ -----------
8
+
9
+ Write declarative tests with nested contexts without performance
10
+ penalties. Contest is less than 40 lines and gets the job done.
11
+
12
+ Usage
13
+ -----
14
+
15
+ Declare your tests as you would in RSpec or Shoulda. The keywords here
16
+ are `setup`, `context` and `test`:
17
+
18
+ require 'contest'
19
+
20
+ class SomeTest < Test::Unit::TestCase
21
+ setup do
22
+ @value = 1
23
+ end
24
+
25
+ test "sample test" do
26
+ assert_equal 1, @value
27
+ end
28
+
29
+ context "a context" do
30
+ setup do
31
+ @value += 1
32
+ end
33
+
34
+ test "more tests" do
35
+ assert_equal 2, @value
36
+ end
37
+
38
+ context "a nested context" do
39
+ setup do
40
+ @value += 1
41
+ end
42
+
43
+ test "yet more tests" do
44
+ assert_equal 3, @value
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ Installation
51
+ ------------
52
+
53
+ $ gem sources -a http://gems.github.com (you only have to do this once)
54
+ $ sudo gem install citrusbyte-contest
55
+
56
+ License
57
+ -------
58
+
59
+ Copyright (c) 2009 Damian Janowski
60
+
61
+ Permission is hereby granted, free of charge, to any person
62
+ obtaining a copy of this software and associated documentation
63
+ files (the "Software"), to deal in the Software without
64
+ restriction, including without limitation the rights to use,
65
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
66
+ copies of the Software, and to permit persons to whom the
67
+ Software is furnished to do so, subject to the following
68
+ conditions:
69
+
70
+ The above copyright notice and this permission notice shall be
71
+ included in all copies or substantial portions of the Software.
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
74
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
75
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
76
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
77
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
78
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
79
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
80
+ OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ require 'rake'
2
+ require 'rake/gempackagetask'
3
+ require 'rake/testtask'
4
+ require 'rake/clean'
5
+
6
+ gem_spec_file = 'contest.gemspec'
7
+
8
+ gem_spec = eval(File.read(gem_spec_file)) rescue nil
9
+
10
+ task :default => :test
11
+
12
+ Rake::TestTask.new(:test) do |t|
13
+ t.pattern = 'test/**/*_test.rb'
14
+ t.verbose = false
15
+ end
16
+
17
+ Rake::GemPackageTask.new(gem_spec) do |pkg|
18
+ pkg.need_zip = false
19
+ pkg.need_tar = false
20
+ rm_f FileList['pkg/**/*.*']
21
+ end if gem_spec
22
+
23
+ desc "Generate the gemspec file."
24
+ task :gemspec do
25
+ require 'erb'
26
+
27
+ File.open(gem_spec_file, 'w') do |f|
28
+ f.write ERB.new(File.read("#{gem_spec_file}.erb")).result(binding)
29
+ end
30
+ end
31
+
32
+ desc "Builds and installs the gem."
33
+ task :install => :repackage do
34
+ `sudo gem install pkg/#{gem_spec.name}-#{gem_spec.version}.gem`
35
+ end
data/lib/contest.rb ADDED
@@ -0,0 +1,38 @@
1
+ require "test/unit"
2
+
3
+ class Test::Unit::TestCase
4
+ def self.setup(&block)
5
+ setup_blocks << block
6
+ end
7
+
8
+ def setup
9
+ self.class.setup_blocks.each do |block|
10
+ instance_eval(&block)
11
+ end
12
+ end
13
+
14
+ def self.context(name, &block)
15
+ subclass = Class.new(self.superclass)
16
+ subclass.setup_blocks.unshift(*setup_blocks)
17
+ subclass.class_eval(&block)
18
+ const_set(context_name(name), subclass)
19
+ end
20
+
21
+ def self.test(name, &block)
22
+ define_method(test_name(name), &block)
23
+ end
24
+
25
+ private
26
+
27
+ def self.setup_blocks
28
+ @setup_blocks ||= []
29
+ end
30
+
31
+ def self.context_name(name)
32
+ "#{name.gsub(/(^| )(\w)/) { $2.upcase }}Test".to_sym
33
+ end
34
+
35
+ def self.test_name(name)
36
+ "test_#{name.gsub(/\s+/,'_')}".to_sym
37
+ end
38
+ end
data/test/all_test.rb ADDED
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + "/../lib/contest"
2
+
3
+ class FooTest < Test::Unit::TestCase
4
+ setup do
5
+ @value = 1
6
+ end
7
+
8
+ test "truth" do
9
+ assert_equal 1, @value
10
+ end
11
+
12
+ context "some context" do
13
+ setup do
14
+ @value += 1
15
+ end
16
+
17
+ test "another truth" do
18
+ assert_equal 2, @value
19
+ end
20
+
21
+ context "and a nested context" do
22
+ setup do
23
+ @value += 1
24
+ end
25
+
26
+ test "more" do
27
+ assert_equal 3, @value
28
+ end
29
+ end
30
+ end
31
+
32
+ context "some other context" do
33
+ setup do
34
+ @value += 1
35
+ end
36
+
37
+ test "yet another truth" do
38
+ assert_equal 2, @value
39
+ end
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: citrusbyte-contest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Damian Janowski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-16 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: damian.janowski@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/contest.rb
26
+ - README.markdown
27
+ - LICENSE
28
+ - Rakefile
29
+ - test/all_test.rb
30
+ has_rdoc: false
31
+ homepage: http://github.com/citrusbyte/contest
32
+ post_install_message:
33
+ rdoc_options: []
34
+
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ version:
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ requirements: []
50
+
51
+ rubyforge_project:
52
+ rubygems_version: 1.2.0
53
+ signing_key:
54
+ specification_version: 2
55
+ summary: Contexts for Test::Unit
56
+ test_files: []
57
+