Class: Hecks::Behaviors::BehaviorsBuilder
- Inherits:
-
Object
- Object
- Hecks::Behaviors::BehaviorsBuilder
- Defined in:
- lib/hecks/behaviors/dsl.rb
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(name, source_path:) ⇒ BehaviorsBuilder
constructor
A new instance of BehaviorsBuilder.
-
#loads(*paths) ⇒ Object
Relative to THIS
.behaviorsfile, never to the filesystem's cwd or a same-stem convention — scope is a fact this file declares, not one a runner infers. - #test(description, &block) ⇒ Object
- #vision(text) ⇒ Object
Constructor Details
#initialize(name, source_path:) ⇒ BehaviorsBuilder
Returns a new instance of BehaviorsBuilder.
80 81 82 83 84 85 86 87 |
# File 'lib/hecks/behaviors/dsl.rb', line 80 def initialize(name, source_path:) @name = name @source_path = source_path @source_dir = File.dirname(source_path) @vision = nil @loads = nil @tests = [] end |
Class Method Details
.build(name, source_path:, &block) ⇒ Object
118 119 120 121 122 |
# File 'lib/hecks/behaviors/dsl.rb', line 118 def self.build(name, source_path:, &block) builder = new(name, source_path: source_path) builder.instance_eval(&block) if block builder.build end |
Instance Method Details
#build ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/hecks/behaviors/dsl.rb', line 104 def build unless @vision raise Malformed, "#{@source_path}: no `vision \"...\"` — say in one line " \ "what this suite is examples of" end unless @loads raise Malformed, "#{@source_path}: no `loads \"...\"` — a behaviors file " \ "must declare exactly which files to boot" end BehaviorsSuite.new(name: @name, vision: @vision, loads: @loads, tests: @tests, path: @source_path) end |
#loads(*paths) ⇒ Object
Relative to THIS .behaviors file, never to the filesystem's cwd
or a same-stem convention — scope is a fact this file declares,
not one a runner infers.
94 95 96 |
# File 'lib/hecks/behaviors/dsl.rb', line 94 def loads(*paths) @loads = paths.map { |path| File.(path, @source_dir) } end |
#test(description, &block) ⇒ Object
98 99 100 101 102 |
# File 'lib/hecks/behaviors/dsl.rb', line 98 def test(description, &block) builder = TestCaseBuilder.new(description) builder.instance_eval(&block) if block @tests << builder.build end |
#vision(text) ⇒ Object
89 |
# File 'lib/hecks/behaviors/dsl.rb', line 89 def vision(text) = @vision = text |