Html/CSS
rspec 标签描述

在阅读本节之前,您可能需要阅读有关RSpec元数据(Metadata)的部分,因为事实证明,RSpec筛选(Filtering)基于RSpec元数据。 假设您有一个spec文件,它包含两种类型的测试:正确测试和错误测试。让无涯教程这样定义它们 RSpec.describe"AnExampleGroupwithpositiveandnegativeExamples"do context'whentestingRuby\'sbuild-inmathlibrary'do it'candonormalnumericoperations'do expect(1+1).toeq(2) end i...

  raKFu9QULpEG   2023年11月20日   28   0   0 rspecrspec

当您学习RSpec时,您可能会读到很多关于期望值(Expectations)的内容,起初可能会有些混乱。当您看到"Expectations"一词时,应牢记两个主要细节 Expectations只是it块中使用expect()方法的一条语句。当您具有如下代码:expect(1+1).toeq(2)时,您期望表达式1+1的值为2。 Expectation语法是相对较新的。在引入expect()方法之前(早在2012年),RSpec使用基于should()方法的另一种语法。上面的期望是用旧语法这样写的:(1+1).shouldeq(2)。 使用较旧的基于代码的版本或较旧版本的RSpec时,...

  raKFu9QULpEG   2023年11月20日   80   0   0 rspecrspec

让无涯教程仔细看看HelloWorld示例的代码。首先,如果不清楚,正在测试HelloWorld类的函数。当然,这是一个非常简单的类,仅包含一个方法say_hello()。 这又是RSpec代码 describeHelloWorlddo context“WhentestingtheHelloWorldclass”do it"Thesay_hellomethodshouldreturn'HelloWorld'"do hw=HelloWorld.new message=hw.say_hello expect(message).toeq"HelloWorld!" end end end d...

  raKFu9QULpEG   2023年11月19日   31   0   0 rspecrspec

RSpecTags提供了一种在规范文件中运行特定测试的简便方法。假设您只想运行指定测试方法,则可以使用Tags标签实现。 describe"HowtorunspecificExampleswithTags"do it'isaslowtest',:slow=>truedo sleep10 puts'Thistestisslow!' end it'isafasttest',:fast=>truedo puts'Thistestisfast!' end end 现在,将上面的代码保存在一个名为tag_spec.rb的新文件中。在命令行中,运行以下命令:rspec--tagslow...

  raKFu9QULpEG   2023年11月20日   25   0   0 rspecrspec

RSpecsubjets提供了编写简写测试用例的快捷方式。 考虑以下代码 classPerson attr_reader:first_name,:last_name definitialize(first_name,last_name) @first_name=first_name @last_name=last_name end end describePersondo it'createanewpersonwithafirstandlastname'do person=Person.new'John','Smith' expect(person).tohave_attribut...

  raKFu9QULpEG   2023年11月20日   37   0   0 rspecrspec

RSpec是一种灵活而强大的工具。RSpec中的元数据(Metadata)函数也不例外。元数据通常指“关于数据的数据”。在RSpec中,这意味着有关您的描述,上下文及其块的数据,让无涯教程看一个例子 RSpec.describe"AnExampleGroupwithametadatavariable",:foo=>17do context'andacontextwithanothervariable',:bar=>12do it'canaccessthemetadatavariableoftheouterExampleGroup'do|example| expect(exa...

  raKFu9QULpEG   2023年11月20日   35   0   0 rspecrspec

行为驱动开发(英语:Behavior-drivendevelopment,缩写BDD)是一种敏捷软件开发的技术,它鼓励软件项目中的开发者、QA和非技术人员或商业参与者之间的协作。BDD最初是由DanNorth在2003年命名,它包括验收测试和客户测试驱动等的极限编程的实践,作为对测试驱动开发的回应。在过去数年里,它得到了很大的发展。 2009年,在伦敦发表的“敏捷规格,BDD和极限测试交流”[3]中,DanNorth对BDD给出了如下定义: BDD是第二代的、由外及内的、基于拉(pull)的、多方利益相关者的(stakeholder)、多种可扩展的、高自动化的敏捷方法。它描述...

  raKFu9QULpEG   2023年11月19日   24   0   0 rspecrspec

如果您已经阅读了RSpecDoubles部分,那么您已经看到了RSpecStubs,它是一种特殊类型的方法,代表现有方法或尚不存在的方法。 这是RSpecDoubles部分中的代码 classClassRoom definitialize(students) @students=students End deflist_student_names @students.map(&:name).join(',') end end describeClassRoomdo it'thelist_student_namesmethodshouldworkcorrectly'do stu...

  raKFu9QULpEG   2023年11月20日   31   0   0 rspecrspec

在本章中,无涯教程将讨论RSpecDoubles,RSpecDouble是一个模拟对象,在代码中模拟系统的另一个对象,方便测试。 假设您为学校构建一个应用程序,有一个教室,还有一个学生。类定义如下: classClassRoom definitialize(students) @students=students end deflist_student_names @students.map(&:name).join(',') end end 这是一个简单的类,它具有一个方法list_student_names,该方法返回以逗号分隔的学生姓名。现在,想为此教室能创建测试,但是如...

  raKFu9QULpEG   2023年11月20日   21   0   0 rspecrspec

如果您还记得无涯教程最初的HelloWorld示例,则其中包含以下内容: expect(message).toeq"HelloWorld!" 关键字eq是RSpec匹配器。在这里,将介绍RSpec中的其他类型的匹配器。 匹配器 匹配器以测试对象或值是否相等。 Matcher Remark Example eq Passeswhenactualexpected expect(actual).toeqexpected eql Passeswhenactual.eql?(expected) expect(actual).toeqlexpected be Passeswhena...

  raKFu9QULpEG   2023年11月20日   41   0   0 rspecrspec