Skip to content

Commit d920669

Browse files
committed
ensure feature file syntaxis
1 parent 044939d commit d920669

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

calabash-android-features-skeleton/support/app_installation_hooks.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
require 'calabash-android/management/app_installation'
22

3-
AfterConfiguration do |config|
3+
AfterConfiguration do |_config|
44
FeatureMemory.feature = nil
55
end
66

77
Before do |scenario|
8-
scenario = scenario.scenario_outline if scenario.respond_to?(:scenario_outline)
8+
scenario = scenario.scenario_outline if scenario.respond_to?(
9+
:scenario_outline
10+
)
911

1012
feature = scenario.feature
1113
if FeatureMemory.feature != feature || ENV['RESET_BETWEEN_SCENARIOS'] == '1'

lib/kraken-mobile/models/feature_file.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,45 @@ def tags_for_user_id(user_id)
4747
user_scenario.tags.reject { |tag| tag == user_tag }
4848
end
4949

50+
def right_syntax?
51+
all_scenarios_have_a_user_tag? &&
52+
only_one_user_tag_for_each_scenario? &&
53+
!duplicate_tags_for_a_user?
54+
end
55+
56+
def duplicate_tags_for_a_user?
57+
taken_user_tags = {}
58+
scenarios.each do |scenario|
59+
user_tag = scenario.tags.select do |tag|
60+
tag.start_with?('@user')
61+
end.first
62+
return true unless taken_user_tags[user_tag].nil?
63+
64+
taken_user_tags[user_tag] = user_tag
65+
end
66+
false
67+
end
68+
69+
def only_one_user_tag_for_each_scenario?
70+
scenarios.each do |scenario|
71+
user_tags = scenario.tags.select do |tag|
72+
tag.start_with?('@user')
73+
end
74+
return false if user_tags.count != 1
75+
end
76+
true
77+
end
78+
79+
def all_scenarios_have_a_user_tag?
80+
scenarios.each do |scenario|
81+
user_tag = scenario.tags.select do |tag|
82+
tag.start_with?('@user')
83+
end.first
84+
return false if user_tag.nil?
85+
end
86+
true
87+
end
88+
5089
private
5190

5291
def read_content

lib/kraken-mobile/test_scenario.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'kraken-mobile/helpers/feature_analyzer'
12
require 'kraken-mobile/mobile/mobile_process'
23
require 'kraken-mobile/models/feature_file'
34
require 'kraken-mobile/models/web_device'
@@ -34,6 +35,11 @@ def before_execution
3435
end
3536

3637
def run
38+
unless @feature_file.right_syntax?
39+
raise "ERROR: Verify feature file #{@file_path} has one unique @user tag"\
40+
' for each scenario'
41+
end
42+
3743
before_execution
3844
execute
3945
after_execution

lib/kraken_mobile.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def start
2828
#-------------------------------
2929
# Helpers
3030
#-------------------------------
31-
def apk_path_for_process_id(process_id)
31+
def apk_path_for_process_id(_process_id)
3232
@apk_path
3333
end
3434

0 commit comments

Comments
 (0)