if the name and version methods haven't been called, the instance
variables will not be initialized, and calling to_spec will warn. This
ensures that the data has actually been loaded before looping through
the loaded specs.
# The full Gem::Specification for this gem, loaded from evalling its gemspec
def to_spec
- @spec ||= Gem.loaded_specs.values.find { |spec|
- spec.name == @name and spec.version == @version
- }
+ @spec ||= if @data then
+ Gem.loaded_specs.values.find { |spec|
+ spec.name == name and spec.version == version
+ }
+ end
@spec ||= Gem::Specification.load(loaded_from)
@spec.ignored = @ignored if instance_variable_defined? :@ignored
assert_same real_foo, @foo.to_spec
end
+ def test_to_spec_with_other_specs_loaded_does_not_warn
+ real_foo = util_spec @foo.name, @foo.version
+ real_foo.activate
+ bar = Gem::StubSpecification.new BAR
+ refute_predicate Gem.loaded_specs, :empty?
+ assert bar.to_spec
+ end
+
def test_to_spec_activated
assert @foo.to_spec.is_a?(Gem::Specification)
assert_equal "foo", @foo.to_spec.name