RSpec Tutorial
RSpec Resources
Selected Reading
选读
- RSpec - Expectations
- RSpec - Filtering
- RSpec - Metadata
- RSpec - Helpers
- RSpec - Subjects
- RSpec - Tags
- RSpec - Hooks
- RSpec - Stubs
- RSpec - Test Doubles
- RSpec - Matchers
- RSpec - Writing Specs
- RSpec - Basic Syntax
- RSpec - Introduction
- RSpec - Home
RSpec Resources
Selected Reading
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
选读
RSpec - Expectations
RSpec - Expectations
当你学习RSpec时,你可以读到很多关于期望的内容,这首先可能是混淆。 在你看到“期望”一词时,应当铭记两个主要细节。
期望只是一份在it>栏中的声明。 使用expect()方法。 这一点。 它没有比这更复杂。 如果您有这样的守则:expect(1+1)。 您预计,这一表述将1 + 1。 页: 1 尽管RSpec是一个BDD测试框架,但措辞很重要。 您的《RSpec法典》将这一声明称为一种期望,从而清楚地描述了其测试守则的“行为”。 想法是,你以类似文件的方式来表达守则应如何行事。
投机财团比较新。 在采用expect()方法之前(2012年之后),RSpec使用了一种基于should(方法的不同辛奈。 以上试金字在旧的yn中写成:(1+1)。
您在采用旧法典或旧版本的RSpec工作时,可能会碰到旧的RSpec syntax。 如果你使用新版本的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 exppcitly enabpng the syntax is deprecated. Use the new `:expect` syntax or exppcitly 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
除非要求你使用旧的辛迪加,否则建议你使用预期(而不是()。
Advertisements