rspec causes issues when using action generator

Hi,

I’m running into strange issue when using the action generator with Hanami 2.3. I’ve searched on the github issues for hanami-rspec and here as well, but can’t find nothing similar. I’m guessing it’s again something with my setup.

I’m using Ruby 3.3.2 and Hanami 2.3.

Here are the 3 outputs I get with 3 different commands. It doesn’t matter if I omit the -skipp* options.

The views and the templates get generated, but specs don’t.

On a side note, the getting started guide specifies the `bin/hanami generate` command, while, the docs for generate specify the `bundle exec hanami generate`. The later breaks with a different error, but still breaks.

bin/hanami generate action home.index --skip-route --skip-tests
Created app/actions/home/index.rb
Created app/views/home/index.rb
Created app/templates/home/index.html.erb
/home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/hanami-rspec-2.3.0/lib/hanami/rspec/commands.rb:131:in `call': wrong number of arguments (given 0, expected 1) (ArgumentError)
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/hanami-cli-2.3.3/lib/hanami/cli/commands/app/command.rb:46:in `call'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.0/lib/dry/cli/command_registry.rb:258:in `instance_exec'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.0/lib/dry/cli/command_registry.rb:258:in `block in run'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/3.3.0/set.rb:501:in `each_key'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/3.3.0/set.rb:501:in `each'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.0/lib/dry/cli/command_registry.rb:257:in `run'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.0/lib/dry/cli.rb:125:in `perform_registry'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.0/lib/dry/cli.rb:66:in `call'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/hanami-cli-2.3.3/exe/hanami:11:in `<top (required)>'
	from bin/hanami:27:in `load'
	from bin/hanami:27:in `<main>'



bin/hanami generate action home1.index --skip-tests
Updated config/routes.rb
Created app/actions/home1/index.rb
Created app/views/home1/index.rb
Created app/templates/home1/index.html.erb
/home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/hanami-rspec-2.3.0/lib/hanami/rspec/commands.rb:131:in `call': wrong number of arguments (given 0, expected 1) (ArgumentError)
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/hanami-cli-2.3.3/lib/hanami/cli/commands/app/command.rb:46:in `call'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.0/lib/dry/cli/command_registry.rb:258:in `instance_exec'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.0/lib/dry/cli/command_registry.rb:258:in `block in run'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/3.3.0/set.rb:501:in `each_key'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/3.3.0/set.rb:501:in `each'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.0/lib/dry/cli/command_registry.rb:257:in `run'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.0/lib/dry/cli.rb:125:in `perform_registry'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.0/lib/dry/cli.rb:66:in `call'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/hanami-cli-2.3.3/exe/hanami:11:in `<top (required)>'
	from bin/hanami:27:in `load'
	from bin/hanami:27:in `<main>'


