mynyml-phocus 0.5
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/README +0 -0
- data/Rakefile +66 -0
- data/TODO +8 -0
- data/lib/phocus.rb +40 -0
- data/test/test_helper.rb +29 -0
- data/test/test_phocus.rb +110 -0
- metadata +60 -0
data/README
ADDED
|
File without changes
|
data/Rakefile
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# --------------------------------------------------
|
|
2
|
+
# based on thin's Rakefile (http://github.com/macournoyer/thin)
|
|
3
|
+
# --------------------------------------------------
|
|
4
|
+
require 'rake/gempackagetask'
|
|
5
|
+
require 'rake/rdoctask'
|
|
6
|
+
require 'pathname'
|
|
7
|
+
require 'yaml'
|
|
8
|
+
|
|
9
|
+
RUBY_1_9 = RUBY_VERSION =~ /^1\.9/
|
|
10
|
+
WIN = (RUBY_PLATFORM =~ /mswin|cygwin/)
|
|
11
|
+
SUDO = (WIN ? "" : "sudo")
|
|
12
|
+
|
|
13
|
+
def gem
|
|
14
|
+
RUBY_1_9 ? 'gem19' : 'gem'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def all_except(res)
|
|
18
|
+
Dir['**/*'].reject do |path|
|
|
19
|
+
Array(res).any? {|re| path.match(re) }
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
spec = Gem::Specification.new do |s|
|
|
24
|
+
s.name = 'phocus'
|
|
25
|
+
s.version = '0.5'
|
|
26
|
+
s.summary = "Run focused tests on test/unit."
|
|
27
|
+
s.description = "Tell test/unit exactly which tests you want run. It will ignore all the other ones and let you concentrate on a few."
|
|
28
|
+
s.author = "Martin Aumont"
|
|
29
|
+
s.email = 'mynyml@gmail.com'
|
|
30
|
+
s.homepage = ''
|
|
31
|
+
s.has_rdoc = true
|
|
32
|
+
s.require_path = "lib"
|
|
33
|
+
s.files = all_except([/doc/, /pkg/])
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
Rake::GemPackageTask.new(spec) do |p|
|
|
37
|
+
p.gem_spec = spec
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
desc "Remove package products"
|
|
41
|
+
task :clean => :clobber_package
|
|
42
|
+
|
|
43
|
+
desc "Update the gemspec for GitHub's gem server"
|
|
44
|
+
task :gemspec do
|
|
45
|
+
Pathname("#{spec.name}.gemspec").open('w') {|f| f << YAML.dump(spec) }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
desc "Install gem"
|
|
49
|
+
task :install => [:clobber, :package] do
|
|
50
|
+
sh "#{SUDO} #{gem} install pkg/#{spec.full_name}.gem"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
desc "Uninstall gem"
|
|
54
|
+
task :uninstall => :clean do
|
|
55
|
+
sh "#{SUDO} #{gem} uninstall -v #{spec.version} -x #{spec.name}"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
desc "Generate rdoc documentation."
|
|
59
|
+
Rake::RDocTask.new("rdoc") { |rdoc|
|
|
60
|
+
rdoc.rdoc_dir = 'doc/rdoc'
|
|
61
|
+
rdoc.title = "Simple Router - Document"
|
|
62
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
|
63
|
+
rdoc.options << '--charset' << 'utf-8'
|
|
64
|
+
rdoc.rdoc_files.include('README')
|
|
65
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
66
|
+
}
|
data/TODO
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
o test (implement?) compatibility with test/unit plugins
|
|
2
|
+
- context, shoulda, test/spec, contess, etc.
|
|
3
|
+
|
|
4
|
+
o handle errors when a TestCase doesn't define any test method
|
|
5
|
+
`def default_test() end` works, but test count should not go up
|
|
6
|
+
|
|
7
|
+
o add docs
|
|
8
|
+
- rdocs, README
|
data/lib/phocus.rb
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module Phocus
|
|
2
|
+
def self.included(base)
|
|
3
|
+
base.extend ClassMethods
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
module ClassMethods
|
|
7
|
+
@@__test_methods = {}
|
|
8
|
+
@@__focused = false
|
|
9
|
+
@@__focus_next = false
|
|
10
|
+
|
|
11
|
+
def focused
|
|
12
|
+
unless @@__focused
|
|
13
|
+
clear_test_methods!
|
|
14
|
+
@@__focused = true
|
|
15
|
+
end
|
|
16
|
+
@@__focus_next = true
|
|
17
|
+
end
|
|
18
|
+
alias :focus :focused
|
|
19
|
+
alias :phocus :focused
|
|
20
|
+
|
|
21
|
+
def method_added(name)
|
|
22
|
+
super
|
|
23
|
+
if name.to_s.match(/^test_/)
|
|
24
|
+
if @@__focused
|
|
25
|
+
@@__focus_next ? @@__focus_next = false : remove_method(name)
|
|
26
|
+
else
|
|
27
|
+
@@__test_methods[self] ||= []
|
|
28
|
+
@@__test_methods[self] << name
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
def clear_test_methods!
|
|
35
|
+
@@__test_methods.each do |klass, method_names|
|
|
36
|
+
method_names.each {|name| klass.class_eval { remove_method(name) } }
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'pathname'
|
|
2
|
+
require 'set'
|
|
3
|
+
require 'rubygems'
|
|
4
|
+
begin
|
|
5
|
+
require 'ruby-debug'
|
|
6
|
+
rescue LoadError, RuntimeError
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
root = Pathname(__FILE__).dirname.parent.expand_path
|
|
10
|
+
require root.join('lib/phocus')
|
|
11
|
+
|
|
12
|
+
class Object
|
|
13
|
+
def self.metaclass
|
|
14
|
+
(class << self; self; end)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def reset_phocused_classes(*classes)
|
|
19
|
+
Array(classes).flatten.each do |klass|
|
|
20
|
+
klass.metaclass.class_eval do
|
|
21
|
+
class_variable_set(:@@__focused, false )
|
|
22
|
+
class_variable_set(:@@__focus_next, false )
|
|
23
|
+
class_variable_set(:@@__test_methods, {} )
|
|
24
|
+
end
|
|
25
|
+
klass.class_eval do
|
|
26
|
+
instance_methods(false).each {|name| remove_method(name) }
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/test/test_phocus.rb
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
require 'test/test_helper'
|
|
2
|
+
require 'expectations'
|
|
3
|
+
|
|
4
|
+
class TestCase
|
|
5
|
+
include Phocus
|
|
6
|
+
end
|
|
7
|
+
class TestA < TestCase; end
|
|
8
|
+
class TestB < TestCase; end
|
|
9
|
+
|
|
10
|
+
def reset
|
|
11
|
+
reset_phocused_classes(TestA, TestB)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
Expectations do
|
|
15
|
+
|
|
16
|
+
## api
|
|
17
|
+
|
|
18
|
+
expect true do
|
|
19
|
+
reset
|
|
20
|
+
TestA.respond_to?(:focus) &&
|
|
21
|
+
TestA.respond_to?(:focused) &&
|
|
22
|
+
TestA.respond_to?(:phocus)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
## focused tests
|
|
26
|
+
|
|
27
|
+
# only keeps focused method
|
|
28
|
+
expect %w( test_foo ) do
|
|
29
|
+
reset
|
|
30
|
+
class TestA
|
|
31
|
+
focus
|
|
32
|
+
def test_foo() end
|
|
33
|
+
def test_bar() end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
TestA.instance_methods(false)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# keeps more than one focused methods
|
|
40
|
+
expect %w( test_foo test_bar ).to_set do
|
|
41
|
+
reset
|
|
42
|
+
class TestA
|
|
43
|
+
focus
|
|
44
|
+
def test_foo() end
|
|
45
|
+
focus
|
|
46
|
+
def test_bar() end
|
|
47
|
+
def test_baz() end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
TestA.instance_methods(false).to_set
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# focuses across subclasses
|
|
54
|
+
expect %w( test_foo ).to_set do
|
|
55
|
+
reset
|
|
56
|
+
class TestA
|
|
57
|
+
focus
|
|
58
|
+
def test_foo() end
|
|
59
|
+
def test_bar() end
|
|
60
|
+
end
|
|
61
|
+
class TestB
|
|
62
|
+
def test_abc() end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
TestA.instance_methods(false).to_set +
|
|
66
|
+
TestB.instance_methods(false).to_set
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# focuses more than one methods across subclasses
|
|
70
|
+
expect %w( test_foo test_def ).to_set do
|
|
71
|
+
reset
|
|
72
|
+
class TestA
|
|
73
|
+
focus
|
|
74
|
+
def test_foo() end
|
|
75
|
+
def test_bar() end
|
|
76
|
+
end
|
|
77
|
+
class TestB
|
|
78
|
+
def test_abc() end
|
|
79
|
+
focus
|
|
80
|
+
def test_def() end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
TestA.instance_methods(false).to_set +
|
|
84
|
+
TestB.instance_methods(false).to_set
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# non-test methods aren't touched
|
|
88
|
+
expect %w( test_foo helper ).to_set do
|
|
89
|
+
reset
|
|
90
|
+
class TestA
|
|
91
|
+
focus
|
|
92
|
+
def test_foo() end
|
|
93
|
+
def test_bar() end
|
|
94
|
+
def helper() end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
TestA.instance_methods(false).to_set
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# test methods don't get removed if nothing is focused (control test)
|
|
101
|
+
expect %w( test_foo test_bar ).to_set do
|
|
102
|
+
reset
|
|
103
|
+
class TestA
|
|
104
|
+
def test_foo() end
|
|
105
|
+
def test_bar() end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
TestA.instance_methods(false).to_set
|
|
109
|
+
end
|
|
110
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: mynyml-phocus
|
|
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-05-27 21:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: Tell test/unit exactly which tests you want run. It will ignore all the other ones and let you concentrate on a few.
|
|
17
|
+
email: mynyml@gmail.com
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files: []
|
|
23
|
+
|
|
24
|
+
files:
|
|
25
|
+
- Rakefile
|
|
26
|
+
- test
|
|
27
|
+
- test/test_phocus.rb
|
|
28
|
+
- test/test_helper.rb
|
|
29
|
+
- TODO
|
|
30
|
+
- lib
|
|
31
|
+
- lib/phocus.rb
|
|
32
|
+
- README
|
|
33
|
+
has_rdoc: true
|
|
34
|
+
homepage: ""
|
|
35
|
+
post_install_message:
|
|
36
|
+
rdoc_options: []
|
|
37
|
+
|
|
38
|
+
require_paths:
|
|
39
|
+
- lib
|
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
41
|
+
requirements:
|
|
42
|
+
- - ">="
|
|
43
|
+
- !ruby/object:Gem::Version
|
|
44
|
+
version: "0"
|
|
45
|
+
version:
|
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
|
+
requirements:
|
|
48
|
+
- - ">="
|
|
49
|
+
- !ruby/object:Gem::Version
|
|
50
|
+
version: "0"
|
|
51
|
+
version:
|
|
52
|
+
requirements: []
|
|
53
|
+
|
|
54
|
+
rubyforge_project:
|
|
55
|
+
rubygems_version: 1.2.0
|
|
56
|
+
signing_key:
|
|
57
|
+
specification_version: 3
|
|
58
|
+
summary: Run focused tests on test/unit.
|
|
59
|
+
test_files: []
|
|
60
|
+
|