Class: Fix::Dsl Private
- Inherits:
-
Object
- Object
- Fix::Dsl
- Extended by:
- Matcher, Requirement
- Defined in:
- lib/fix/dsl.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Abstract class for handling the domain-specific language.
Class Method Summary collapse
-
.challenges ⇒ Array<Defi::Method>
private
The list of challenges to be addressed to the object to be tested.
-
.it(requirement = nil) { ... } ⇒ Symbol
Defines a concrete spec definition.
-
.let(name) { ... } ⇒ Symbol
Sets a user-defined property.
-
.on(method_name, *args, **kwargs) { ... } ⇒ Class
Defines an example group that describes a unit to be tested.
-
.with(**kwargs) { ... } ⇒ Class
Defines an example group with user-defined properties that describes a unit to be tested.
Methods included from Requirement
MAY, MUST, MUST_NOT, SHOULD, SHOULD_NOT
Class Method Details
.challenges ⇒ Array<Defi::Method>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The list of challenges to be addressed to the object to be tested.
135 136 137 |
# File 'lib/fix/dsl.rb', line 135 def self.challenges [] end |
.it(requirement = nil) { ... } ⇒ Symbol
Defines a concrete spec definition.
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/fix/dsl.rb', line 119 def self.it(requirement = nil, &block) raise ::ArgumentError, "Must provide either requirement or block, not both" if requirement && block raise ::ArgumentError, "Must provide either requirement or block" unless requirement || block location = caller_locations(1, 1).fetch(0) location = [location.path, location.lineno].join(":") test_method_name = :"test_#{(requirement || block).object_id}" define_method(test_method_name) do [location, requirement || singleton_class.class_eval(&block), self.class.challenges] end end |
.let(name) { ... } ⇒ Symbol
Sets a user-defined property.
32 33 34 |
# File 'lib/fix/dsl.rb', line 32 def self.let(name, &) private define_method(name, &) end |
.on(method_name, *args, **kwargs) { ... } ⇒ Class
Defines an example group that describes a unit to be tested.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/fix/dsl.rb', line 83 def self.on(method_name, *args, **kwargs, &block) klass = ::Class.new(self) klass.const_get(:CONTEXTS) << klass const_name = :"MethodContext_#{block.object_id}" const_set(const_name, klass) klass.define_singleton_method(:challenges) do challenge = ::Defi::Method.new(method_name, *args, **kwargs) super() + [challenge] end klass.instance_eval(&block) klass end |
.with(**kwargs) { ... } ⇒ Class
Defines an example group with user-defined properties that describes a unit to be tested.
55 56 57 58 59 60 61 |
# File 'lib/fix/dsl.rb', line 55 def self.with(**kwargs, &) klass = ::Class.new(self) klass.const_get(:CONTEXTS) << klass kwargs.each { |name, value| klass.let(name) { value } } klass.instance_eval(&) klass end |