简体   繁体   English

尝试运行rake时出现rspec错误

[英]rspec bugs when trying to run rake

I'm trying to teach myself some ruby using the app academy tutorials and after doing the readings, installing rvm,rubygems and rspec2 when I even try to run the first most basic code (00_hello) with rake I get the whole error : 我正在尝试使用应用程序学院教程来教自己一些红宝石,并在阅读后安装了rvm,rubygems和rspec2,甚至当我尝试用rake运行第一个最基本的代码(00_hello)时,我得到了整个错误:

 (in /home/deadpool/Documents/learn_ruby)
/home/deadpool/Documents/learn_ruby/rspec_config.rb:3:in `block in <top (required)>': undefined method `color=' for #<RSpec::Core::Configuration:0x0000000293dee0> (NoMethodError)
    from /home/deadpool/.rvm/gems/ruby-2.0.0-p481/gems/rspec-core-2.0.0/lib/rspec/core.rb:67:in `configure'
    from /home/deadpool/Documents/learn_ruby/rspec_config.rb:1:in `<top (required)>'
    from /home/deadpool/.rvm/gems/ruby-2.0.0-p481/gems/rspec-core-2.0.0/lib/rspec/core/configuration.rb:162:in `require'
    from /home/deadpool/.rvm/gems/ruby-2.0.0-p481/gems/rspec-core-2.0.0/lib/rspec/core/configuration.rb:162:in `block in requires='
    from /home/deadpool/.rvm/gems/ruby-2.0.0-p481/gems/rspec-core-2.0.0/lib/rspec/core/configuration.rb:162:in `map'
    from /home/deadpool/.rvm/gems/ruby-2.0.0-p481/gems/rspec-core-2.0.0/lib/rspec/core/configuration.rb:162:in `requires='
    from /home/deadpool/.rvm/gems/ruby-2.0.0-p481/gems/rspec-core-2.0.0/lib/rspec/core/configuration_options.rb:22:in `block in configure'
    from /home/deadpool/.rvm/gems/ruby-2.0.0-p481/gems/rspec-core-2.0.0/lib/rspec/core/configuration_options.rb:21:in `each'
    from /home/deadpool/.rvm/gems/ruby-2.0.0-p481/gems/rspec-core-2.0.0/lib/rspec/core/configuration_options.rb:21:in `configure'
    from /home/deadpool/.rvm/gems/ruby-2.0.0-p481/gems/rspec-core-2.0.0/lib/rspec/core/command_line.rb:17:in `run'
    from /home/deadpool/.rvm/gems/ruby-2.0.0-p481/gems/rspec-core-2.0.0/lib/rspec/core/runner.rb:55:in `run_in_process'
    from /home/deadpool/.rvm/gems/ruby-2.0.0-p481/gems/rspec-core-2.0.0/lib/rspec/core/runner.rb:46:in `run'
    from /home/deadpool/.rvm/gems/ruby-2.0.0-p481/gems/rspec-core-2.0.0/lib/rspec/core/runner.rb:10:in `block in autorun'
rake aborted!
ruby -S bundle exec rspec -I/home/deadpool/Documents/learn_ruby/00_hello -I/home/deadpool/Documents/learn_ruby/00_hello/solution -f documentation -r ./rspec_config "/home/deadpool/Documents/learn_ruby/00_hello/hello_spec.rb" failed
/home/deadpool/.rvm/gems/ruby-2.0.0-p481/gems/rspec-core-2.0.0/lib/rspec/core/rake_task.rb:117:in `rescue in block (2 levels) in initialize'
/home/deadpool/.rvm/gems/ruby-2.0.0-p481/gems/rspec-core-2.0.0/lib/rspec/core/rake_task.rb:113:in `block (2 levels) in initialize'
/home/deadpool/.rvm/gems/ruby-2.0.0-p481/gems/rspec-core-2.0.0/lib/rspec/core/rake_task.rb:109:in `block in initialize'
Tasks: TOP => default => spec
(See full trace by running task with --trace)

I tried to google some of the errors, but with no success. 我试图用Google搜索一些错误,但没有成功。 I had previously another error with the rake file using rspec v2 and the current version is 3.0.0, so I had to install the older and I think it might be another setup problem. 我以前使用rspec v2的rake文件遇到另一个错误,当前版本是3.0.0,所以我必须安装较旧的版本,我认为这可能是另一个设置问题。 Thanks if someone can help me or direct me. 谢谢有人帮助我或指导我。

rspec_config.rb file : rspec_config.rb文件:

RSpec.configure do |c|
    c.fail_fast = true
    c.color = true
end

