Module: Phocus
- Defined in:
- lib/phocus.rb
Overview
Phocus let’s you single out selected methods out of a defined group of methods.
It is intended to be used to focus one or more tests in a test suite, although it is generic enough that it could conceivably be used in other circumstances as well.
Use the focus statement right before defining your test method.
Examples
require 'test/unit'
require 'phocus'
Phocus.method_pattern = /^test_/
class TestUser < Test::Unit::TestCase
include Phocus
focus
def test_foo
assert true
end
def
flunk "not focused"
end
end
When executed, only test_foo will be run. Can also be used on more than one methods.
Phocus also let’s you focus methods across classes, which is almost always the desired behaviour. Simply include the mixin in the parent class. In the case of test/unit and test/unit based testing frameworks, this means:
class Test::Unit::TestCase
include Phocus
end
Now focusing will work across all your tests. Not much benifit if you run your test files individually, but indispensable when using rake test or autotest.
Defined Under Namespace
Modules: ClassMethods
Class Attribute Summary collapse
-
.method_pattern ⇒ Object
Specify a pattern that identifies the names of the group of methods focusing will apply to.
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Class Attribute Details
.method_pattern ⇒ Object
Specify a pattern that identifies the names of the group of methods focusing will apply to.
For example, when using test/unit, you want the relevant group of methods to be your test methods, which are the ones starting with test_.
Phocus.method_pattern = /^test_/
(which happens to be the default pattern)
On the other hand, context (github.com/jeremymcanally/context), has test methods starting with test:, so you can specify:
Phocus.method_pattern = /^test:/
In reality, it’s not so much that Phocus focuses on certain methods, but rather it ignores others. Since we don’t want to ignore helper methods (setup, teardown, custom helpers, etc.), we must restrict the scope of ignored methods, which is what method_pattern allows us to do.
67 68 69 |
# File 'lib/phocus.rb', line 67 def method_pattern @method_pattern end |
Class Method Details
.included(base) ⇒ Object
:nodoc:
72 73 74 |
# File 'lib/phocus.rb', line 72 def self.included(base) #:nodoc: base.extend ClassMethods end |