Bee C0 Coverage Information - RCov

lib/bee_version_dependant.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/bee_version_dependant.rb 132 77
80.30%
76.62%

Key

Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.

Coverage Details

1 #!/usr/bin/env ruby
2 
3 # Copyright 2006-2012 Michel Casabianca <michel.casabianca@gmail.com>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 module Bee
18 
19   module VersionDependant
20 
21     # Convert a string to a version number (array of integers). Thus will turn
22     # '1.2.3' to [1, 2, 3].
23     def self.to_version(string)
24       return string.split('.').map{|s| s.to_i}
25     end
26 
27     # Compares two versions.
28     # Returns:
29     # - < 0 if first is lower than second.
30     # - > 0 if first is greater than second.
31     # - = 0 if first is equal to second.
32     def self.compare_versions(v1, v2)
33       v1 = to_version(v1) if v1.kind_of?(String)
34       v2 = to_version(v2) if v2.kind_of?(String)
35       return (v1 <=> v2)
36     end
37 
38     # Get Ruby version as an Array.
39     def self.ruby_version()
40       return to_version(RUBY_VERSION)
41     end
42 
43     # Get Gems version.
44     def self.gems_version()
45       return Gem::RubyGemsVersion
46     end
47 
48     # Tells if ruby version is greater than a given string version.
49     def self.ruby_greater_than(version)
50       return compare_versions(ruby_version, to_version(version)) > 0
51     end
52 
53     # Tells if ruby version is lower than a given string version.
54     def self.ruby_lower_than(version)
55       return compare_versions(ruby_version, to_version(version)) < 0
56     end
57 
58     # Tells if ruby version equals a given string version.
59     def self.ruby_equals_to(version)
60       return compare_versions(ruby_version, to_version(version)) == 0
61     end
62 
63     # Tells if a given gem is available.
64     def self.gem_available?(gem)
65       if compare_versions(gems_version, [1, 3, 0]) < 0
66         begin
67           Gem::activate(gem, false)
68           return true
69         rescue LoadError
70           return false
71         end
72       elsif compare_versions(gems_version, [1, 8, 0]) < 0
73         return Gem::available?(gem)
74       else
75         begin
76           Gem::Specification::find_by_name(gem)
77           return true
78         rescue LoadError
79           return false
80         end
81       end
82     end
83 
84     # Find gems with name matching a given pattern. Returns the list of gem
85     # specifications.
86     def self.find_gems(*patterns)
87       gems = []
88       if compare_versions(gems_version, [1, 8, 0]) < 0
89         index = Gem::SourceIndex.from_installed_gems()
90         for pattern in patterns
91           gems += index.find_name(pattern)
92         end
93       else
94         for pattern in patterns
95           Gem::Specification::each do |spec|
96             gems << spec if spec.name =~ pattern
97           end
98         end
99       end
100       return gems.uniq
101     end
102 
103   end
104 
105 end
106 
107 # patch test/unit to disable autorun for Ruby 1.9.2 or 1.9.1
108 if Bee::VersionDependant::ruby_equals_to('1.9.2') or Bee::VersionDependant::ruby_equals_to('1.9.1')
109 
110   require 'minitest/unit'
111 
112   module MiniTest
113 
114     class Unit
115       def self.autorun
116       end
117     end
118 
119   end
120 
121 end
122 
123 # patch test/unit to disable autorun for Ruby 1.9.3
124 if Bee::VersionDependant::ruby_equals_to('1.9.3')
125 
126   require 'test/unit'
127 
128   class Test::Unit::Runner
129     @@stop_auto_run = true
130   end
131 
132 end

Generated on Fri Oct 09 02:07:49 +0200 2015 with rcov 1.0.0