运行rspec宝石

时间:2011-10-27 19:08:51

标签: ruby-on-rails rubygems rspec

当我运行$ rspec spec /我收到此错误:

You must use ANSICON 1.31 or later (http://adoxa.110mb.com/ansicon/) to use colour on Windows
C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.18/lib/bundler/runtime.rb:31:in `block in setup': You have already activated rspec-core 2.7.1,but your Gemfile requires rspec-core 2.0.1. Consider using bundle exec. (Gem::LoadError) from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.18
/lib/bundler/runtime.rb:17:in `setup'
    from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.18
/lib/bundler.rb:107:in `setup'
    from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.18
/lib/bundler/setup.rb:7:in `<top (required)>'
    from C:/RailsInstaller/Ruby1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custo
m_require.rb:59:in `require'
    from C:/RailsInstaller/Ruby1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custo
m_require.rb:59:in `rescue in require'
    from C:/RailsInstaller/Ruby1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custo
m_require.rb:35:in `require'
    from c:/Sites/app2/config/boot.rb:6:in `<top (required)>'
    from C:/RailsInstaller/Ruby1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custo
m_require.rb:36:in `require'
    from C:/RailsInstaller/Ruby1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custo
m_require.rb:36:in `require'
    from c:/Sites/app2/config/application.rb:1:in `<top (required)>'
    from C:/RailsInstaller/Ruby1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custo
m_require.rb:36:in `require'
    from C:/RailsInstaller/Ruby1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custo
m_require.rb:36:in `require'
    from c:/Sites/app2/config/environment.rb:2:in `<top (required)>'
    from C:/RailsInstaller/Ruby1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custo
m_require.rb:36:in `require'
    from C:/RailsInstaller/Ruby1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custo
m_require.rb:36:in `require'
    from c:/Sites/app2/spec/spec_helper.rb:3:in `<top (required)>'
    from C:/RailsInstaller/Ruby1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custo
m_require.rb:36:in `require'
    from C:/RailsInstaller/Ruby1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custo
m_require.rb:36:in `require'
    from c:/Sites/app2/spec/controllers/pages_controller_spec.rb:1:in `<top
(required)>'
    from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7
.1/lib/rspec/core/configuration.rb:459:in `load'
    from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7
.1/lib/rspec/core/configuration.rb:459:in `block in load_spec_files'
    from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7
.1/lib/rspec/core/configuration.rb:459:in `map'
    from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7
.1/lib/rspec/core/configuration.rb:459:in `load_spec_files'
    from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7
.1/lib/rspec/core/command_line.rb:18:in `run'
    from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7
.1/lib/rspec/core/runner.rb:80:in `run_in_process'
    from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7
.1/lib/rspec/core/runner.rb:69:in `run' from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:10:in `block in autorun'k in autorun'

我安装了rspec和rspec-core:

捆绑show rspec

C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-2.0.1

捆绑show rspec-core

C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1

运行rspec需要做什么?

1 个答案:

答案 0 :(得分:2)

嗯,解决方案正确在错误消息中:

  

考虑使用bundle exec。

所以你输入:

$ bundle exec rspec spec/

但这是要输入的字符数的两倍!不能那样!所以考虑bundle install --binstubs

这样做一次:

$ bundle install --binstubs          

现在这个“正常”

$ rspec spec/