Module: User
- Extended by:
- LapisLazuli
- Defined in:
- lib/lapis_lazuli/generators/cucumber/template/features/helpers/user_helper.rb
Overview
This helper loads user data from the config files. After loading the data, it will overwrite certain strings, like __TIMESTAMP__ to randomize information
Constant Summary collapse
- @@data =
nil
Constants included from LapisLazuli
LapisLazuli::CONFIG_OPTIONS, LapisLazuli::PLACEHOLDERS, LapisLazuli::VERSION
Constants included from LapisLazuli::WorldModule::Hooks
LapisLazuli::WorldModule::Hooks::HOOK_QUEUES
Instance Attribute Summary
Attributes included from LapisLazuli
Class Method Summary collapse
- .get(field) ⇒ Object
- .load_user_data(user) ⇒ Object
- .number_to_letter(numbers) ⇒ Object
-
.replace_constants(value) ⇒ Object
replace certain constants in a string, for example ‘TIMESTAMP’ becomes ‘154875631’.
-
.replace_hash_constants(hash) ⇒ Object
Replace random or time values of a complete hash.
- .set(field, value) ⇒ Object
Methods included from LapisLazuli
After, Before, Start, fetch_versions
Methods included from LapisLazuli::Assertions
Methods included from LapisLazuli::GenericModule::XPath
#xp_and, #xp_contains, #xp_not, #xp_or
Methods included from LapisLazuli::WorldModule::API
Methods included from LapisLazuli::WorldModule::Browser
Methods included from LapisLazuli::WorldModule::Browser::ClassMethods
#browser_module, #browser_modules
Methods included from LapisLazuli::WorldModule::Proxy
Methods included from LapisLazuli::WorldModule::Logging
Methods included from LapisLazuli::WorldModule::Config
#add_config_from_file, #config, #current_env, #env, #env_or_config, #get_config_from_file, #has_config?, #has_env?, #has_env_or_config?, #init, #load_config, #metadata, #var_from_env
Methods included from LapisLazuli::WorldModule::Config::ClassMethods
#add_config, #config_file, #config_file=, #config_files
Methods included from LapisLazuli::WorldModule::Error
Methods included from LapisLazuli::WorldModule::Variable
#has_storage?, #scenario, #storage, #time, #uuid, #variable, #variable!
Methods included from LapisLazuli::WorldModule::Hooks
add_hook, #after_scenario_hook, #before_scenario_hook
Class Method Details
.get(field) ⇒ Object
24 25 26 |
# File 'lib/lapis_lazuli/generators/cucumber/template/features/helpers/user_helper.rb', line 24 def get(field) return @@data[field] end |
.load_user_data(user) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/lapis_lazuli/generators/cucumber/template/features/helpers/user_helper.rb', line 9 def load_user_data(user) data = config('users.default-user') begin specific_data = config("users.#{user}") rescue Exception => err1 begin specific_data = config("users.#{ENV['TEST_ENV']}.#{user}") rescue Exception => err2 error "The given user `#{user}` was not found in any of the config files:\n- #{err1.message}\n- #{err2.message}" end end new_data = data.merge specific_data @@data = replace_hash_constants(new_data) end |
.number_to_letter(numbers) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/lapis_lazuli/generators/cucumber/template/features/helpers/user_helper.rb', line 63 def number_to_letter(numbers) num_string = numbers.to_s alpha26 = ("a".."j").to_a letters = '' num_string.scan(/./).each do |number| letters += alpha26[number.to_i] end return letters end |
.replace_constants(value) ⇒ Object
replace certain constants in a string, for example ‘TIMESTAMP’ becomes ‘154875631’
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/lapis_lazuli/generators/cucumber/template/features/helpers/user_helper.rb', line 46 def replace_constants(value) if value.to_s == value epoch = Time.now.to_i alpha = number_to_letter(epoch) = Time.now.strftime("D%Y-%M-%d-T%H-%M-%S") old_val = value.to_s value = value.sub('_RAND_', epoch.to_s) value = value.sub('_TIMESTAMP_', ) value = value.sub('_RAND-ALPHA_', alpha) unless value == old_val log.debug "#{old_val} > #{value}" end end return value end |
.replace_hash_constants(hash) ⇒ Object
Replace random or time values of a complete hash
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/lapis_lazuli/generators/cucumber/template/features/helpers/user_helper.rb', line 33 def replace_hash_constants(hash) if hash.respond_to? :each new_hash = {} hash.each do |key, value| new_hash[key] = replace_constants(value) end else new_hash = replace_constants(hash) end return new_hash end |
.set(field, value) ⇒ Object
28 29 30 |
# File 'lib/lapis_lazuli/generators/cucumber/template/features/helpers/user_helper.rb', line 28 def set(field, value) @@data[field] = User.replace_constants(value) end |