Sha256: 5fc10ff82278e3820c8c86532ee75ffd07b34c9510d20f23fd47fde41034acab

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require 'rspec'
require 'rast/parameter_generator'
require 'rast/spec_dsl'

# Main DSL. This is the entry point of the test when running a spec.
class Rast
# RSpec All scenario test
#
# Example:
#   >> Hola.hi("spanish")
#   => hola mundo
#
# Arguments:
#   language: (String)

  alias global_spec spec

  def initialize(rasted_subject, &block)
    @subject = if rasted_subject.class == Module
                 Class.new { extend rasted_subject }
               else
                 rasted_subject.new
               end

    @subject_name = rasted_subject

    spec_path = caller[2][/spec.*?\.rb/]
    yaml_path = spec_path.gsub(/(\w+).rb/, 'rast/\\1.yml')

    @generator = ParameterGenerator.new(yaml_path: yaml_path)

    instance_eval(&block)
  end

  def self.assert(message)
    raise message unless yield
  end

  def spec(id, &block)
    global_spec(
      subject: @subject,
      name: @subject_name,
      fixtures: @generator.generate_fixtures(spec_id: id),
      spec_id: id,
      &block
    )
  end
end

# DSL Entry Point
def rast(rasted_subject, &block)
  Rast.new(rasted_subject, &block)
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rast-0.15.1 lib/rast.rb
rast-0.14.0 lib/rast.rb
rast-0.11.4 lib/rast.rb
rast-0.11.3 lib/rast.rb