piotrmurach / tty

Toolkit for developing sleek command line apps.
https://ttytoolkit.org
MIT License
2.5k stars 78 forks source link

integration tests don't work ootb #58

Open matti opened 4 years ago

matti commented 4 years ago
$ teletype new test-cmd
# remove todos from gemspec
$ teletype add config
$ rake
  1) `test-cmd config` command executes `test-cmd help config` command successfully
     Failure/Error: output = `test-cmd help config`

     Errno::ENOENT:
       No such file or directory - test-cmd

"fix" by prefixing runner to use exe/test-cmd :

RSpec.describe "`test-cmd config` command", type: :cli do
  it "executes `test-cmd help config` command successfully" do
    output = `exe/test-cmd help config`
piotrmurach commented 4 years ago

Hi Matti,

Thanks for using tty and reporting this.

In my experience, you get this behaviour due to git not tracking the files in newly generated project. Adding exe directory to staged files makes git aware of the folder, meaning, gemspec can locate the executable and your specs should run fine. In near future, I will improve this experience by stoping to rely on git for loading files. Trust me I want to provide a very good experience out of the gate. For now I'm creating a roadmap of how tty v1.0 may look like.

slowbro commented 3 years ago

For me, even having git added and even committed, I get the same error:

  1) `test-app test` command executes `test-app help test` command successfully
     Failure/Error: output = `test-app help test`

     Errno::ENOENT:
       No such file or directory - test-app
     # ./spec/integration/test_spec.rb:3:in ``'
     # ./spec/integration/test_spec.rb:3:in `block (2 levels) in <top (required)>'

To me, it seems like a PATH issue. If I were to install the gem, it would probably work - but that means it could possibly be testing against a different version of my app, and not the code itself.

However, while looking more into this, I realized that I probably missed a step somewhere. When trying to execute the app with bundle exec test-app, I got:

[katelyn@h test-app]$ bundler exec test-app
Traceback (most recent call last):
    2: from /home/katelyn/.rvm/rubies/ruby-2.6.5/bin/bundler:23:in `<main>'
    1: from /home/katelyn/.rvm/rubies/ruby-2.6.5/lib/ruby/site_ruby/2.6.0/rubygems.rb:303:in `activate_bin_path'
/home/katelyn/.rvm/rubies/ruby-2.6.5/lib/ruby/site_ruby/2.6.0/rubygems.rb:284:in `find_spec_for_exe': Could not find 'bundler' (1.17.3) required by your /home/katelyn/code/test-app/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:1.17.3`

Then:

[katelyn@h test-app]$ bundler exec test-app
bundler: command not found: test-app
Install missing gem executables with `bundle install`

Once I did a bundle-install, the integration test passed, since test-app was now found by bundler. As someone who has not used bundler before, I wasn't aware of the pre-requisites so likely that is how I ended up with this. Is there some way to have bundler look around in the base project dir even if bundler install has not been ran, or is that an anti-pattern for bundler?