简体   繁体   English

需要'rspec / autorun'-对我不起作用

[英]require 'rspec/autorun' — doesnt work for me

Can anyone tell me what I'm doing wrong? 谁能告诉我我在做什么错?

~/ruby_programs$ rspec --version
3.0.3

~/ruby_programs$ ruby --version
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin10.0]



~/ruby_programs$ cat my_rspec.rb
require 'rspec/autorun'

describe "require 'rspec/autorun'" do
  it 'should not cause this program to throw an error' do
    true
  end

end

~/ruby_programs$ rspec my_rspec.rb 
.

Deprecation Warnings:

Requiring `rspec/autorun` when running RSpec via the `rspec` command is deprecated. Called from /Users/7stud/ruby_programs/my_rspec.rb:1:in `<top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.

1 deprecation warning total

Finished in 0.00159 seconds (files took 0.16241 seconds to load)
1 example, 0 failures

Here we go: 开始了:

~/ruby_programs$ ruby my_rspec.rb
my_rspec.rb:3:in `<main>': undefined method `describe' for main:Object (NoMethodError)

That's because RSpec is missed. 那是因为错过了RSpec You should do the following: 您应该执行以下操作:

require 'rspec/autorun'

RSpec.describe "require 'rspec/autorun'" do
  it 'should not cause this program to throw an error' do
    true
  end
end

尝试使用$ bundle exec rspec而不是仅rspec执行rspec

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

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