lib/teuton/case/dsl/expect.rb in teuton-2.6.0 vs lib/teuton/case/dsl/expect.rb in teuton-2.7.0
- old
+ new
@@ -1,8 +1,11 @@
# frozen_string_literal: true
module DSL
+ # expect, expect2, expect_any, expect_first, expect_last
+ # expect_nothing, expect_none, expect_one
+
# expect <condition>, :weight => <value>
def expect(input, args = {})
if input.instance_of?(TrueClass) || input.instance_of?(FalseClass)
expect2(input, args)
elsif input.instance_of?(String) || input.instance_of?(Regexp) || input.instance_of?(Array)
@@ -14,22 +17,20 @@
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]
+ @action[:result] = (args[:value] || @result.value)
+ @action[:alterations] = @result.alterations
+ @action[:expected] = (args[:expected] || @result.expected)
@report.lines << @action.clone
weight(1.0)
- app = Application.instance
- c = app.letter[:bad]
- c = app.letter[:good] if cond
+ c = Settings.letter[:bad]
+ c = Settings.letter[:good] if cond
verbose Rainbow(c).green
end
def expect_any(input, args = {})
if input.instance_of? Array
@@ -38,10 +39,26 @@
result.find(input)
end
expect2 result.count.gt(0), args
end
+ def expect_exit(value)
+ @result.alterations = "Read exit code"
+ real_value = result.exitcode
+ cond = if value.is_a? Range
+ expect_value = "With range #{value}"
+ value.to_a.include? real_value
+ elsif value.is_a? Array
+ expect_value = "Inside list #{value}"
+ value.include? real_value
+ else
+ expect_value = value
+ (real_value == value.to_i)
+ end
+ expect2 cond, value: real_value, expected: expect_value
+ end
+
def expect_first(input, args = {})
@result.first
output = input
output = args[:expected] if args[:expected]
expect2 input, expected: output
@@ -52,11 +69,10 @@
output = input
output = args[:expected] if args[:expected]
expect2 input, expected: output
end
- # def expect_none(input, args = {})
def expect_nothing(args = {})
expect2 result.count.eq(0), args
end
def expect_none(input = nil, args = {})
@@ -77,11 +93,11 @@
result.find(input)
end
expect2 result.count.eq(1), args
end
- # Set weight value for the action
def weight(value = nil)
+ # Set weight value for the action
if value.nil?
@action[:weight]
elsif value == :default
@action[:weight] = 1.0
else