Class: Megatest::State::Suite
- Inherits:
-
Object
- Object
- Megatest::State::Suite
- Defined in:
- lib/megatest/state.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#around_callback ⇒ Object
readonly
Returns the value of attribute around_callback.
-
#setup_callback ⇒ Object
readonly
Returns the value of attribute setup_callback.
-
#teardown_callback ⇒ Object
readonly
Returns the value of attribute teardown_callback.
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_callback = nil @teardown_callback = nil @around_callback = nil @current_context = nil @current_tags = nil end |
Instance Attribute Details
#around_callback ⇒ Object (readonly)
Returns the value of attribute around_callback.
31 32 33 |
# File 'lib/megatest/state.rb', line 31 def around_callback @around_callback end |
#setup_callback ⇒ Object (readonly)
Returns the value of attribute setup_callback.
31 32 33 |
# File 'lib/megatest/state.rb', line 31 def setup_callback @setup_callback end |
#teardown_callback ⇒ Object (readonly)
Returns the value of attribute teardown_callback.
31 32 33 |
# File 'lib/megatest/state.rb', line 31 def teardown_callback @teardown_callback 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
96 97 98 99 100 101 |
# File 'lib/megatest/state.rb', line 96 def on_around(block) raise Error, "The around block is already defined" if @around_callback raise Error, "around blocks can't be defined in context blocks" if @current_context @around_callback = block end |
#on_setup(block) ⇒ Object
89 90 91 92 93 94 |
# File 'lib/megatest/state.rb', line 89 def on_setup(block) raise Error, "The setup block is already defined" if @setup_callback raise Error, "setup blocks can't be defined in context blocks" if @current_context @setup_callback = block end |
#on_teardown(block) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/megatest/state.rb', line 103 def on_teardown(block) raise Error, "The teardown block is already defined" if @teardown_callback raise Error, "teardown blocks can't be defined in context blocks" if @current_context @teardown_callback = 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 |