hello.rb file: hello.rb文件:

def hello
   "Hello!"
end

def greet(who)
   "Hello, #{who}!"
end

UPDATE UPDATE

Getting new error as :- 得到新的错误为:-

While I changed c.color = true to c.color_enabled = true 当我将c.color = true更改为c.color_enabled = true

(in /home/deadpool/Documents/learn_ruby)
the hello function says hello (FAILED - 1)

Failures: 1) the hello function says hello Failure/Error: 
Unable to find matching line from backtrace undefined method run_all' for []:Array 
# /home/deadpool/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.0.0/lib/rspec/core/hooks.rb:116:inrun_hook_filtered' 
# /home/deadpool/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.0.0/lib/rspec/core/example_group.rb:176:in eval_before_alls'
# /home/deadpool/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.0.0/lib/rspec/core/example_group.rb:231:inrun'
# /home/deadpool/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.0.0/lib/rspec/core/command_line.rb:26:in block (2 levels) in run'
# /home/deadpool/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.0.0/lib/rspec/core/command_line.rb:26:inmap'
# /home/deadpool/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.0.0/lib/rspec/core/command_line.rb:26:in block in run' 
# /home/deadpool/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.0.0/lib/rspec/core/reporter.rb:11:inreport'
# /home/deadpool/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.0.0/lib/rspec/core/command_line.rb:23:in run' 
# /home/deadpool/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.0.0/lib/rspec/core/runner.rb:55:inrun_in_process' 
# /home/deadpool/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.0.0/lib/rspec/core/runner.rb:46:in run'
# /home/deadpool/.rvm/gems/ruby-2.1.2/gems/rspec-core-2.0.0/lib/rspec/core/runner.rb:10:inblock in autorun'

UPDATE UPDATE

hello_spec.rb file : hello_spec.rb文件:

require "hello"

describe "the hello function" do
  it "says hello" do
    hello.should == "Hello!"
  end
end

describe "the greet function" do
  it "says hello to someone" do
    greet("Alice").should == "Hello, Alice!"
  end

  it "says hello to someone else" do
    greet("Bob").should == "Hello, Bob!"
  end
end

UPDATE So, I updated rspec to v3.0.0 and changed Rakefile gem 'rspec', '~>3.0.0' and c.color = true back. 更新因此,我将rspec更新为v3.0.0,并更改了Rakefile gem'rspec gem 'rspec', '~>3.0.0'c.color = true Everything is working now(getting some deprecation warnings, but nothing critical), getting the output that is in the tutorial. 现在一切正常(获取一些弃用警告,但没有什么紧要关头),获得本教程中的输出。 Guess I just had to updae my rspec and change the version in the Rakefile. 猜猜我只需要更新我的rspec并更改Rakefile中的版本。 Thank you so much :) 非常感谢 :)

Your error log is showing you are in rspec-core-2.0.0 version and your error is saying - 您的错误日志显示您使用的是rspec-core-2.0.0版本,并且您的错误是-

rspec_config.rb:3:in `block in <top (required)>': undefined method `color=' for 
#<RSpec::Core::Configuration:0x0000000293dee0> (NoMethodError)

Now Deprecate config options confirms that below versions of 2.99.0.rc1 / 2014-05-18 or 2.99.0 methods were - #color_enabled , #color_enabled= and #color? 现在弃用的配置选项确认,以下的2.99.0.rc1 / 2014年5月18日2.99.0方法版本是- #color_enabled#color_enabled=#color? . Which are changed since 2.99.0 to #color , #color= and #color_enabled? 因为2.99.0哪家改变#color#color=#color_enabled? .

I got the information from the changelog as I linked - 链接时,我从变更日志中获得了信息-

Deprecate #color_enabled, #color_enabled= and #color? 弃用#color_enabled,#color_enabled =和#color? in favour of #color, #color= and #color_enabled? 支持#color,#color =和#color_enabled? output. 输出。 (Jon Rowe) (乔恩·罗)

Thus you need to write as 因此,您需要写成

RSpec.configure do |c|
    c.fail_fast = true
    c.color_enabled = true
end

Regarding your new error, I found it as a bug undefined method run_all' for []:Array` . 关于您的新错误,我发现它是[]:Array`bug undefined method run_all' Which has been fixed in this patch . 该补丁已修复该问题 Check this Rspec issue . 检查此Rspec问题

My suggestion use Rspec 3.0 , at least you will be happy. 我的建议使用Rspec 3.0 ,至少您会满意的。 In this case revert the color_enabled to color . 在这种情况下,将color_enabled还原为color

Hope this would help you. 希望这对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM