-
Notifications
You must be signed in to change notification settings - Fork 369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Predicate filter proposal #1075
base: develop
Are you sure you want to change the base?
Changes from 6 commits
8576e7e
0b9eab1
78d16b2
efb3f13
43de674
dbbe1d7
bcbc1be
ce91975
fd8f144
9fe8f33
6c920fe
33b2dd8
1650d00
03ee1fb
0f0cacc
282b64d
4d24fc6
e226c3f
7ec6933
6af4214
3732a0b
4753008
348a902
90b064f
a267dda
6b44569
ecb035f
ee7d0cc
8a69cf1
280f23c
deb6224
f72a770
4dff0a2
e2d974d
2995a64
603acef
503e831
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,28 +77,29 @@ def self.map(query, method_name, *method_args) | |
# | ||
# @see map for examples. | ||
def self.raw_map(query, method_name, *method_args) | ||
operation_map = { | ||
:method_name => method_name, | ||
:arguments => method_args | ||
} | ||
if correct_predicate?(query) || correct_format?(query) | ||
operation_map = { | ||
:method_name => method_name, | ||
:arguments => method_args | ||
} | ||
|
||
route = {:method => :post, :path => "map"} | ||
parameters = {:query => query, | ||
:operation => operation_map} | ||
body = self.map_factory.http(route, parameters) | ||
route = {:method => :post, :path => "map"} | ||
parameters = {:query => query, | ||
:operation => operation_map} | ||
body = self.map_factory.http(route, parameters) | ||
|
||
hash = JSON.parse(body) | ||
if hash["outcome"] != "SUCCESS" | ||
message = %Q[ | ||
map #{query}, #{method_name} failed for: | ||
hash = JSON.parse(body) | ||
if hash["outcome"] != "SUCCESS" | ||
message = %Q[ | ||
map #{query}, #{method_name} failed for: | ||
reason: #{hash["reason"]} | ||
details: #{hash["details"]} | ||
] | ||
self.map_factory.screenshot_and_raise(message) | ||
end | ||
|
||
reason: #{hash["reason"]} | ||
details: #{hash["details"]} | ||
] | ||
self.map_factory.screenshot_and_raise(message) | ||
hash | ||
end | ||
|
||
hash | ||
end | ||
|
||
# Asserts the result of a calabash `map` call and raises an error with | ||
|
@@ -143,6 +144,40 @@ def self.assert_map_results(map_results, msg) | |
end | ||
end | ||
|
||
# Evaluating whether a query contain correct predicate selector | ||
# returns true if query include correct predicate selector | ||
def self.correct_predicate?(query) | ||
if !query.match(/{.*}/).nil? | ||
str = query.match(/{.*}/)[0] | ||
correct = false | ||
predicate = %w(BEGINSWITH CONTAINS ENDSWITH LIKE MATCHES) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe extract these to a ruby constant so you can share them with the rspec tests. |
||
predicate.each do |value| | ||
if str.include?(value) | ||
correct = true | ||
return correct | ||
end | ||
end | ||
if !correct | ||
fail "Incorrect predicate used, valid selectors are: #{predicate}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use |
||
end | ||
end | ||
end | ||
|
||
# Evaluating whether a query contain two ' characters | ||
# returns true if query include : character and two ' characters | ||
# returns true if query does not include : character, like query("label") | ||
# TODO: We can add additional verification in future | ||
def self.correct_format?(query) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename to something like:
|
||
if !query.match(/:'/).nil? | ||
if !query.match(/:'.*'/).nil? | ||
true | ||
else | ||
fail 'Incorrect query format please check query string' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use |
||
end | ||
else | ||
true | ||
end | ||
end | ||
private | ||
|
||
def self.map_factory | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,5 +40,36 @@ | |
/map view marked:'my mark', scrollToViewWithMark failed for:/) | ||
end | ||
end | ||
|
||
describe ".raw_map.correct_predicate" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +100 for rspec tests. |
||
let(:query) { "view marked:'my mark'" } | ||
let(:incorrect_predicate) {%w(BEGINSWTH CONTAIN ENDWITH LKE MTCHES)} | ||
let(:correct_predicate) {%w(BEGINSWITH CONTAINS ENDSWITH LIKE MATCHES)} | ||
|
||
it "raw_map receive incorrect predicate and raise error" do | ||
|
||
incorrect_predicate.each do |predicate| | ||
merged_query = query + "{text #{predicate} 'sometext'}" | ||
expect do | ||
Calabash::Cucumber::Map.raw_map(merged_query, method_name, args) | ||
end.to raise_error(RuntimeError, | ||
/Incorrect predicate used, valid selectors are:/) | ||
end | ||
|
||
end | ||
|
||
it "raw_map receive correct predicate and not raise error" do | ||
|
||
correct_predicate.each do |predicate| | ||
merged_query = query + "{text #{predicate} 'sometext'}" | ||
expect do | ||
Calabash::Cucumber::Map.raw_map(merged_query, method_name, args) | ||
end.not_to raise_error(RuntimeError, | ||
/Incorrect predicate used, valid selectors are:/) | ||
end | ||
|
||
end | ||
end | ||
|
||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer this pattern:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are actually two conditions for a valid predicate:
'
).