Skip to content
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

Open
wants to merge 37 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
8576e7e
Merge branch 'release/0.16.2'
jmoody Sep 17, 2015
0b9eab1
Merge pull request #856 from calabash/release/0.16.3
jmoody Sep 17, 2015
78d16b2
Merge pull request #865 from calabash/release/0.16.4
jmoody Oct 1, 2015
efb3f13
Merge pull request #946 from calabash/release/0.17.0
jmoody Dec 9, 2015
43de674
Merge pull request #981 from calabash/release/0.17.1
jmoody Jan 14, 2016
dbbe1d7
Merge pull request #988 from calabash/release/0.18.0
jmoody Feb 2, 2016
bcbc1be
Merge pull request #999 from calabash/release/0.18.1
jmoody Feb 19, 2016
ce91975
Merge pull request #1012 from calabash/release/0.18.2
jmoody Mar 11, 2016
fd8f144
Predicate filter proposal
ark-konopacki Apr 19, 2016
9fe8f33
Merge pull request #1079 from calabash/release/0.19.0
jmoody Apr 21, 2016
6c920fe
Merge branch 'develop' of https://github.com/calabash/calabash-ios in…
ark-konopacki Apr 27, 2016
33b2dd8
Added correct_predicate method
ark-konopacki Apr 27, 2016
1650d00
Added rspec tests for correct_predicate
ark-konopacki Apr 27, 2016
03ee1fb
Remove not needed part in test
ark-konopacki Apr 27, 2016
0f0cacc
added correct_format method
ark-konopacki May 10, 2016
282b64d
Review fixes, improvement in correct_predicate? method
ark-konopacki May 11, 2016
4d24fc6
Minor fixes and adding tests
ark-konopacki May 12, 2016
e226c3f
Merge pull request #1104 from calabash/release/0.19.1
jmoody May 20, 2016
7ec6933
Merge pull request #1110 from calabash/release/0.19.2
jmoody Jun 30, 2016
6af4214
Merge pull request #1153 from calabash/release/0.20.0
jmoody Sep 13, 2016
3732a0b
Merge pull request #1206 from calabash/release/0.20.3
jmoody Oct 14, 2016
4753008
Merge pull request #1250 from calabash/release/0.20.4
jmoody Jan 2, 2017
348a902
Merge pull request #1295 from calabash/release/0.20.5
jmoody Apr 19, 2017
90b064f
Merge pull request #1331 from calabash/release/0.21.1
jmoody Sep 22, 2017
a267dda
Merge pull request #4 from calabash/develop
ark-konopacki Oct 20, 2017
6b44569
Merge pull request #1342 from calabash/release/0.21.2
jmoody Nov 1, 2017
ecb035f
Merge pull request #1360 from calabash/release/0.21.4
jmoody Dec 6, 2017
ee7d0cc
Merge pull request #1373 from calabash/release/0.21.5
jmoody Apr 3, 2018
8a69cf1
Gem: bump version to 0.21.6
AlexWellsHS Aug 15, 2018
280f23c
update run_loop dependency version
AlexWellsHS Aug 30, 2018
deb6224
update cocoapod version
AlexWellsHS Aug 30, 2018
f72a770
remove RunLoop::SimControl methods from quit_sim, calabash_sim_reset
AlexWellsHS Aug 30, 2018
4dff0a2
remove SimControl reference from spec resources
AlexWellsHS Aug 30, 2018
e2d974d
remove accessibility methods and callers
AlexWellsHS Aug 31, 2018
2995a64
update .irbrc SimControl references to Simctl
AlexWellsHS Aug 31, 2018
603acef
Merge pull request #1389 from AlexWellsHS/release/0.21.6
jmoody Sep 5, 2018
503e831
Merge remote-tracking branch 'upstream/master' into feature/predicate…
ark-konopacki Sep 5, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 53 additions & 18 deletions calabash-cucumber/lib/calabash-cucumber/map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer this pattern:

def self.query_has_predicate?(query)
  query.match(/{.*}/)
end

# Expect implies an exception will be raised.
def self.expect_valid_predicate(query)
   match = self.query_has_predicate?(query)
   return true if match.nil?

   ...
end

Copy link
Contributor

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:

  1. The predicate keyword is supported (CONTAINS, LIKE, etc).
  2. The right-hand side of the predicate is valid (not missing a ').

str = query.match(/{.*}/)[0]
correct = false
predicate = %w(BEGINSWITH CONTAINS ENDSWITH LIKE MATCHES)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use %w; use [ ].

Copy link
Contributor

Choose a reason for hiding this comment

The 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}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use fail here. Raise a RuntimeError. We don't need to take a screenshot.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to something like:

def self.right_hand_side_of_predicate_valid?(query)

if !query.match(/:'/).nil?
if !query.match(/:'.*'/).nil?
true
else
fail 'Incorrect query format please check query string'
Copy link
Contributor

@jmoody jmoody May 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use fail.

end
else
true
end
end
private

def self.map_factory
Expand Down
31 changes: 31 additions & 0 deletions calabash-cucumber/spec/lib/map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,36 @@
/map view marked:'my mark', scrollToViewWithMark failed for:/)
end
end

describe ".raw_map.correct_predicate" do
Copy link
Contributor

Choose a reason for hiding this comment

The 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