Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Detecting duplicate dependencies in specification doesn't distinguish between runtime and development dependencies #1032
03dbac9 (released in 2.2.0) introduced a feature where rubygems would error if a dependency was specified twice in a gem specification.
I think it might be too strict however as it doesn't seem to distinguish between runtime dependencies and development dependencies. It's not hard to come up with a scenario where a runtime dependency could be less strict than a development dependency and so you would want to specify the dependency twice.
For example: I work at a company that publishes a gem that provides some new matchers for rspec. The matchers work in any version of rspec, but our own specs for the gem are written against rspec 3. I'd expect to be able to specify that dependency graph as follows:
Gem::Specification.new do |gem| gem.add_runtime_dependency('rspec') gem.add_development_dependency('rspec', '>= 3.0') end
That it suggests the solution is to replace my
I think it would make sense to collect the
I'm happy to take a shot at working this up as a PR if you think it sounds like a good idea.
added a commit
this pull request
Sep 30, 2014
I agree with this bug report, but it should still report an error if the two requirements are not compatible.
I like your proposed solution and would appreciate a pull request. There should be adequate tests for you to work from, let me know here if you need extra assistance.
How's this? I appreciate the change is a bit noisy, but I ended up moving some things around so that raising an error would show all the error conditions rather than failing at the first hurdle. Let me know if you'd rather I a) didn't, b) did it in separate commits, c) something else.
You suggested that it still reports an error if the two requirements are not compatible so I wrote the following test:
def test_validate_dependencies_disallow_incompatible_runtime_vs_development_duplicates util_setup_validate Dir.chdir @tempdir do @a1.add_runtime_dependency 'b', '< 1.2.3' @a1.add_development_dependency 'b', '>= 1.2.3' use_ui @ui do e = assert_raises Gem::InvalidSpecificationException do @a1.validate end end assert_equal '', @ui.error, 'warning' end end
However, when digging into the
@a1.add_runtime_dependency 'b', '< 1.2.3', '>= 1.2.3'
It still wouldn't raise. I even tried doing
I like your change. I'll merge this when I can next get some time.
Since RubyGems doesn't already complain about dependencies that are impossible to install I guess that should be a separate bug/pull request. Adding it to this one doesn't maintain topical consistency, IMO.