Sha256: 8ce8d9b458d42620addc9db029c434502827efb66afa842d7492ead3172370b6

Contents?: true

Size: 1.65 KB

Versions: 11

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

# DSL module:
# * expect_none
# * expect_one
# * expect_any
# * expect
# * expect2
# * weight
module DSL
  def expect_none(input)
    if input.class == Array
      input.each { |i| result.find(i) }
    else
      result.find(input)
    end
    expect2 result.count.eq(0)
  end

  def expect_one(input)
    if input.class == Array
      input.each { |i| result.find(i) }
    else
      result.find(input)
    end
    expect2 result.count.eq(1)
  end

  def expect_any(input)
    if input.class == Array
      input.each { |i| result.find(i) }
    else
      result.find(input)
    end
    expect2 result.count.gt(0)
  end

  # expect <condition>, :weight => <value>
  def expect(input, args = {})
    if input.class == TrueClass || input.class == FalseClass
      expect2(input, args)
    elsif input.class == String || input.class == Regexp || input.class == Array
      expect_any input
    else
      puts "[ERROR] expect #{input} (#{input.class})"
    end
  end

  def expect2(cond, args = {})
    @action_counter += 1
    @action[:id] = @action_counter
    @action[:check] = cond
    @action[:result] = @result.value

    @action[:alterations] = @result.alterations
    @action[:expected] = @result.expected
    @action[:expected] = args[:expected] if args[:expected]

    @report.lines << @action.clone
    weight(1.0)

    app = Application.instance
    c = app.letter[:bad]
    c = app.letter[:good] if cond
    verbose c
  end

  # Set weight value for the action
  def weight(value = nil)
    if value.nil?
      @action[:weight]
    elsif value == :default
      @action[:weight] = 1.0
    else
      @action[:weight] = value.to_f
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
teuton-2.1.8 lib/teuton/case_manager/case/dsl/expect.rb
teuton-2.1.8dev1 lib/teuton/case_manager/case/dsl/expect.rb
teuton-2.1.7 lib/teuton/case_manager/case/dsl/expect.rb
teuton-2.1.6 lib/teuton/case_manager/case/dsl/expect.rb
teuton-2.1.5dev lib/teuton/case_manager/case/dsl/expect.rb
teuton-2.1.4 lib/teuton/case_manager/case/dsl/expect.rb
teuton-2.1.3 lib/teuton/case_manager/case/dsl/expect.rb
teuton-2.1.2 lib/teuton/case_manager/case/dsl/expect.rb
teuton-2.1.1 lib/teuton/case_manager/case/dsl/expect.rb
teuton-2.1.0 lib/teuton/case_manager/case/dsl/expect.rb
teuton-0.0.1 lib/teuton/case_manager/case/dsl/expect.rb