mynyml-phocus 0.9.4 → 0.9.8

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/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/README CHANGED
@@ -0,0 +1,95 @@
1
+ ==== Intro
2
+
3
+ Phocus let's you temporarily focus some tests, ignoring all others, even across test classes.
4
+
5
+ ==== Examples
6
+
7
+ require 'test/unit'
8
+ require 'phocus/test_unit'
9
+
10
+ class TestUser < Test::Unit::TestCase
11
+
12
+ focus
13
+ def test_foo
14
+ assert User.authenticate('...')
15
+ end
16
+
17
+ def test_bar
18
+ assert User.do_something_else
19
+ end
20
+ end
21
+
22
+ class TestAcmeWidget < Test::Unit::TestCase
23
+
24
+ def test_abc
25
+ assert true
26
+ end
27
+
28
+ focus
29
+ def test_xyz
30
+ assert true
31
+ end
32
+ end
33
+
34
+ Executing these tests (say with <tt>rake test</tt> or <tt>autotest</tt>), will
35
+ only run <tt>test_foo</tt> and <tt>test_xyz</tt>.
36
+
37
+ Also works fine with <tt>test "description"</tt> style tests.
38
+
39
+ focus
40
+ test "abc" do
41
+ assert true
42
+ end
43
+
44
+ ==== Phocus Vs. Editor
45
+
46
+ "Dude, MY editor already does that! Just get a real editor!!1!"
47
+
48
+ Actually, so does my editor. But I've found that in many situations, it was far
49
+ from enough.
50
+
51
+ Contexts:
52
+ Some frameworks like shoulda, context and contest allow you to embed tests
53
+ within context blocks, which throws off the editor's "run a single test"
54
+ funtionality, since they expand the test method names.
55
+
56
+ Debugging:
57
+ Some editors will even allow you to step into the code when using
58
+ <tt>debugger</tt> within that single test, but it's usually not as convenient
59
+ as the console.
60
+
61
+ Multiple Tests:
62
+ Phocus allows focusing more than one tests.
63
+
64
+ ==== Other Testing Frameworks
65
+
66
+ Phocus is compatible with various testing frameworks. To use with your
67
+ framework of choice, simply require the right compatibility file:
68
+
69
+ require 'phocus/test_unit'
70
+ require 'phocus/minitest'
71
+ require 'phocus/shoulda'
72
+ require 'phocus/context'
73
+ require 'phocus/contest'
74
+
75
+ It is likely to be compatible with other frameworks as well, but these are the
76
+ ones that have been verified to work and that are automatically set up.
77
+
78
+ In case you're wondering,
79
+
80
+ require 'phocus'
81
+
82
+ is the standalone phocus functionality. You can require it directly, but you'll
83
+ have to set it up (which pretty much just means setting the right
84
+ Phocus.method_pattern for your test framework and including the mixin). You
85
+ really don't need to bother though, that work has been taken care of for you if
86
+ you <tt>require 'phocus/...'</tt> directly. Though it will be useful if you're
87
+ trying to get Phocus working with another framework. Refer to the rdocs in this
88
+ case (or better yet, you can read the source; it's < 50 LOCs)
89
+
90
+ ==== Links
91
+ source:: http://github.com/mynyml/phocus
92
+ rdocs:: http://docs.github.com/mynyml/phocus
93
+
94
+ ==== License
95
+ MIT. See LICENSE file.
data/Rakefile CHANGED
@@ -22,7 +22,7 @@ end
22
22
 
23
23
  spec = Gem::Specification.new do |s|
24
24
  s.name = 'phocus'
25
- s.version = '0.9.4'
25
+ s.version = '0.9.8'
26
26
  s.summary = "Run focused tests on test/unit."
27
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
28
  s.author = "Martin Aumont"
@@ -33,6 +33,16 @@ spec = Gem::Specification.new do |s|
33
33
  s.files = all_except([/doc/, /pkg/])
34
34
  end
35
35
 
36
+ desc "Generate rdoc documentation."
37
+ Rake::RDocTask.new("rdoc") { |rdoc|
38
+ rdoc.rdoc_dir = 'doc/rdoc'
39
+ rdoc.title = "Phocus"
40
+ rdoc.options << '--line-numbers' << '--inline-source'
41
+ rdoc.options << '--charset' << 'utf-8'
42
+ rdoc.rdoc_files.include('README')
43
+ rdoc.rdoc_files.include('lib/**/*.rb')
44
+ }
45
+
36
46
  Rake::GemPackageTask.new(spec) do |p|
37
47
  p.gem_spec = spec
38
48
  end
@@ -54,13 +64,3 @@ desc "Uninstall gem"
54
64
  task :uninstall => :clean do
55
65
  sh "#{SUDO} #{gem} uninstall -v #{spec.version} -x #{spec.name}"
56
66
  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
- }
@@ -4,8 +4,10 @@ require 'contest'
4
4
  root = Pathname(__FILE__).dirname.parent.parent.expand_path
