class Datum::Helpers

@!visibility private Various helper functions

Public Class Methods

build_key(test_instance, method) click to toggle source

@!visibility private @param [TestCase] test_instance The ActiveSupport::TestCase instance @param [String] method The name of the method @return [String] A key for usage in Datum-compatible Hash instances

# File lib/datum/helpers.rb, line 34
def build_key test_instance, method
 "#{test_instance}_#{method}"
end
build_test_name(data_method_name, counter) click to toggle source

@!visibility private Test name for current test case, index, data_test method @param [String] data_method_name The name of the data_test method @param [int] counter The index / datum_id of the current test case @return [String]

# File lib/datum/helpers.rb, line 26
def build_test_name data_method_name, counter
 "test_#{data_method_name}_#{counter}"
end
clone_resource(resource, override_hash = nil) click to toggle source

@!visibility private @param [ActiveRecord::Base] resource An ActiveRecord Model instance @param [Hash] override_hash Hash of attributes / values to override from @return [Hash] Hash of attributes from provided resource

# File lib/datum/helpers.rb, line 60
def clone_resource resource, override_hash = nil
  override_hash.nil? ? resource.dup.attributes.with_indifferent_access :
    resource.dup.attributes.merge(
      override_hash.with_indifferent_access).with_indifferent_access
end
data_method_from_test_name(test_name) click to toggle source

@!visibility private @param [String] test_name Test case name generated from data_test usage @return [String] Name of the data_test method which generated the test

# File lib/datum/helpers.rb, line 17
def data_method_from_test_name test_name
  test_name.slice(/(?<=_).*(?=_)/)
end
import_file(file_name, directory, current_binding) click to toggle source

@!visibility private Reads a ruby file and eval’s it’s contents in the context of the Binding @param [String] file_name The name of the file to import @param [Pathname] directory A Pathname representing the file’s directory @param [Binding] current_binding Context at a particular code location

# File lib/datum/helpers.rb, line 52
def import_file file_name, directory, current_binding
  eval(read_file(file_name, directory), current_binding)
end
index_from_test_name(test_name) click to toggle source

@!visibility private @param [String] test_name Test case name generated from data_test usage @return [int] The index of the data_test / datum_id

# File lib/datum/helpers.rb, line 10
def index_from_test_name test_name
  ((test_name.to_s.split('_')[-1]).to_i)
end
read_file(file_name, directory, ext = ".rb") click to toggle source

@!visibility private @param [String] file_name The name of the file to read @param [Pathname] directory A Pathname representing the file’s directory @param [String] ext Optional extention of the file (default: ‘.rb’) @return [String] The file’s contents

# File lib/datum/helpers.rb, line 43
def read_file file_name, directory, ext = ".rb"
  File.read directory.join("#{file_name}#{ext}")
end