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

'feature' variable comes up nil if you don't provide an explicit file path to cucumber command (4.0.0) #1427

Closed
DougMaisells opened this issue Jun 15, 2020 · 18 comments

Comments

@DougMaisells
Copy link

Describe the bug
Cucumber no longer searches beyond current folder for scripts matching a -t@

To Reproduce
Steps to reproduce the behavior:
I recently updated a bunch of gems including Chromedriver, cucumber, capybara, selenium-webdriver. Everything was working fine before. Now I get the following error. The token (feature is undefined)....

cucumber OS=xxx ENV=yyy -t@some_tag

undefined method tags' for nil:NilClass (NoMethodError) ../.rvm/gems/ruby-2.3.0/gems/cucumber-gherkin-13.0.0/lib/gherkin/query.rb:19:in update_feature'

_def update_feature(feature)
store_nodes_location(feature.tags)

feature.children.each do |child|
update_rule(child.rule) if child.rule
update_background(child.background) if child.background
update_scenario(child.scenario) if child.scenario
end
end_

I used to be able to at my root directory where I had a features/app_name directory I used to be able to run a script with

cucumber OS=xxx ENV=yyy -t@some_tag

(and this would search all folders from the root directory AND ALL subfolders for this tag and run those scripts)

now I must use

cucumber OS=xxx ENV=yyy features/app_name/..sub-directory... -t@some_tag OR

cucumber OS=xxx ENV=yyy features/app_name/..sub-directory... /thefeature.feature -t@some_tag

Is there something I need to set in my environment so that the first command works that it will search from the root folder for all feature files matching the tag?

Expected behavior
Cucumber 3.0 used to search all .feature files from the root directory whether they were in the current folder or sub-folders within the current folder etc

Context & Motivation

I must be more specific in the path given to cucumber particularly for a hierarchical test system of feature files broken up into folders by functionality

Screenshots
If applicable, add screenshots to help explain your problem.

Your Environment

  • 4.0.0
  • MAC OSX Mojave

Additional context
Come on. Basic functionality was removed in 4.0.0. Was this not regression tested by QA team at SmartBear prior to release?

@vincent-psarga
Copy link
Contributor

Hey Douglas,

Thanks for opening the issue. The behaviour you explain is surprising, as this should now have changed in v4.

As an example:

╭─vincent.pretre@Vincents-MacBook-Pro ~/dev/open-source/cucumber-ruby-meta/cucumber-ruby ‹ruby-2.6.3› ‹master*› 
╰─$ bundle exec cucumber
WARNING: Nokogiri was built against LibXML version 2.9.10, but has dynamically loaded 2.9.4
Using the default profile...
............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

217 scenarios (217 passed)
1285 steps (1285 passed)
0m3.701s

╭─vincent.pretre@Vincents-MacBook-Pro ~/dev/open-source/cucumber-ruby-meta/cucumber-ruby ‹ruby-2.6.3› ‹master*› 
╰─$ bundle exec cucumber -t@global_state
WARNING: Nokogiri was built against LibXML version 2.9.10, but has dynamically loaded 2.9.4
Using the default profile...
.......................................

4 scenarios (4 passed)
39 steps (39 passed)
0m0.117s