5
5
  require root + 'lib/phocus'
6
6
 
7
- class Test::Unit::TestCase
8
- include ::Phocus
7
+ module Test #:nodoc: all
8
+ class Unit::TestCase
9
+ include ::Phocus
10
+ end
9
11
  end
10
12
 
11
13
  Phocus.method_pattern = /^test_/
@@ -4,8 +4,10 @@ require 'context'
4
4
  root = Pathname(__FILE__).dirname.parent.parent.expand_path
5
5
  require root + 'lib/phocus'
6
6
 
7
- class Test::Unit::TestCase
8
- include ::Phocus
7
+ module Test #:nodoc: all
8
+ class Unit::TestCase
9
+ include ::Phocus
10
+ end
9
11
  end
10
12
 
11
13
  Phocus.method_pattern = /test:/
@@ -4,8 +4,10 @@ require 'minitest/unit'
4
4
  root = Pathname(__FILE__).dirname.parent.parent.expand_path
5
5
  require root + 'lib/phocus'
6
6
 
7
- class MiniTest::Unit::TestCase
8
- include ::Phocus
7
+ module MiniTest #:nodoc: all
8
+ class Unit::TestCase
9
+ include ::Phocus
10
+ end
9
11
  end
10
12
 
11
13
  Phocus.method_pattern = /^test_/
@@ -5,14 +5,18 @@ require 'shoulda'
5
5
  root = Pathname(__FILE__).dirname.parent.parent.expand_path
6
6
  require root + 'lib/phocus'
7
7
 
8
- class Test::Unit::TestCase
9
- include ::Phocus
8
+ module Test #:nodoc: all
9
+ class Unit::TestCase
10
+ include ::Phocus
11
+ end
10
12
  end
11
13
 
12
- class Test::Unit::TestSuite
13
- # TODO only override when @@__focused
14
- def empty?
15
- false
14
+ module Test #:nodoc: all
15
+ class Unit::TestSuite
16
+ # TODO only override when @@__focused
17
+ def empty?
18
+ false
19
+ end
16
20
  end
17
21
  end
18
22
 
@@ -4,14 +4,18 @@ require 'test/unit'
4
4
  root = Pathname(__FILE__).dirname.parent.parent.expand_path
5
5
  require root + 'lib/phocus'
6
6
 
7
- class Test::Unit::TestCase
8
- include ::Phocus
7
+ module Test #:nodoc: all
8
+ class Unit::TestCase
9
+ include ::Phocus
10
+ end
9
11
  end
10
12
 
11
- class Test::Unit::TestSuite
12
- # TODO only override when @@__focused
13
- def empty?
14
- false
13
+ module Test #:nodoc: all
14
+ class Unit::TestSuite
15
+ # TODO only override when @@__focused
16
+ def empty?
17
+ false
18
+ end
15
19
  end
16
20
  end
17
21
 
