Last active
August 29, 2015 14:05
-
-
Save xiangzhuyuan/e236f75f6d3411233b91 to your computer and use it in GitHub Desktop.
I want to get know the initialize process of rspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the following snippt is script registered into command | |
#! ruby | |
# | |
# This file was generated by RubyGems. | |
# | |
# The application 'rspec-core' is installed as part of a gem, and | |
# this file is here to facilitate running it. | |
# | |
require 'rubygems' | |
version = ">= 0" | |
if ARGV.first | |
str = ARGV.first | |
str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding | |
if str =~ /\A_(.*)_\z/ | |
version = $1 | |
ARGV.shift | |
end | |
end | |
gem 'rspec-core', version | |
# bin_path ? what is it? | |
load Gem.bin_path('rspec-core', 'rspec', version) | |
###################### rubygem handle the depandency ################ | |
## | |
# Find the full path to the executable for gem +name+. If the +exec_name+ | |
# is not given, the gem's default_executable is chosen, otherwise the | |
# specified executable's path is returned. +requirements+ allows | |
# you to specify specific gem versions. | |
def self.bin_path(name, exec_name = nil, *requirements) | |
# TODO: fails test_self_bin_path_bin_file_gone_in_latest | |
# Gem::Specification.find_by_name(name, *requirements).bin_file exec_name | |
raise ArgumentError, "you must supply exec_name" unless exec_name | |
requirements = Gem::Requirement.default if | |
requirements.empty? | |
# new depency | |
specs = Gem::Dependency.new(name, requirements).matching_specs(true) | |
raise Gem::GemNotFoundException, | |
"can't find gem #{name} (#{requirements})" if specs.empty? | |
specs = specs.find_all { |spec| | |
spec.executables.include? exec_name | |
} if exec_name | |
unless spec = specs.last | |
msg = "can't find gem #{name} (#{requirements}) with executable #{exec_name}" | |
raise Gem::GemNotFoundException, msg | |
end | |
spec.bin_file exec_name | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment