Class: FlowVerify

Inherits:
Object
  • Object
show all
Includes:
Test::Unit::Assertions
Defined in:
lib/taft_files/framework/zznamezz/watir/flows/flow_objects.rb

Overview

A class defining a verification step

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected, value_or_regex, flow_field) ⇒ FlowVerify

expected is a boolean for whether or not the verification is expected to succeed or fail value_or_regex is a string, number, boolean or regex flow_field is a FlowField object pointing to a field whose value value_or_regex must be used against



390
391
392
393
394
395
396
# File 'lib/taft_files/framework/zznamezz/watir/flows/flow_objects.rb', line 390

def initialize(expected, value_or_regex, flow_field)
  @expected = expected
  @value_or_regex = value_or_regex

  @flow_field = flow_field
  raise ":flow_field must be of class FlowField" unless @flow_field.class == FlowField
end

Instance Attribute Details

#expectedObject

Returns the value of attribute expected.



385
386
387
# File 'lib/taft_files/framework/zznamezz/watir/flows/flow_objects.rb', line 385

def expected
  @expected
end

#flow_fieldObject

Returns the value of attribute flow_field.



385
386
387
# File 'lib/taft_files/framework/zznamezz/watir/flows/flow_objects.rb', line 385

def flow_field
  @flow_field
end

#value_or_regexObject

Returns the value of attribute value_or_regex.



385
386
387
# File 'lib/taft_files/framework/zznamezz/watir/flows/flow_objects.rb', line 385

def value_or_regex
  @value_or_regex
end

Instance Method Details

#to_sObject



398
399
400
401
402
# File 'lib/taft_files/framework/zznamezz/watir/flows/flow_objects.rb', line 398

def to_s
  s = ""
  s += "Flow verifier : expected : #{@expected}. Value/regex : #{@value_or_regex.inspect}. Field : #{@flow_field}"
  s
end

#verify(actual) ⇒ Object



404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'lib/taft_files/framework/zznamezz/watir/flows/flow_objects.rb', line 404

def verify(actual)
  puts "now in verify for FlowVerify for field #{@flow_field} against value #{@value_or_regex}"

  case @value_or_regex # case is better, leaves room for other options depending on class
    when Regexp
      match = !!(actual =~ @value_or_regex) # double-invert to convert to true-or-false
    else
      match = (actual == @value_or_regex)
  end
  if @expected
    message = "FlowVerify failed. Expected the value to match #{@value_or_regex.inspect} but was actually #{actual.inspect}"
  else
    message = "FlowVerify failed. Expected the value #{@value_or_regex.inspect} to be different to the actual value of #{actual.inspect}"
  end
  puts "about to assert; #{actual.inspect} == #{@value_or_regex.inspect} => #{@expected == match}"
  assert_equal(@expected, match, message)
  puts "assertion passed"
end