bobf / strong_versions

Enforce a strict versioning policy in your Gemfile
MIT License
28 stars 2 forks source link

Standalone usage is not working #2

Open cgeorgii opened 4 years ago

cgeorgii commented 4 years ago

When installing the gem with gem install strong_versions -v '0.4.2' all commands fail with the following information:

$ strong_versions -v                                                            
Traceback (most recent call last):
        6: from /Users/cgeorgii/.rbenv/versions/2.6.5/bin/strong_versions:23:in `<main>'
        5: from /Users/cgeorgii/.rbenv/versions/2.6.5/bin/strong_versions:23:in `load'
        4: from /Users/cgeorgii/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/strong_versions-0.4.2/bin/strong_versions:7:in `<top (required)>'
        3: from /Users/cgeorgii/.rbenv/versions/2.6.5/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        2: from /Users/cgeorgii/.rbenv/versions/2.6.5/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        1: from /Users/cgeorgii/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/strong_versions-0.4.2/lib/strong_versions.rb:25:in `<top (required)>'
/Users/cgeorgii/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/strong_versions-0.4.2/lib/strong_versions.rb:19:in `root': uninitialized constant StrongVersions::Pathname (NameError)

I've cloned the repository to fix it, as it seemed straightforward. The fixes can be seen here.

I would open a pull request, however the specs are not passing (but were not passing before the changes either):

Failures:

  1) StrongVersions::Dependencies#validate! auto-correct auto-corrects gemfile
     Failure/Error: Bundler::LockfileParser.new(Bundler.read_file(Bundler.default_lockfile))

     Errno::ENOENT:
       No such file or directory @ rb_sysopen - /Users/cgeorgii/code/playground/strong_versions/spec/fixtures/Gemfile.lock
     # ./lib/strong_versions/dependency.rb:68:in `default_lockfile'
     # ./lib/strong_versions/dependency.rb:11:in `initialize'
     # ./lib/strong_versions/dependencies.rb:7:in `new'
     # ./lib/strong_versions/dependencies.rb:7:in `block in initialize'
     # ./lib/strong_versions/dependencies.rb:6:in `map'
     # ./lib/strong_versions/dependencies.rb:6:in `initialize'
     # ./spec/strong_versions/dependencies_spec.rb:15:in `new'
     # ./spec/strong_versions/dependencies_spec.rb:15:in `block (2 levels) in <top (required)>'
     # ./spec/strong_versions/dependencies_spec.rb:92:in `block (4 levels) in <top (required)>'

  2) StrongVersions::Dependencies#validate! auto-correct with necessary guard definition leaves necessary guard definition intact
     Failure/Error: Bundler::LockfileParser.new(Bundler.read_file(Bundler.default_lockfile))

     Errno::ENOENT:
       No such file or directory @ rb_sysopen - /Users/cgeorgii/code/playground/strong_versions/spec/fixtures/Gemfile.lock
     # ./lib/strong_versions/dependency.rb:68:in `default_lockfile'
     # ./lib/strong_versions/dependency.rb:11:in `initialize'
     # ./lib/strong_versions/dependencies.rb:7:in `new'
     # ./lib/strong_versions/dependencies.rb:7:in `block in initialize'
     # ./lib/strong_versions/dependencies.rb:6:in `map'
     # ./lib/strong_versions/dependencies.rb:6:in `initialize'
     # ./spec/strong_versions/dependencies_spec.rb:15:in `new'
     # ./spec/strong_versions/dependencies_spec.rb:15:in `block (2 levels) in <top (required)>'
     # ./spec/strong_versions/dependencies_spec.rb:100:in `block (5 levels) in <top (required)>'

Finished in 0.13283 seconds (files took 0.18205 seconds to load)
64 examples, 2 failures

Failed examples:

rspec ./spec/strong_versions/dependencies_spec.rb:90 # StrongVersions::Dependencies#validate! auto-correct auto-corrects gemfile
rspec ./spec/strong_versions/dependencies_spec.rb:99 # StrongVersions::Dependencies#validate! auto-correct with necessary guard definition leaves necessary guard definition intact

I can help if necessary, just let me know how to proceed here.

bobf commented 4 years ago

@cgeorgii Thank you for catching this and for providing all the info + suggested fix.

The reason the tests failed is because Gemfile.lock is in .gitignore so the fixture was never added to Git. I have fixed this issue and also applied your fixes to latest master.

However - I am not sure if standalone usage of StrongVersions would make much sense as it is so tightly integrated with Bundler.

Either way, thanks for the help - those missing require statements were definitely an oversight on my part. : )

I will do a new release in a few days if no other issues come up.

cgeorgii commented 4 years ago

@bobf Glad you acted so quickly and thanks for fixing yourself. It's a very interesting tool and one that made me avoid thinking about an issue I had in the back of my mind for some time: what's the best approach for version declarations in Gemfiles.

Regarding standalone usage - I believe it would be interesting to have the gem work without having to add it to the Gemfile of the project, even if only to allow experimentation. I personally tried to install the gem and run the command at the root of my project.

As an example, this is what I expected to be able to do:

$ gem install strong_versions
Successfully installed strong_versions-0.4.2
Done installing documentation for strong_versions after 0 seconds
1 gem installed

$ ls
Gemfile Gemfile.lock

$ strong_versions
StrongVersions Failure

`http`: [not specified]
  Expected major and minor version or unstable version, e.g. 1.2 or 0.2.3, found: [not specified]
  Suggested: '~> 4.3'

61 gem definitions inspected, 1 issue detected
bobf commented 4 years ago

@cgeorgii Yes - I experienced the same kind of issue when I ran it in standalone mode.

I hadn't thought of using it this way but I can see why it would be useful. The problems are that, since the gem uses Bundler to introspect on the currently-loaded Gemfile, StrongVersions would need to load the Gemfile and it would need to do it using the correct version of Ruby which might be quite difficult. I will take a look, though - if it's not too complicated then it would be a nice feature for sure.