bin/hanami generate action home2.index
Updated config/routes.rb
Created app/actions/home2/index.rb
Created app/views/home2/index.rb
Created app/templates/home2/index.html.erb
/home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/hanami-rspec-2.3.0/lib/hanami/rspec/commands.rb:131:in `call': wrong number of arguments (given 0, expected 1) (ArgumentError)
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/hanami-cli-2.3.3/lib/hanami/cli/commands/app/command.rb:46:in `call'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.0/lib/dry/cli/command_registry.rb:258:in `instance_exec'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.0/lib/dry/cli/command_registry.rb:258:in `block in run'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/3.3.0/set.rb:501:in `each_key'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/3.3.0/set.rb:501:in `each'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.0/lib/dry/cli/command_registry.rb:257:in `run'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.0/lib/dry/cli.rb:125:in `perform_registry'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.0/lib/dry/cli.rb:66:in `call'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/hanami-cli-2.3.3/exe/hanami:11:in `<top (required)>'
	from bin/hanami:27:in `load'
	from bin/hanami:27:in `<main>'

Edit START

Here is the `bundle exec` command error:

bundle exec hanami generate action home3.index --skip-route --skip-tests
Created app/actions/home3/index.rb
Created app/views/home3/index.rb
Created app/templates/home3/index.html.erb
bundler: failed to load command: hanami (/home/sebastjan/.rbenv/versions/3.3.2/bin/hanami)
/home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/hanami-rspec-2.3.0/lib/hanami/rspec/commands.rb:131:in `call': wrong number of arguments (given 0, expected 1) (ArgumentError)
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/hanami-cli-2.3.3/lib/hanami/cli/commands/app/command.rb:46:in `call'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.0/lib/dry/cli/command_registry.rb:258:in `instance_exec'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.0/lib/dry/cli/command_registry.rb:258:in `block in run'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/3.3.0/set.rb:501:in `each_key'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/3.3.0/set.rb:501:in `each'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.0/lib/dry/cli/command_registry.rb:257:in `run'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.0/lib/dry/cli.rb:125:in `perform_registry'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.0/lib/dry/cli.rb:66:in `call'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/hanami-cli-2.3.3/exe/hanami:11:in `<top (required)>'
	from /home/sebastjan/.rbenv/versions/3.3.2/bin/hanami:25:in `load'
	from /home/sebastjan/.rbenv/versions/3.3.2/bin/hanami:25:in `<top (required)>'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/3.3.0/bundler/cli/exec.rb:58:in `load'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/3.3.0/bundler/cli/exec.rb:58:in `kernel_load'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/3.3.0/bundler/cli/exec.rb:23:in `run'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/3.3.0/bundler/cli.rb:451:in `exec'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/3.3.0/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/3.3.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/3.3.0/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/3.3.0/bundler/cli.rb:34:in `dispatch'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/3.3.0/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/3.3.0/bundler/cli.rb:28:in `start'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.5.9/exe/bundle:28:in `block in <top (required)>'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/3.3.0/bundler/friendly_errors.rb:117:in `with_friendly_errors'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.5.9/exe/bundle:20:in `<top (required)>'
	from /home/sebastjan/.rbenv/versions/3.3.2/bin/bundle:25:in `load'
	from /home/sebastjan/.rbenv/versions/3.3.2/bin/bundle:25:in `<main>'

Edit End

Any ideas about the cause for these?

Thank you. seba

Thanks for reporting. I’ll look into this as soon as I get a chance.

In the meantime, are you able to reproduce this in a fresh app? That’ll let us deduce whether it’s an issue in your local setup.

Hi @cllns,

this was a fresh app. I just created another one, build runs ok. Then cd into the project dir and running `bin/hanami generate action home.index --skip-route --skip-tests` returns:

Created app/actions/home/index.rb
Created app/views/home/index.rb
Created app/templates/home/index.html.erb
/home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/hanami-rspec-2.3.0/lib/hanami/rspec/commands.rb:131:in `call': wrong number of arguments (given 0, expected 1) (ArgumentError)
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/hanami-cli-2.3.3/lib/hanami/cli/commands/app/command.rb:46:in `call'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.1/lib/dry/cli/command_registry.rb:258:in `instance_exec'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.1/lib/dry/cli/command_registry.rb:258:in `block in run'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/3.3.0/set.rb:501:in `each_key'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/3.3.0/set.rb:501:in `each'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.1/lib/dry/cli/command_registry.rb:257:in `run'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.1/lib/dry/cli.rb:125:in `perform_registry'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/dry-cli-1.4.1/lib/dry/cli.rb:66:in `call'
	from /home/sebastjan/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/hanami-cli-2.3.3/exe/hanami:11:in `<top (required)>'
	from bin/hanami:27:in `load'
	from bin/hanami:27:in `<main>'

Looks like this is a bug introduced with dry-cli 1.4.0. I’m sorry about that, @sebastjan_hribar!

If you put this in your Gemfile and re-bundle, you should be good again:

gem "dry-cli", "~> 1.3.0"

I’ll investigate the issue with the newer version of dry-cli and get it fixed ASAP.

Fix PR up here: Update callbacks to support dry-cli 1.3 and 1.4+ by timriley · Pull Request #41 · hanami/hanami-rspec

I’ll do some manual testing tomorrow and if it all looks good, cut a release.

Hi @timriley,

yes, I was just about to post about the comment in hanami-rspec/lib/hanami/rspec/commands.rb at main · hanami/hanami-rspec · GitHub, line 132, which refers to that.

Thank you.

Changing to 1.3.0 for dry-cli solved it. Thank you.

I’ve just released Hanami RSpec 2.3.1 which should fix the issue for either version of Dry CLI :slight_smile:

1 Like