File tree Expand file tree Collapse file tree 3 files changed +17
-12
lines changed Expand file tree Collapse file tree 3 files changed +17
-12
lines changed Original file line number Diff line number Diff line change 11module GemEmpty
2+ # monkey patch rubygems specification to easily find gem version
23 module Specification
34 def self . installed_gems
45 if
@@ -9,11 +10,12 @@ def self.installed_gems
910 Gem . source_index . map { |name , spec | spec }
1011 end
1112 end
12- def self . find ( name = "gem-empty" )
13- @gem_empty_spec ||= installed_gems . find { |spec | spec . name == name }
13+ def self . find_gem_spec ( name )
14+ installed_gems . find { |spec | spec . name == name }
1415 end
15- def self . version
16- find ? find . version . to_s : nil
16+ def self . gem_loaded? ( name , version )
17+ spec = find_gem_spec ( name )
18+ spec && spec . version . to_s == version
1719 end
1820 end
1921end
Original file line number Diff line number Diff line change 55
66# continue only if loaded and called versions all the same, and not shared gems disabled in bundler
77if
8- ( $:. include? ( called_path ) || GemEmpty ::Specification . version == called_version ) and
8+ ( $:. include? ( called_path ) || GemEmpty ::Specification . gem_loaded? ( "gem-empty" , called_version ) ) and
99 ( !defined? ( Bundler ) || ( defined? ( Bundler ) && Bundler ::SharedHelpers . in_bundle? && !Bundler . settings [ :disable_shared_gems ] ) )
10-
10+ then
1111 require 'gem-empty/command'
1212 Gem ::CommandManager . instance . register_command :empty
13-
1413end
Original file line number Diff line number Diff line change 99 end
1010
1111 it "finds specification" do
12- GemEmpty ::Specification . find ( "gem-empty" ) . name . must_equal ( "gem-empty" )
12+ GemEmpty ::Specification . find_gem_spec ( "gem-empty" ) . name . must_equal ( "gem-empty" )
1313 end
1414
15- it "gets specification version " do
16- GemEmpty ::Specification . version . must_equal ( GemEmpty :: VERSION )
15+ it "does not find imaginary gems " do
16+ GemEmpty ::Specification . find_gem_spec ( "imaginary-gem" ) . must_equal ( nil )
1717 end
1818
19- it "does not find imaginary gems" do
20- GemEmpty ::Specification . find ( "imaginary-gem" ) . must_equal ( nil )
19+ it "confirms specification version" do
20+ GemEmpty ::Specification . gem_loaded? ( "gem-empty" , GemEmpty ::VERSION ) . must_equal true
21+ end
22+
23+ it "does not confirms specification version" do
24+ GemEmpty ::Specification . gem_loaded? ( "gem-empty" , "0.0.0" ) . wont_equal true
2125 end
2226
2327end
You can’t perform that action at this time.
0 commit comments