Class: Hecks::Behaviors::BehaviorsBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/hecks/behaviors/dsl.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, source_path:) ⇒ BehaviorsBuilder

Returns a new instance of BehaviorsBuilder.



51
52
53
54
55
56
57
58
# File 'lib/hecks/behaviors/dsl.rb', line 51

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



89
90
91
92
93
# File 'lib/hecks/behaviors/dsl.rb', line 89

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

#buildObject



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/hecks/behaviors/dsl.rb', line 75

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.



65
66
67
# File 'lib/hecks/behaviors/dsl.rb', line 65

def loads(*paths)
  @loads = paths.map { |path| File.expand_path(path, @source_dir) }
end

#test(description, &block) ⇒ Object



69
70
71
72
73
# File 'lib/hecks/behaviors/dsl.rb', line 69

def test(description, &block)
  builder = TestCaseBuilder.new(description)
  builder.instance_eval(&block) if block
  @tests << builder.build
end

#vision(text) ⇒ Object



60
# File 'lib/hecks/behaviors/dsl.rb', line 60

def vision(text) = @vision = text