RSpec - 期望值

RSpec - 期望值 首页 / RSpec入门教程 / RSpec - 期望值

当您学习RSpec时,您可能会读到很多关于期望值(Expectations)的内容,起初可能会有些混乱。当您看到"Expectations"一词时,应牢记两个主要细节-

使用较旧的基于代码的版本或较旧版本的RSpec时,可能会遇到旧RSpec语法,如果在新版本的RSpec中使用旧语法,则会看到警告。

如,使用此代码-

RSpec.describe "An RSpec file that uses the old syntax" do
   it 'you should see a warning when you run this Example' do 
      (1 + 1).should eq(2) 
   end 
end

运行它时,您将获得如下所示的输出:

无涯教程网

. Deprecation Warnings:

Using `should` from rspec-expectations' old `:should` 
   syntax without explicitly enabling the syntax is deprecated. 
   Use the new `:expect` syntax or explicitly enable 
	
`:should` with `config.expect_with( :rspec) { |c| c.syntax=:should }`
   instead. Called from C:/rspec_tutorial/spec/old_expectation.rb:3 :in 
   `block (2 levels) 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.001 seconds (files took 0.11201 seconds to load) 
1 example, 0 failures

除非需要使用旧的语法,否则强烈建议您使用Expect()而不是should()。

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

人工智能基础课 -〔王天一〕

大规模数据处理实战 -〔蔡元楠〕

DevOps实战笔记 -〔石雪峰〕

接口测试入门课 -〔陈磊〕

去无方向的信 -〔小麥〕

网络排查案例课 -〔杨胜辉〕

云原生架构与GitOps实战 -〔王炜〕

Python实战 · 从0到1搭建直播视频平台 -〔Barry〕

结构写作力 -〔李忠秋〕

好记忆不如烂笔头。留下您的足迹吧 :)