要求&#rs; rspec / autorun' - 对我不起作用

时间:2014-08-02 17:10:34

标签: ruby rspec

谁能告诉我我做错了什么?

~/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

我们走了:

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

2 个答案:

答案 0 :(得分:2)

那是因为错过了RSpec。您应该执行以下操作:

require 'rspec/autorun'

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

答案 1 :(得分:0)

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