data/lib/phocus.rb CHANGED
@@ -1,13 +1,74 @@
1
+ # Phocus let's you single out selected methods out of a defined group of methods.
2
+ #
3
+ # It is intended to be used to focus one or more tests in a test suite,
4
+ # although it is generic enough that it could conceivably be used in other
5
+ # circumstances as well.
6
+ #
7
+ # Use the <tt>focus</tt> statement right before defining your test method.
8
+ #
9
+ # ===== Examples
10
+ # require 'test/unit'
11
+ # require 'phocus'
12
+ #
13
+ # Phocus.method_pattern = /^test_/
14
+ #
15
+ # class TestUser < Test::Unit::TestCase
16
+ # include Phocus
17
+ #
18
+ # focus
19
+ # def test_foo
20
+ # assert true
21
+ # end
22
+ #
23
+ # def test_bar
24
+ # flunk "not focused"
25
+ # end
26
+ # end
27
+ #
28
+ # When executed, only test_foo will be run. Can also be used on more than one
29
+ # methods.
30
+ #
31
+ # Phocus also let's you focus methods across classes, which is almost always
32
+ # the desired behaviour. Simply include the mixin in the parent class. In the
33
+ # case of test/unit and test/unit based testing frameworks, this means:
34
+ #
35
+ # class Test::Unit::TestCase
36
+ # include Phocus
37
+ # end
38
+ #
39
+ # Now focusing will work across *all* your tests. Not much benifit if you run
40
+ # your test files individually, but indispensable when using <tt>rake test</tt>
41
+ # or autotest.
42
+ #
1
43
  module Phocus
2
44
  class << self
3
45
  attr_accessor :method_pattern
4
46
 
47
+ # Specify a pattern that identifies the names of the group of methods
48
+ # focusing will apply to.
49
+ #
50
+ # For example, when using test/unit, you want the relevant group of methods
51
+ # to be your test methods, which are the ones starting with <tt>test_</tt>.
52
+ #
53
+ # Phocus.method_pattern = /^test_/
54
+ #
55
+ # (which happens to be the default pattern)
56
+ #
57
+ # On the other hand, context (http://github.com/jeremymcanally/context),
58
+ # has test methods starting with <tt>test:</tt>, so you can specify:
59
+ #
60
+ # Phocus.method_pattern = /^test:/
61
+ #
62
+ # In reality, it's not so much that Phocus focuses on certain methods, but
63
+ # rather it ignores others. Since we don't want to ignore helper methods
64
+ # (setup, teardown, custom helpers, etc.), we must restrict the scope of
65
+ # ignored methods, which is what <tt>method_pattern</tt> allows us to do.
5
66
  def method_pattern
6
67
  @method_pattern || /^test_/
7
68
  end
8
69
  end
9
70
 
10
- def self.included(base)
71
+ def self.included(base) #:nodoc:
11
72
  base.extend ClassMethods
12
73
  end
13
74
 
@@ -16,19 +77,28 @@ module Phocus
16
77
  @@__focused = false
17
78
  @@__focus_next = false
18
79
 
19
- def focused
80
+ # Use right before defining a method to focus it.
81
+ def focus
20
82
  unless @@__focused
21
83
  clear_test_methods!
22
84
  @@__focused = true
23
85
  end
24
86
  @@__focus_next = true
25
87
  end
26
- alias :focus :focused
27
- alias :phocus :focused
88
+ # :stopdoc:
89
+ alias :focused :focus
90
+ alias :phocus :focus
91
+ # :startdoc:
28
92
 
29
- def method_added(name)
93
+ # If the method belongs to target group (method_pattern), then remove it
94
+ # unless it is focused.
95
+ #
96
+ # we don't want any methods removed if focus is never used, so until it is,
97
+ # keep a reference to methods being defined so that we can come back and
98
+ # remove them later.
99
+ #
100
+ def method_added(name) #:nodoc:
30
101
  super
31
- #if name.to_s.match(/^test/)
32
102
  if name.to_s.match(Phocus.method_pattern)
33
103
  if @@__focused
34
104
  @@__focus_next ? @@__focus_next = false : remove_method(name)
data/phocus.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phocus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Aumont
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-28 00:00:00 -04:00
12
+ date: 2009-05-29 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -43,6 +43,7 @@ files:
43
43
  - lib/phocus/test_unit.rb
44
44
  - lib/phocus.rb
45
45
  - phocus.gemspec
46
+ - LICENSE
46
47
  - README
47
48
  has_rdoc: true
48
49
  homepage: ""
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mynyml-phocus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Aumont
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-27 21:00:00 -07:00
12
+ date: 2009-05-28 21:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -43,6 +43,7 @@ files:
43
43
  - lib/phocus/test_unit.rb
44
44
  - lib/phocus.rb
45
45
  - phocus.gemspec
46
+ - LICENSE
46
47
  - README
47
48
  has_rdoc: true
48
49
  homepage: ""