guard / guard-cucumber

Guard::Cucumber automatically run your features (much like autotest)
https://rubygems.org/gems/guard-cucumber
MIT License
86 stars 36 forks source link

Initialising guard-cucumber plugin fails with Error #42

Open s2k opened 3 years ago

s2k commented 3 years ago

Setup/Configuration/Environment

OS: macOS (11.1, Big Sur) Ruby: 3.0.0 installed using rvm

Bundler:

$ bundler -v
Bundler version 2.1.4

Gemfile:

source 'https://rubygems.org'

ruby '3.0.0'

group :development do
  gem 'guard-cucumber', '~> 3.0.0'
  gem 'guard', '~> 2.16.2'
end

Behaviour

Initialising guard-cucumberfails with an error message:

$ bundle exec guard init guard-cucumber
12:24:16 - INFO - Writing new Guardfile to /Users/stephan/dev/fastfeedbackusingruby/tmp/Guardfile
12:24:17 - ERROR - Could not load 'guard/guard-cucumber' or '~/.guard/templates/guard-cucumber' or find class Guard::Guardcucumber
> [#]

A Guardfile is created, but without guard-cucumber specific content:

$ cat Guardfile
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

## Uncomment and set this to only include directories you want to watch
# directories %w(app lib config test spec features) \
#  .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}

## Note: if you are using the `directories` clause above and you are not
## watching the project directory ('.'), then you will want to move
## the Guardfile to a watched dir and symlink it back, e.g.
#
#  $ mkdir config
#  $ mv Guardfile config/
#  $ ln -s config/Guardfile .
#
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"

Observation

Reverting to the previous release of guard-cucumber using

gem 'guard-cucumber', '~> 2.1.2'

in the Gemfile instead of '3.0.0' works. Since using the previous version of the plugin avoids the error _and creates a Cucumber related Guardfile, I presume this is in fact an issue with guard-cucumbernot Guard itself.

The Guardfile created with guard-cucumber 2.1.2:

$ cat Guardfile
# A sample Guardfile
# … skip comment lines 

cucumber_options = {
  # … skip comment lines 
}

guard "cucumber", cucumber_options do
  watch(%r{^features/.+\.feature$})
  watch(%r{^features/support/.+$}) { "features" }

  watch(%r{^features/step_definitions/(.+)_steps\.rb$}) do |m|
    Dir[File.join("**/#{m[1]}.feature")][0] || "features"
  end
end
s2k commented 2 years ago

Meanwhile, I upgraded to macOS 12.5 (Monterey) and Ruby 3.1.2 … and the behaviour persists.

s2k commented 2 years ago

Another bit of experimenting showed that initialisation fails, when running in a bundler context:

> cat Gemfile
source 'https://rubygems.org'

ruby '3.1.2'

gem 'guard-cucumber'
gem 'guard'

> gem list bundler

*** LOCAL GEMS ***

bundler (2.3.19, default: 2.3.18)
guard-bundler (3.0.0)
> gem list "^guard$"

*** LOCAL GEMS ***

guard (2.18.0)
> gem list "guard-cucumber"

*** LOCAL GEMS ***

guard-cucumber (3.0.0)
> guard init guard-cucumber
Warning: you have a Gemfile, but you're not using bundler or RUBYGEMS_GEMDEPS
13:40:10 - INFO - Writing new Guardfile to /Users/stephan/dev/tmp/gaincute/Guardfile
13:40:11 - INFO - cucumber guard added to Guardfile, feel free to edit it
> cat Guardfile
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

## Uncomment and set this to only include directories you want to watch
# directories %w(app lib config test spec features) \
#  .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}

## Note: if you are using the `directories` clause above and you are not
## watching the project directory ('.'), then you will want to move
## the Guardfile to a watched dir and symlink it back, e.g.
#
#  $ mkdir config
#  $ mv Guardfile config/
#  $ ln -s config/Guardfile .
#
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"

cucumber_options = {
  # Below are examples overriding defaults

  # cmd: 'bin/cucumber',
  # cmd_additional_args: '--profile guard',

  # all_after_pass: false,
  # all_on_start: false,
  # keep_failed: false,
  # feature_sets: ['features/frontend', 'features/experimental'],

  # run_all: { cmd_additional_args: '--profile guard_all' },
  # focus_on: { 'wip' }, # @wip
  # notification: false
}

guard "cucumber", cucumber_options do
  watch(%r{^features/.+\.feature$})
  watch(%r{^features/support/.+$}) { "features" }

  watch(%r{^features/step_definitions/(.+)_steps\.rb$}) do |m|
    Dir[File.join("**/#{m[1]}.feature")][0] || "features"
  end
end
> rm Guardfile
> bundle exec guard init guard-cucumber
13:40:38 - INFO - Writing new Guardfile to /Users/stephan/dev/tmp/gaincute/Guardfile
13:40:38 - ERROR - Could not load 'guard/guard-cucumber' or '~/.guard/templates/guard-cucumber' or find class Guard::Guardcucumber
> [#]
> cat Guardfile
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

## Uncomment and set this to only include directories you want to watch
# directories %w(app lib config test spec features) \
#  .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}

## Note: if you are using the `directories` clause above and you are not
## watching the project directory ('.'), then you will want to move
## the Guardfile to a watched dir and symlink it back, e.g.
#
#  $ mkdir config
#  $ mv Guardfile config/
#  $ ln -s config/Guardfile .
#
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"

So, when not running in a bundler context it seems to work. However, now I really wonder why it doesn't work, when using bundler.

kisp commented 8 months ago

Hi,

I did a git bisect between v2.1.2 and master (03949aad0df4785b540302192985dcba8bb84b15).

I am talking here also about the error that occurs when running RUN bundle exec guard init guard-cucumber:

 > [myapp 7/8] RUN bundle exec guard init guard-cucumber:
0.917 11:59:43 - INFO - Writing new Guardfile to /app/Guardfile
1.123 11:59:43 - ERROR - Could not load 'guard/guard-cucumber' or '~/.guard/templates/guard-cucumber' or find class Guard::Guardcucumber
1.123 > [#]

The commit 4c7d0e4a99c24526fc78bd455514c6d3614ef0fd was found to cause this error: move guard-compat to a development dependency

This changes guard-compat in the Gemfile from being a normal dependency to being a development dependency.

kisp commented 8 months ago

@todd-a-jacobs I am not sure what the implications of reverting the commit 4c7d0e4a99c24526fc78bd455514c6d3614ef0fd would be.

I did revert the commit in #43 and the problem (the Error message mentioned above) goes away.