File.dirname在ruby 2.2.3中返回错误的路径

时间:2016-02-21 19:11:11

标签: ruby-on-rails ruby rspec

在Rails 4.2.0 / ruby​​ 2.2.3平台上安装rspec时,会产生错误:

std::vector

问题出在以下几行:

$ rails g rspec:install
   identical  .rspec
       exist  spec
      create  spec/C:/Users/Jun C/AppData/Local/Temp/d20160221-13928-5s67uj/spec/spec_helper.rb
C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:252:in `mkdir': Invalid argument @ dir_s_mkdir - C:/D/code/rails_proj/engines/simple_projectx/spec/C: (Errno::EINVAL)
        from C:/Ruby22-x64/lib/ruby/2.2.0/fileutils.rb:252:in `fu_mkdir'

此处create spec/C:/Users/Jun C/AppData/Local/Temp/d20160221-13928-5s67uj/spec/spec_helper.rb 应指向Rails app root下的spec子目录,即spec/C:/Users/Jun C/AppData/Local/Temp/d20160221-13928-5s67uj。正确的路径应该是:

C:/d/code/rails_proj/engines/simple_projectx/

以下是create C:/d/code/rails_proj/engines/simple_projectx/spec/spec_helper.rb ruby的部分:

fileutils.rb

def mkdir_p(list, options = {}) fu_check_options options, OPT_TABLE['mkdir_p'] list = fu_list(list) fu_output_message "mkdir -p #{options[:mode] ? ('-m %03o ' % options[:mode]) : ''}#{list.join ' '}" if options[:verbose] return *list if options[:noop] list.map {|path| remove_tailing_slash(path)}.each do |path| # optimize for the most common case begin fu_mkdir path, options[:mode] next rescue SystemCallError next if File.directory?(path) end stack = [] until path == stack.last # dirname("/")=="/", dirname("C:/")=="C:/" stack.push path path = File.dirname(path) end stack.reverse_each do |dir| begin fu_mkdir dir, options[:mode] rescue SystemCallError raise unless File.directory?(dir) end end end return *list end module_function :mkdir_p alias mkpath mkdir_p alias makedirs mkdir_p module_function :mkpath module_function :makedirs OPT_TABLE['mkdir_p'] = OPT_TABLE['mkpath'] = OPT_TABLE['makedirs'] = [:mode, :noop, :verbose] def fu_mkdir(path, mode) #:nodoc: path = remove_tailing_slash(path) if mode Dir.mkdir path, mode File.chmod mode, path else Dir.mkdir path #line #252 which causes error end end ..................... 是导致错误的行。如何让Dir.mkdir path提交正确的ruby

1 个答案:

答案 0 :(得分:0)

我认为您应该从官方RSpec存储库获得支持:https://github.com/rspec/rspec-rails