Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用RSpec进行Ruby测试_Ruby_Rspec - Fatal编程技术网

用RSpec进行Ruby测试

用RSpec进行Ruby测试,ruby,rspec,Ruby,Rspec,我正在尝试使用Rspec和Bundler进行一些简单的ruby(没有rails)测试。 从命令行im running$bundle exec rspec spec/hello\u example.rb 我没有收到指向spec_helper.rb文件的方法错误,如下所示: /Users/rockyboy/test-ruby/spec/spec/spec_helper.rb:31:in `block (2 levels) in <top (required)>': undefined

我正在尝试使用Rspec和Bundler进行一些简单的ruby(没有rails)测试。 从命令行im running
$bundle exec rspec spec/hello\u example.rb

我没有收到指向spec_helper.rb文件的方法错误,如下所示:

 /Users/rockyboy/test-ruby/spec/spec/spec_helper.rb:31:in `block (2 levels) in <top (required)>': undefined method `include_chain_clauses_in_custom_matcher_descriptions=' for #<RSpec::Expectations::Configuration:0x007fa91115dee0> (NoMethodError)
    from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:580:in `expect_with'
    from /Users/rockyboy/test-ruby/spec/spec/spec_helper.rb:23:in `block in <top (required)>'
    from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.99.1/lib/rspec/core.rb:154:in `configure'
    from /Users/rockyboy/test-ruby/spec/spec/spec_helper.rb:19:in `<top (required)>'
    from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1036:in `require'
    from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1036:in `block in setup_load_path_and_require'
    from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1036:in `each'
    from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1036:in `setup_load_path_and_require'
    from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1036:in `each'
    from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1036:in `setup_load_path_and_require'
    from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.99.1/lib/rspec/core/configuration_options.rb:25:in `configure'
    from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.99.1/lib/rspec/core/command_line.rb:17:in `run'
    from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.99.1/lib/rspec/core/runner.rb:103:in `run'
    from /Library/Ruby/Gems/2.0.0/gems/rspec-core-2.99.1/lib/rspec/core/runner.rb:17:in `block in autorun'`   
/Users/rockyboy/test ruby/spec/spec/spec\u helper.rb:31:in'block(2层)in':未定义的方法'include_chain_子句_in_custom_matcher_description='for#(NoMethodError)
from/Library/Ruby/Gems/2.0.0/Gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:580:in'expect_with'
from/Users/rockyboy/test-ruby/spec/spec/spec\u-helper.rb:23:in'block-in'
from/Library/Ruby/Gems/2.0.0/Gems/rspec-core-2.99.1/lib/rspec/core.rb:154:in'configure'
from/Users/rockyboy/test ruby/spec/spec/spec\u helper.rb:19:in`'
from/Library/Ruby/Gems/2.0.0/Gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1036:in'require'
from/Library/Ruby/Gems/2.0.0/Gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1036:in `设置中的块加载路径和要求'
from/Library/Ruby/Gems/2.0.0/Gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1036:in'each'
from/Library/Ruby/Gems/2.0.0/Gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1036:in“setup\u load\u path\u and\u require”
from/Library/Ruby/Gems/2.0.0/Gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1036:in'each'
from/Library/Ruby/Gems/2.0.0/Gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1036:in“setup\u load\u path\u and\u require”
来自/Library/Ruby/Gems/2.0.0/Gems/rspec-core-2.99.1/lib/rspec/core/configuration_options.rb:25:in“configure”
from/Library/Ruby/Gems/2.0.0/Gems/rspec-core-2.99.1/lib/rspec/core/command_-line.rb:17:in'run'
from/Library/Ruby/Gems/2.0.0/Gems/rspec-core-2.99.1/lib/rspec/core/runner.rb:103:in'run'
from/Library/Ruby/Gems/2.0.0/Gems/rspec-core-2.99.1/lib/rspec/core/runner.rb:17:in'block in autorun'
我的计算机上安装了Rpec 2.99版和3.2.3版。Bundler通知我它正在使用2.99版。我猜我必须切换Bundler,让它使用Rspec版本3.2.3。谁能告诉我如何确保Bundler运行的是3.2.3版。或者其他我可以解决这个问题的方法。非常感谢你

在项目根目录中创建:

source "http://rubygems.org"
gem "rspec", '~> 3.2.3'

你好,谢谢你的回答。我以前也在bundler网站上通过Your's链接阅读过这篇文章,但我并不完全清楚如何创建一个文件。谢谢,所以muchIt是一个名为“Gemfile”(无文件扩展名)的纯文本文件,它位于应用程序/脚本根目录中。打开一个简单的文本编辑器,用上面的内容创建一个新文件,并将其保存为名为“Gemfile”的纯文本。感谢@tessi的扩展谢谢您的解释。我做了上面提到的所有事情,但我仍然收到相同的错误消息您是否将文件放在了错误的文件夹中?它需要位于您正在运行的文件夹中。
$bundle exec rspec spec/hello_example.rb
。通过查看堆栈跟踪,您有两个嵌套的spec文件夹:
/Users/rockyboy/test ruby/spec/spec/