我很难在SO/Google上找到这个特殊案例。我有一个带有函数的模块,为了使用它们,您必须创建一个包含/扩展模块的类,具体取决于您需要实例方法还是类方法。moduleAdefsay_helloname"hello#{name}"enddefsay_bye"bye"endend如何使用rspec测试此模块?我有这样的事情,我不确定我应该在哪里创建类和扩展模块。describeAdoclassMyClassextendAendbefore(:each){@name="Radu"}describe"#say_hello"doit"shouldgreetaname"doexpect(Mycla
假设我有一个这样的类定义:classFoodefinit(val)@val=valenddefself.bar:barenddefval@valendend规范如下:describeFooit{shouldrespond_to(:val)}it{shouldrespond_to(:bar)}end第二个it断言失败。从RSpec的文档中我不清楚respond_to应该在类方法上失败。 最佳答案 现在建议我们使用expect,像这样:describeFoodoit'shouldrespondto:bar'doexpect(Foo).t
目前,当我的代码中有一个延迟方法时,如下所示:CommentMailer.delay.deliver_comments(@comment,true)我在规范中写了这样的东西:dj=mock("DelayProxy")CommentMailer.should_receive(:delay).and_return(dj)dj.should_receive(:deliver_comments).with(comment,true)一般来说,有没有更好的方法来处理这个和/或类似rSpec中的链式方法? 最佳答案 我们可以在beforeblo
我刚刚开始使用RSpec,我在RSpecgithub存储库上复制了非常简单的测试,以确保一切按预期工作:require'spec_helper'describe'HomePage'doit"Welcomestheuser"dovisit'/products'page.shouldhave_content("Welcome")endend当我将字符串更改为“Olá”或“Caçamba”之类的字符串时,问题就开始了。任何带有特殊字符的字符串。当我这样做时,出现以下错误:invalidmultibytechar(US-ASCII)(SyntaxError)invalidmultibytech
我想从Rails测试控制台测试RSpecstub和模拟。是否可以?如果是,怎么办?这是我试过的:$railsctest>require"./spec/spec_helper"true>source=double('source')NoMethodError:undefinedmethod`double'formain:Object 最佳答案 您需要要求'rspec/mocks/standalone',如statedinthedocumentation. 关于ruby-on-rails-来
我该如何做:it{shouldhave_constant(:FIXED_LIST)}在我的模型(事件记录)中,我有FIXED_LIST='AString'它不是数据库属性或方法,我无法使用responds_to或has_attribute对其进行测试(它们失败了)。我可以用什么来检查它。-顺便说一句,我安装了shoulda-matchers。 最佳答案 根据DavidChelimsky的回答,我通过稍微修改他的代码使它起作用。在文件spec/support/utilities.rb(或spec/support中的其他文件)中,您可以
我有一个充满对象的json数组。my_array=[{id=>6,name=>"bob"},{id=>5,name=>"jim"},{id=>2,name=>"steve"}]我需要查看数组是否包含一个对象,该对象包含设置为5的属性“id”。“name”属性未知。我如何在rspec中执行此操作?我知道如果我有name属性我知道我可以这样做:my_array.shouldinclude({:id=>5,:name=>"jim"}) 最佳答案 expect(myArray.find{|item|item[:id]==5}).to_not
it'shouldbeanarrayandnotbeempty'dopendingexpect(a.class).tobe(Array)expect(a.empty?).tobe(false)expect(a.first.class).tobe(ExampleClass)end当我运行rspec时:Failures:1)shouldbeanarrayandnotbeemptyFIXEDExpectedpending'Noreasongiven'tofail.NoErrorwasraised.#./spec/example_spec.rb:19知道为什么这会被列为失败吗?
我已经按照我能够在网上找到的使用Rspec2和Mocha配置Rails3的所有步骤进行操作。在我的Gemfile中:group:developmentdogem'rails3-generators'gem"rspec",'>=2.0.0.beta.19'gem"rspec-rails",'>=2.0.0.beta.19'endgroup:testdogem"faker"gem"rspec",'>=2.0.0.beta.19'gem"rspec-rails",'>=2.0.0.beta.19'gem"machinist",'>=2.0.0.beta1'gem"mocha"gem"capy
我已经使用RoR进行开发一年多了,但我才刚刚开始使用RSpec进行测试。对于标准模型/Controller测试,我通常没有任何问题,但问题是我想测试一些复杂的功能流程,并且不知道如何构建我的测试文件夹/文件/数据库。这是我的应用程序的基本结构:classCustomerhas_one:wallethas_many:ordershas_many:invoices,through::ordershas_many:invoice_summariesendclassWalletbelongs_to:customerendclassOrderhas_one:invoicebelongs_to:c