【问题标题】:Using guard with JRuby on Windows fails在 Windows 上使用 JRuby 防护失败
【发布时间】:2012-02-26 20:26:40
【问题描述】:

我正在尝试使用 JRuby 在 Windows 上设置 Guard,我得到了以下输出:

$ guard
You must 'gem install win32console' to use color on Windows
WARNING: You are using Guard outside of Bundler, this is dangerous and could not
 work. Using `bundle exec guard` is safer.
Guard uses Notifu to send notifications.
Guard is now watching at 'C:/Workspace/OE_11/CyberTrack_Rails3'
Guard::RSpec is running, with RSpec 2!

Running all specs
bundler: command not found: rspec
Install missing gem executables with `bundle install`
>

如果我只输入命令“rspec”,一切都会奏效。那么我在这里错过了什么?

$ rspec
←[32m.←[0m←[32m.←[0m←[32m.←[0m←[32m.←[0m←[32m.←[0m←[32m.←[0m←[32m.←[0m←[32m.←[0m


Finished in 1.39 seconds
←[32m8 examples, 0 failures←[0m

我将 rspec.bat 的路径添加到我的 PATH 环境变量中。

顺便说一句,我在 Windows 上工作。在 Ubuntu 上,我很快就能搞定一切......

更新 宝石文件:

source 'https://rubygems.org'

gem 'rails', '3.2.2.rc1'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'activerecord-jdbcsqlite3-adapter'

gem 'jruby-openssl'
gem 'json'

group :development do
    gem 'rspec-rails'
    gem 'guard-rspec'
end

group :test do
    gem 'rspec-rails'
    gem 'guard-rspec'
  gem 'capybara', '1.1.2'
  gem 'rb-fchange', '0.0.5'
  gem 'rb-notifu', '0.0.4'
  #gem 'win32console', '1.3.0'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  gem 'therubyrhino'

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug'

【问题讨论】:

    标签: rspec jruby guard


    【解决方案1】:

    我认为这是一个 bundler 错误,因为如果我运行,我会得到同样的错误:

    bundle exec rspec spec
    

    我设法让它在 guard-rspec 源文件中添加评论和添加一些代码。

    打开文件:

    C:\jruby-1.6.7\lib\ruby\gems\1.8\gems\guard-rspec-0.6.0\lib\guard\rspec\runner.rb
    

    Obs:请注意,此路径在您的机器上可能不同。无论如何,只需转到guard-rspec gem 的源并打开runner.rb 文件即可。

    并将rspec_command 更改为:

      def rspec_command(paths, options={})
        warn_deprectation(options)
    
        cmd_parts = []
        cmd_parts << "rvm #{options[:rvm].join(',')} exec" if options[:rvm].is_a?(Array)
        cmd_parts << "bundle exec" if (bundler? && options[:binstubs] == true && options[:bundler] != false) || (bundler? && options[:bundler] != false)
        cmd_parts << "'"
        cmd_parts << rspec_exec(options)
        cmd_parts << options[:cli] if options[:cli]
        cmd_parts << "-f progress" if options[:cli].nil? || !options[:cli].split(/[\s=]/).any? { |w| %w[-f --format].include?(w) }
        #cmd_parts << "-r #{File.dirname(__FILE__)}/formatters/notification_#{rspec_class.downcase}.rb -f Guard::RSpec::Formatter::Notification#{rspec_class}#{rspec_version == 1 ? ":" : " --out "}/dev/null" if options[:notification] != false
        cmd_parts << "--failure-exit-code #{failure_exit_code}" if failure_exit_code_supported?(options)
    
        cmd_parts << paths.join(' ')
        cmd_parts << "'"
    
        cmd_parts.join(' ')
      end
    

    我所做的更改:

     1. commented on of the lines
     2. Added 2 code line to add "quotes" to the string builder.
    

    它在这里工作,所以它也应该在你的机器上工作。 我在 bundler https://github.com/carlhuda/bundler/issues/1689 上为此问题打开一个问题。

    【讨论】:

    • 仍然出现同样的错误...但是,我追踪 cmd_parts 并显示: bundle exec rspec -f progress --failure-exit-code 2 spec spec' 现在,如果我运行 bundle exec rspec spec,我收到错误:bundler: command not found: rspec ... 也许这是有不同的原因? rspec 规范工作正常, bundle exec rspec 规范不起作用。 (在 Windows 上)。
    • 查看了 github,确实, bundle exec "rspec spec" 工作正常。奇怪的。 Guard 然而仍然不起作用,但我只是看到我忘了添加一行......
    • 谢谢,现在工作正常,同时我学会了如何调试 gem。
    • 顺便说一句,与 bundle exec spork --bootstrap 完全相同的问题。 bundle exec "spork --bootstrap" 工作正常。
    • 我所做的就是运行 make guard-rspec 使用引号运行代码。您是否对我的代码进行了任何更改以使其在您的机器上运行?如果是这样,请在此处发布,以便对其他人有所帮助。 =]
    猜你喜欢
    • 2014-11-01
    • 1970-01-01
    • 2011-05-08
    • 2023-03-10
    • 2018-09-18
    • 1970-01-01
    • 2015-07-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多