草庐IT

describe

全部标签

ruby - 我可以拥有没有方法类的 RSpec 吗

我只是在写一些我不想放在类中的算法方法。所以我只是把它们放在我的ruby​​文件中。但是我无法弄清楚如何编写测试或更具体地使用describe:xxx因为我没有要放在主要描述之后的类名。有什么想法吗? 最佳答案 您可以在describe语句后放置任何字符串:describe"SomethingYouWantToTest"do#Yourspecshereend 关于ruby-我可以拥有没有方法类的RSpec吗,我们在StackOverflow上找到一个类似的问题:

ruby - 在 rspec 中描述 vs 上下文。差异?

这个问题在这里已经有了答案:RSpec:describe,context,feature,scenario?(3个答案)关闭8年前。我已经阅读了一些关于应该如何组织rspec代码的内容。似乎“上下文”更多地用于对象的状态。用你的话来说,你会如何描述如何在rspec代码中使用“describe”?这是我的movie_spec.rb代码片段:require_relative'movie'describeMoviedobeforedo@initial_rank=10@movie=Movie.new("goonies",@initial_rank)endit"hasacapitaliedtit

ruby-on-rails - 我如何解决 "Missing host to link to! Please provide the :host parameter"? (返回率)

我正在关注RoRTutorial我被困在Listing9.15运行'bundleexecrspecspec/'后出现以下错误:1)AuthenticationauthorizationaswrongusersubmittingaPATCHrequesttotheUsers#updateactionFailure/Error:specify{expect(response).toredirect_to(root_url)}ArgumentError:Missinghosttolinkto!Pleaseprovidethe:hostparameter,setdefault_url_opti

ruby-on-rails - RSpec.describe 与描述

这是我一段时间以来第一次开始一个新的Rails项目。在构建模型时,Rspec创建以“RSpec”为谓词的描述blockRSpec.describeMyModeldo...end与旧风格对比:describeMyModeldo...end我已经仔细阅读了变更日志,但一定是遗漏了变更的理由? 最佳答案 从RSpec3开始,您可以通过限制domainspecificlanguage(dsl)来禁用describe的全局可用性。.以RSpec.describe为前缀确保测试在实现限制后仍将运行。注意:您仍然不需要前缀,除非您使用config

ruby-on-rails - 一个 has_many :through Relationship 的 Rails RSpec 测试

我是测试和Rails的新手,但我正努力让我的TDD流程正常运行。我想知道您是否使用任何类型的范例来测试has_many:through关系?(或者我想一般来说只是has_many)。例如,我发现在我的模型规范中,我肯定会编写简单的测试来检查关系两端的相关方法。即:require'spec_helper'describePostdobefore(:each)do@attr={:subject=>"f00PostSubject",:content=>"8arPostBodyContent"}enddescribe"validations"do...enddescribe"categoriz

ruby - RSpec NoMethodError : "undefined method ` describe' for main Object"

我正在尝试学习Rspec。我在eclipse中的ruby项目如下-代码-require'rspec'require'./RubyOffRailsTuts/classes/furlong'describeFurlongdoend错误-/RubyOffRailsTuts/specs/furlong_spec.rb:6:in`':undefinedmethod`describe'formain:Object(NoMethodError)没有在网上得到任何有用的答案。我该如何解决这个问题? 最佳答案 作为RSpec.describe的前缀d

javascript - Mocha 和 this 上下文

所以我有这段代码:describe('maindescribe',function(){afterEach(function(){//this.prop===undefined});describe('sub',function(){it('shoulddosomething',function(){this.prop='test';});});});我不知道为什么mainafterEach中的this.prop是undefined因为下面的代码按预期工作:describe('maindescribe',function(){afterEach(function(){//this.pr

javascript - Cloud9 中的 Mocha 测试出现 "undeclared variable"警告

我是node.js和用于单元测试的框架Mocha的新手,但我在cloud9IDE中创建了几个测试只是为了看看它是如何工作的。代码如下所示:varassert=require("assert");require("should");describe('Array',function(){describe('#indexOf()',function(){it('shouldreturn-1whenthevalueisnotpresent',function(){assert.equal(-1,[1,2,3].indexOf(5));assert.equal(-1,[1,2,3].index

javascript - Mocha 中的 describe() 是什么

我正在尝试使用Mocha,这是我从文档中看到的示例:varassert=require("assert")describe('Array',function(){describe('#indexOf()',function(){it('shouldreturn-1whenthevalueisnotpresent',function(){assert.equal(-1,[1,2,3].indexOf(5));assert.equal(-1,[1,2,3].indexOf(0));})})})大多数示例显示第二个describe语句describe('#indexOf()',functio

javascript - 如何避免 Jest 警告 : A "describe" callback must not return a value?

将Jest从版本23升级到版本24后,在运行我的测试时,几乎每个测试都会收到这样的警告消息:A"describe"callbackmustnotreturnavalue.Returningavaluefrom"describe"willfailthetestinafutureversionofJest.附带的堆栈跟踪指向此模块:addSpecsToSuite(node_modules/jest-jasmine2/build/jasmine/Env.js:443:15)这样做的原因是我喜欢在我的测试中使用箭头函数的简写版本,当函数体只包含一个语句时省略大括号,例如:describe('t