test-unit-fasterskip 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,43 @@
1
+ Test::Unit::FasterSkip
2
+ ======================
3
+
4
+ This gem allows you to skip setup/teardown for tests that are omitted/pending.
5
+ If your setup method is very heavy-weight, this can save you a lot of time!
6
+
7
+ To use FasterSkip, just change this:
8
+
9
+ ```ruby
10
+ class MyTestCase < Test::Unit::TestCase
11
+ def test_cool_feature
12
+ pend('Bug #159: To be implemented.')
13
+ # TODO: Figure out how to test this.
14
+ end
15
+
16
+ def test_platform_specific_feature
17
+ omit_if(File::ALT_SEPARATOR, "Skipping test on Windows/VMS")
18
+ # ...
19
+ end
20
+ end
21
+ ```
22
+
23
+ To this:
24
+
25
+ ```ruby
26
+ require 'test-unit-fasterskip'
27
+ class MyTestCase < Test::Unit::TestCase
28
+ pend('Bug #159: To be implemented.')
29
+ def test_cool_feature
30
+ # TODO: Figure out how to test this.
31
+ end
32
+
33
+ omit_if("Skipping test on Windows/VMS") { File::ALT_SEPARATOR }
34
+ def test_platform_specific_feature
35
+ # ...
36
+ end
37
+ end
38
+ ```
39
+
40
+ Note that neither `setup` *nor* `teardown` will be run in these scenarios. You
41
+ can also call `omit_unless`, which negates the value of the boolean returned by
42
+ your block. Your `omit_if` block will be passed the current TestCase instance as
43
+ its first argument.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,52 @@
1
+ module Test::Unit
2
+ class TestCase
3
+ class << self
4
+ # Mark test as pending (and don't run setup/teardown)
5
+ def pend(message, *tests)
6
+ # We capture `caller` here so that we can give a better backtrace in
7
+ # #pending_setup.
8
+ attribute(:fast_pending, [caller, message], *tests)
9
+ end
10
+
11
+ # Omit (and don't run setup/teardown) if block evalutes to true.
12
+ def omit_if(message, *tests, &block)
13
+ attribute(:fast_omit, [caller, message, block], *tests)
14
+ end
15
+
16
+ # Sugar for omit_if() { not .. }
17
+ def omit_unless(message, *tests, &block)
18
+ attribute(:fast_omit, [caller, message, Proc.new { not block.call }], *tests)
19
+ end
20
+ end
21
+
22
+ setup :skipping_setup, :before => :prepend
23
+ # We pend/omit() before setup runs, so that we don't have to run the test's setup
24
+ # if we're skipping it.
25
+ def skipping_setup
26
+ @fast_skipped = false
27
+ bt = nil
28
+ begin
29
+ if self[:fast_pending]
30
+ bt, message = self[:fast_pending]
31
+ pend(message)
32
+ elsif self[:fast_omit]
33
+ bt, message, cond_block = self[:fast_omit]
34
+ omit_if(cond_block.call(self), message)
35
+ end
36
+ rescue PendedError, OmittedError => e
37
+ @fast_skipped = true
38
+ # We reset the backtrace to point to the line where the pend/omit call was
39
+ # originally made.
40
+ e.set_backtrace(bt) if bt
41
+ raise e
42
+ end
43
+ end
44
+
45
+ alias_method :run_teardown_original, :run_teardown
46
+ # We only run the #run_teardown if we're not skipping this test, since
47
+ # teardown probably assumes setup() was called.
48
+ def run_teardown(*args)
49
+ run_teardown_original(*args) unless @fast_skipped
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ require 'test-unit-fasterskip/version'
2
+
3
+ require 'ext/test/unit/testcase'
@@ -0,0 +1,7 @@
1
+ module Test
2
+ module Unit
3
+ module FasterSkip
4
+ VERSION = "0.0.2"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "test-unit-fasterskip/version"
4
+
5
+ # This is so that Jenkins builds increment version number.
6
+ gem_version = Test::Unit::FasterSkip::VERSION.dup
7
+ if ENV.has_key?('BUILD_NUMBER')
8
+ gem_version << ".#{ENV['BUILD_NUMBER']}"
9
+ end
10
+
11
+ Gem::Specification.new do |s|
12
+ s.name = "test-unit-fasterskip"
13
+ s.version = gem_version
14
+ s.authors = ["Jørgen P. Tjernø"]
15
+ s.email = ["jtjerno@mylookout.com"]
16
+ s.homepage = "https://github.com/jorgenpt/test-unit-fasterskip"
17
+ s.summary = %q{Add a class-level pend that skips setup/teardown}
18
+ s.description = %q{If you have very heavy-weight setup/teardown methods, this
19
+ gem allows you to mark tests as pending on a class level. This will skip
20
+ calling setup/teardown for that test, but still "pend" it like normal.}
21
+
22
+ s.rubyforge_project = "test-unit-fasterskip"
23
+
24
+ s.files = `git ls-files`.split("\n")
25
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
26
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
27
+ s.require_paths = ["lib"]
28
+
29
+ s.add_runtime_dependency "test-unit", ">= 2.4.0"
30
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: test-unit-fasterskip
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jørgen P. Tjernø
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-07 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: test-unit
16
+ requirement: &2152621640 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.4.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2152621640
25
+ description: ! "If you have very heavy-weight setup/teardown methods, this\n gem
26
+ allows you to mark tests as pending on a class level. This will skip\n calling
27
+ setup/teardown for that test, but still \"pend\" it like normal."
28
+ email:
29
+ - jtjerno@mylookout.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - Gemfile
36
+ - README.markdown
37
+ - Rakefile
38
+ - lib/ext/test/unit/testcase.rb
39
+ - lib/test-unit-fasterskip.rb
40
+ - lib/test-unit-fasterskip/version.rb
41
+ - test-unit-fasterskip.gemspec
42
+ homepage: https://github.com/jorgenpt/test-unit-fasterskip
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project: test-unit-fasterskip
62
+ rubygems_version: 1.8.11
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Add a class-level pend that skips setup/teardown
66
+ test_files: []