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

Cucumber new tag expressions syntax support #668

Merged
merged 12 commits into from
Nov 9, 2018

Conversation

sandeepnagra
Copy link

@sandeepnagra sandeepnagra commented Nov 9, 2018

Fix for issue #667

  • Updated the gem to use Cucumber::TagExpressions::Parser to support new tag expression syntax
  • parallel_cucumber command will calculate the scenarios to be executed based on passed tag expression string correctly now and will hence determine the scenarios to be executed per node correctly.
  • added few more rspec tests to test additional tag expression combinations possible with new syntax

* Updated the gem to use Cucumber::TagExpressions::Parser to support new tag expression syntax
* parallel_cucumber command will calculate the scenarios to be executed based on passed tag expression string correctly now and will hence determine the scenarios to be executed per node correctly.
* added few more rspec tests to test additional tag expression combinations possible with new syntax
@sandeepnagra sandeepnagra changed the title Cucumber tag expressions fix Cucumber new tag expressions syntax support Nov 9, 2018
Copy link
Author

@sandeepnagra sandeepnagra left a comment

Choose a reason for hiding this comment

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

Updated

lib/parallel_tests/cucumber/scenarios.rb Outdated Show resolved Hide resolved
tags.concat options[:ignore_tag_pattern].to_s.split(/\s*,\s*/).map {|tag| "~#{tag}" }
tags.concat options[:test_options].to_s.scan(/(?:-t|--tags) (~?@[\w,~@]+)/).flatten
# Combine and generate a tag expression for given test options and ignore tag pattern. Refer here to understand how new tag expression syntax works - https://github.com/cucumber/cucumber/tree/master/tag-expressions
tags = [options[:test_options]]
Copy link
Owner

Choose a reason for hiding this comment

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

test_options are the raw arguments passed to cucumber, so they would be -t sometag and not just sometag ?

Copy link
Author

@sandeepnagra sandeepnagra Nov 9, 2018

Choose a reason for hiding this comment

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

Yeah, I totally missed that. I am working on this one now. I have changed:

tags = [options[:test_options]]

to:

tags = options[:test_options].to_s.scan(/(?:-t|--tags) ([\w,(and|or|not) ?@]+)/).flatten

I am testing it right now.

Copy link
Author

Choose a reason for hiding this comment

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

This is working for all the cases except when user passes a tag expression with parenthesis like: not (@white or @blue)

I am trying to figure out the regex for that.

Copy link
Author

Choose a reason for hiding this comment

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

ok, so the following does the job and handles parenthesis in tag expression as well whether passed within or without the quotes (i.e. either -t 'not (@white and @black)' or -t not (@white and @black)):

tags = options[:test_options].to_s.scan(/(?:-t|--tags) ([^"]*)/).flatten.map { |tag| tag.delete("'")}

Copy link
Author

Choose a reason for hiding this comment

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

All the rspec tests work fine, I did update them to include -t and --tags in all test options. I am now testing this gem for a project locally.

tags.concat options[:ignore_tag_pattern].to_s.split(/\s*,\s*/).map {|tag| "~#{tag}" }
tags.concat options[:test_options].to_s.scan(/(?:-t|--tags) (~?@[\w,~@]+)/).flatten
# Combine and generate a tag expression for given test options and ignore tag pattern. Refer here to understand how new tag expression syntax works - https://github.com/cucumber/cucumber/tree/master/tag-expressions
tags = options[:test_options].to_s.scan(/(?:-t|--tags) ([^"]*)/).flatten.map { |tag| tag.delete("'")}
Copy link
Owner

Choose a reason for hiding this comment

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

yeah this gets into parsing ... need to be smarter :D

try

require 'shellwords'
tags = []
words = options[:test_options].to_s.shellsplit
words.each_with_index { |w,i| tags << words[i+1] if ["-t", "--tags"].include?(w) }

Copy link
Author

Choose a reason for hiding this comment

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

Perfect! The previous approach worked too but I agree it looked very complex. shellsplit works better in this case. I updated the PR per this suggestion. All rspec tests are passing and I ran some parallel cucumber tests using local gem and it works fine.

I also updated the tag expression in scenarios_spec.rb as cucumber doesn't support complex tag expressions being passed without single quotes. It only works for single tags now. For example: cucumber features/ -t @colors will work but cucumber features/ -t @colors and not @black won't work, it has to be cucumber features/ -t '@colors and not @black'

I guess this addresses the last issue in PR and we should be good to merge now.

…upport complex tag expressions with being passed in single quotes
@grosser grosser merged commit 65b1573 into grosser:master Nov 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants