Module: DataFactory

Defined in:
lib/test-factory/data_factory.rb

Overview

Provides a set of tools used to create your Data Object classes.

Instance Method Summary collapse

Instance Method Details

#checkbox_setting(checkbox) ⇒ Object Also known as: radio_setting

Transform for use with data object instance variables that refer to checkboxes or radio buttons.

Parameters:

  • checkbox (Watir::CheckBox)

    The checkbox on the page that you want to inspect



33
34
35
# File 'lib/test-factory/data_factory.rb', line 33

def checkbox_setting(checkbox)
  checkbox.set? ? :set : :clear
end

#get_or_select(var, select_list) ⇒ Object

Use this method in your data object class for select list boxes that will have default values you may be interested in. The method will either set the select box to the value specified, or, if no value exists for the given variable in your data object, it will get the value from the UI and set the data object’s variable to that value. Note that this only supports select lists that allow a single selection.

Examples:


@num_resubmissions = get_or_set(@num_resubmissions, page.num_resubmissions)


48
49
50
51
52
53
54
# File 'lib/test-factory/data_factory.rb', line 48

def get_or_select(var, select_list)
  if var==nil
    select_list.selected_options[0].text
  else
    select_list.select var
  end
end

#requires(*elements) ⇒ Object

Items passed to this method are checked to ensure that the associated class instance variable is not nil. If it is, the script is aborted and an error is thrown, describing what information the Data Object requires before the script can run.

Examples:


requires @site @assignment

Parameters:

  • elements (Array)

    the list of items that are required.



23
24
25
26
27
# File 'lib/test-factory/data_factory.rb', line 23

def requires(*elements)
  elements.each do |inst_var|
    raise "You've neglected to define a required variable for the #{self}." if inst_var==nil
  end
end

#set_options(hash) ⇒ Object Also known as: update_options

Add this to the bottom of your Data Object’s initialize method. Converts the contents of the hash into the class’s instance variables.

Parameters:

  • hash (Hash)

    Contains all options required for creating the needed Data Object



7
8
9
10
11
# File 'lib/test-factory/data_factory.rb', line 7

def set_options(hash)
  hash.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end