Class: Megatest::State::Suite
- Inherits:
-
Object
- Object
- Megatest::State::Suite
- Defined in:
- lib/megatest/state.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#around_callbacks ⇒ Object
readonly
Returns the value of attribute around_callbacks.
-
#setup_callbacks ⇒ Object
readonly
Returns the value of attribute setup_callbacks.
-
#teardown_callbacks ⇒ Object
readonly
Returns the value of attribute teardown_callbacks.
Instance Method Summary collapse
- #add_tags(tags) ⇒ Object
- #build_test_case(name, callable, tags, source_location) ⇒ Object
-
#initialize(registry) ⇒ Suite
constructor
A new instance of Suite.
- #on_around(block) ⇒ Object
- #on_setup(block) ⇒ Object
- #on_teardown(block) ⇒ Object
- #own_tags ⇒ Object
- #tag?(name) ⇒ Boolean
- #with_context(context, tags) ⇒ Object
Constructor Details
#initialize(registry) ⇒ Suite
Returns a new instance of Suite.
33 34 35 36 37 38 39 40 41 |
# File 'lib/megatest/state.rb', line 33 def initialize(registry) @registry = registry @tags = nil @setup_callbacks = [] @teardown_callbacks = [] @around_callbacks = [] @current_context = nil @current_tags = nil end |
Instance Attribute Details
#around_callbacks ⇒ Object (readonly)
Returns the value of attribute around_callbacks.
31 32 33 |
# File 'lib/megatest/state.rb', line 31 def around_callbacks @around_callbacks end |
#setup_callbacks ⇒ Object (readonly)
Returns the value of attribute setup_callbacks.
31 32 33 |
# File 'lib/megatest/state.rb', line 31 def setup_callbacks @setup_callbacks end |
#teardown_callbacks ⇒ Object (readonly)
Returns the value of attribute teardown_callbacks.
31 32 33 |
# File 'lib/megatest/state.rb', line 31 def teardown_callbacks @teardown_callbacks end |
Instance Method Details
#add_tags(tags) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/megatest/state.rb', line 60 def () return if .empty? @tags ||= {} @tags.merge!() end |
#build_test_case(name, callable, tags, source_location) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/megatest/state.rb', line 75 def build_test_case(name, callable, , source_location) name = [*@current_context, name].join(" ") = if @current_tags ? @current_tags.merge() : else @current_tags end if callable.is_a?(UnboundMethod) MethodTest.new(self, @klass, name, callable, , source_location) else BlockTest.new(self, @klass, name, callable, , source_location) end end |
#on_around(block) ⇒ Object
95 96 97 98 99 |
# File 'lib/megatest/state.rb', line 95 def on_around(block) raise Error, "around blocks can't be defined in context blocks" if @current_context @around_callbacks << block end |
#on_setup(block) ⇒ Object
89 90 91 92 93 |
# File 'lib/megatest/state.rb', line 89 def on_setup(block) raise Error, "setup blocks can't be defined in context blocks" if @current_context @setup_callbacks << block end |
#on_teardown(block) ⇒ Object
101 102 103 104 105 |
# File 'lib/megatest/state.rb', line 101 def on_teardown(block) raise Error, "teardown blocks can't be defined in context blocks" if @current_context @teardown_callbacks << block end |
#own_tags ⇒ Object
71 72 73 |
# File 'lib/megatest/state.rb', line 71 def @tags end |
#tag?(name) ⇒ Boolean
67 68 69 |
# File 'lib/megatest/state.rb', line 67 def tag?(name) @tags&.key?(name) end |
#with_context(context, tags) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/megatest/state.rb', line 43 def with_context(context, ) previous_context = @current_context @current_context = [@current_context, context].compact.join(" ") = @current_tags if @current_tags = @current_tags ? @current_tags.merge() : end begin yield ensure @current_context = previous_context @current_tags = end end |