Also on OSX (Catalina in my case, but I don't think this has much impact).

Do you have some custom profiles defined by any chance ?

@DougMaisells
Copy link
Author

I wouldn't know about custom profiles. We can certainly do a screenshare as I did not set up the initial environment and did not change it when I switched to cucumber v4.
nokogiri (1.10.9, 1.8.2)
This used to work for me in cuc v3. I did update capybara, selenium-webdriver, chromedriver and all related gem with bundle upgrade xxxxx. I am running ruby-2.3.0. as the scripts are incompatible with any later version. Let me know a good time to do a GTM.

@vincent-psarga
Copy link
Contributor

vincent-psarga commented Jun 23, 2020

Do you have a cucumber.yml file in your repo ? This would define the profiles which may cause an issue here.

I'm also a bit surprised with the way you used the ENV variables (I guesss OS and ENV are used as environment variables). Can you try running this instead to see if that changes anything:

OS=xxx ENV=yyy  cucumber -t@some_tag

@DougMaisells
Copy link
Author

Your suggestion still gives the same error: OS=chrome ENV=us-prod cucumber -t@peak_quick_smoke
undefined method tags' for nil:NilClass (NoMethodError) /Users/douglas.maisells/.rvm/gems/ruby-2.3.0/gems/cucumber-gherkin-13.0.0/lib/gherkin/query.rb:19:in update_feature'

Yes I do have a cucumber.yml file, There are four key value pairs:
html_report, mm, cpro, and parallel. What am I looking for specifically?

@vincent-psarga
Copy link
Contributor

I'm wondering if those extra options may be set for those profiles (which may end up causing issues). That said, the way you describe it, there's no override of the default profile so it should not cause the issue during the run.
I'll send you an email for discussing this issues through Zoom (or any other meeting tool) to try to reproduce this issue and understand how it occurs.

@DougMaisells
Copy link
Author

DougMaisells commented Jun 23, 2020

Sure sounds good or we can do a GTM because I heard Zoom has some security issues

@vincent-psarga
Copy link
Contributor

Good news, I was able to reproduce your issue. It can happened when there's an empty .feature file in your features/ directory.
I'll fix this in Gherkin and/or cucumber-ruby.

Can you confirm you have an empty file in your features ? (or at least a feature that does not have the "Feature" keyword at the beginning, it can also happen when the file only has comments)

@DougMaisells
Copy link
Author

Great. Unfortunately off hand, I don't think I have such a file. I know that I have one or two .feature files that have no Scenarios defined yet but they at least have a Feature line as well as a background section (with an accompanying comment block). I will see if I can find some time to look through the 50+ features files I have but all should have a Feature line.

@DougMaisells
Copy link
Author

I checked all the .feature files which I work on and all have a Feature keyword

So I want to be able to run cucumber like I had before with cucumber 3.0.0 at my $HOME/repos/repo-name. Under this directory is an entire infrastructure of our organization, many of which were worked on by folks no longer in the company so there may be an empty .feature file there somewhere, I don't know. All I had to do before was just specify a tag in my scripts like -t@my_feature and it would find all those scripts buried in the sub-folder directory structure from that root. I tried cd'ing to main header folder for my feature e.g., $HOME/repos/repo-name/features/my_feature. but when I run cucumber from there, I get: No such file or directory - features. You can use cucumber --init to get started.

@marnen
Copy link

marnen commented Jun 23, 2020

@DougMaisells You might be able to use something like grep -Lr Feature path/to/feature/files to quickly print the names of any files that don't contain the word "Feature".

@vincent-psarga
Copy link
Contributor

So I want to be able to run cucumber like I had before with cucumber 3.0.0 at my $HOME/repos/repo-name.

Of course, that's a bug that was introduced when I added gherkin query. I'll publish a bug fix (considering it comes from an empty Feature file). Hopefully it'll solve your problem.

@DougMaisells
Copy link
Author

Yes thank you, with #grep -Lr Feature . I was able to find an empty file. It was another project written by an engineer whom has long since left the company. Now after adding a Feature: line to that file, I get the following:

(1:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got '@Legistar @LSregression @atsui @ats @intc' (Cucumber::Core::Gherkin::ParseError)
/Users/douglas.maisells/.rvm/gems/ruby-2.3.0/gems/cucumber-core-7.0.0/lib/cucumber/core/gherkin/parser.rb:29:in `block in document'

@vincent-psarga
Copy link
Contributor

That's weird, normally the parser supports a file with simply a "Feature: some name" as content.

@vincent-psarga
Copy link
Contributor

So I made a fix in cucumber-gherkin gem - it's not yet released but should be soon (I have to discuss that with the other commiters as we have a few other on-going fixes there).
Once this is done, I'll also make a bug fix release on cucumber so we ensure we use the fixed version of gherkin.

cukebot pushed a commit to cucumber/gherkin-ruby that referenced this issue Jun 24, 2020
@BrianHawley
Copy link

The fix was released in cucumber-gherkin 14.0.0, but cucumber itself doesn't allow the use of that version (it requires ~> 13.0.0). So for others who have run into this issue, I made a patch that applies the fix. Put this code in one of your support files (I used env_changes.rb):

unless Gherkin::Query.const_defined?('Patch', false)
  module Gherkin::Query::Patch
    private

    def update_feature(feature)
      super unless feature.nil?
    end
  end

  Gherkin::Query.class_exec do
    prepend Gherkin::Query::Patch
  end
end

I could have just prepended an anonymous module, but I didn't want to do so more than once just in case the support file got loaded more than once, so I made a named module to have a detectable condition. I did the prepend in a class_exec because it's a private method in older Ruby versions.

Looking forward to the new cucumber gem version that includes this fix.

@DougMaisells
Copy link
Author

DougMaisells commented Jun 29, 2020 via email

@BrianHawley
Copy link

BrianHawley commented Jun 29, 2020

@DougMaisells my patch is basically the same conditional code from the code change that went into the cucumber-gherkin commit referenced above, but refactored into a wrapper method that calls the original method if the not-nil condition passes. It doesn't fix your additional issue.

About that, that code looks like something that should count as a TagLine. The only thing that stands out to me is that tag which starts with the capital letter. Have you tried renaming that tag to lowercase? If switching to lowercase works, that would be useful info for making a new issue report.

@vincent-psarga
Copy link
Contributor

This should be fixed with the 4.1.0 release of cucumber-ruby

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

No branches or pull requests

4 participants