Skip to content

Commit 7cb9517

Browse files
committed
refactor properties
1 parent 1ff8175 commit 7cb9517

File tree

2 files changed

+65
-65
lines changed

2 files changed

+65
-65
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
ParameterType(
2+
name: 'property',
3+
regexp: /[^\"]*/,
4+
type: String,
5+
transformer: lambda do |string|
6+
if string_is_a_property?(string)
7+
string.slice!('<')
8+
string.slice!('>')
9+
handle_property(string)
10+
elsif string_is_a_faker?(string)
11+
handle_faker(string)
12+
else
13+
return string
14+
end
15+
end
16+
)
17+
18+
private
19+
20+
def current_process_id
21+
tag_process_id = @scenario_tags.grep(/@user/).first
22+
process_id = tag_process_id.delete_prefix('@user')
23+
return 'ERROR: User not foud for scenario' if process_id.nil?
24+
25+
process_id
26+
end
27+
28+
def string_is_a_property?(string)
29+
string.start_with?('<') &&
30+
string.end_with?('>')
31+
end
32+
33+
def string_is_a_faker?(string)
34+
string.start_with?('$') || string.start_with?('$$')
35+
end
36+
37+
def handle_property(property)
38+
properties = all_user_properties_as_json
39+
process_id = current_process_id
40+
user_id = "@user#{process_id}"
41+
42+
if !properties[user_id] || !properties[user_id][property]
43+
raise "Property <#{property}> not found for @user#{current_process_id}"
44+
end
45+
46+
properties[user_id][property]
47+
end
48+
49+
def all_user_properties_as_json
50+
raise 'ERROR: No properties file found' if ENV[K::PROPERTIES_PATH].nil?
51+
52+
properties_absolute_path = File.expand_path(ENV[K::PROPERTIES_PATH])
53+
raise 'ERROR: Properties file not found' unless File.file?(
54+
properties_absolute_path
55+
)
56+
57+
file = open(properties_absolute_path)
58+
content = file.read
59+
JSON.parse(content)
60+
end
61+
62+
def handle_faker(faker)
63+
nil
64+
end
Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,7 @@
11
require 'calabash-android/calabash_steps'
22
require 'kraken-mobile/utils/K'
33
require 'kraken-mobile/models/android_device'
4-
5-
ParameterType(
6-
name: 'property',
7-
regexp: /[^\"]*/,
8-
type: String,
9-
transformer: lambda do |string|
10-
if string_is_a_property?(string)
11-
string.slice!('<')
12-
string.slice!('>')
13-
handle_property(string)
14-
elsif string_is_a_faker?(string)
15-
handle_faker(string)
16-
else
17-
return string
18-
end
19-
end
20-
)
4+
require 'kraken-mobile/steps/general_steps'
215

226
Then(
237
/^I send a signal to user (\d+) containing "([^\"]*)"$/
@@ -86,51 +70,3 @@
8670
Then(/^I enter text "([^\"]*)"$/) do |text|
8771
keyboard_enter_text(text, {})
8872
end
89-
90-
private
91-
92-
def current_process_id
93-
tag_process_id = @scenario_tags.grep(/@user/).first
94-
process_id = tag_process_id.delete_prefix('@user')
95-
return 'ERROR: User not foud for scenario' if process_id.nil?
96-
97-
process_id
98-
end
99-
100-
def string_is_a_property?(string)
101-
string.start_with?('<') &&
102-
string.end_with?('>')
103-
end
104-
105-
def string_is_a_faker?(string)
106-
string.start_with?('$') || string.start_with?('$$')
107-
end
108-
109-
def handle_property(property)
110-
properties = all_user_properties_as_json
111-
process_id = current_process_id
112-
user_id = "@user#{process_id}"
113-
114-
if !properties[user_id] || !properties[user_id][property]
115-
raise "Property <#{property}> not found for @user#{current_process_id}"
116-
end
117-
118-
properties[user_id][property]
119-
end
120-
121-
def all_user_properties_as_json
122-
raise 'ERROR: No properties file found' if ENV[K::PROPERTIES_PATH].nil?
123-
124-
properties_absolute_path = File.expand_path(ENV[K::PROPERTIES_PATH])
125-
raise 'ERROR: Properties file not found' unless File.file?(
126-
properties_absolute_path
127-
)
128-
129-
file = open(properties_absolute_path)
130-
content = file.read
131-
JSON.parse(content)
132-
end
133-
134-
def handle_faker(faker)
135-
nil
136-
end

0 commit comments

Comments
 (0)