草庐IT

Test_stub

全部标签

ruby-on-rails - RSpec stub 邮件程序

我有一个UserMailDispatcher类,它的工作是根据特定条件通过ActiveMailer发送邮件。我正在尝试使用RSpec对其进行测试,但效果不佳。我想以某种方式stub测试邮件并查看该类是否正确传递它。这是我到目前为止所拥有的:我所有的邮件程序都继承自ApplicationMailer:application_mailer.rbclassApplicationMaileruser_mail_dispatcher_spec.rbrequire'rails_helper'describeUserMailDispatcherdoclassUserMailer我想测试调度程序是否可

ruby-on-rails - 具有属性的 rspec stub any_instance

我需要对具有特定属性或属性集的模型的所有实例进行stub。例如,使用ActiveRecord:let(:model1){Model.create!(uid:1)}let(:model2){Model.create!(uid:2)}beforedoallow(model1).toreceive(:foo).and_return:barallow(model2).toreceive(:foo).and_return:bazenditdoexpect(model1.foo).toeq:bar#=>passesexpect(model2.foo).toeq:baz#=>passes######

ruby - 为什么 Test::Unit.test_order= 没有按预期工作?

有问题InRuby,howtoIcontroltheorderinwhichTest::Unittestsarerun?并想引用test_order=:defined,来回答documentationforTest::Unit::TestCase.test_order说:Setsthecurrenttestorder.Herearetheavailableorder::alphabeticDefault.Testsaresortedinalphabeticorder.:randomTestsaresortedinrandomorder.:definedTestsaresortedind

ruby-on-rails - 我可以使用 rspec 登录到 test.log 吗?

这里有一个简单的规范来测试这个:require'spec_helper'describeA_controllerdobeforedo@cat_noise="Meow"endit"shoulddonothingbecauseit'semptyandIcreateditjusttotestlogger!"dologger.info"----------Herecomesacatnoise-----------"logger.info@cat_noiselogger.info"-----------Theregoesacatnoise-----------"endend这是我的测试环境的日志

ruby-on-rails - Rspec stub 不起作用

我有以下规范来测试Controller方法:context"#create"doit"shouldredirectwhenmodelisvalid"doUser.stub!(:valid?).and_return(true)post:create,:user=>FactoryGirl.attributes_for(:user)response.shouldredirect_to("/")endit"shouldrendernewtemplatewhenmodelisinvalid"doUser.stub!(:valid?).and_return(false)post:create,:u

ruby - 对如何使用模拟和 stub 感到困惑

我有一个类和一个规范。classStoredefactivate(product_klass,product_id)product=product_klass.find(product_id)ifproduct.inactive?product.update_attribute:active,trueendendenddescribeStoredoit"shouldactivateaninactiveproduct"doproduct=mockproduct.stub(:inactive?).and_return(true)store=Store.newstore.activate(2

ruby-on-rails - 使用 FactoryGirl 构建一个 json stub

我尝试使用工厂构建json,但是当我尝试构建build时它是空的。下面是Factory类。require'faker'FactoryGirl.definedofactory:accountdo|f|f.name{Faker::Name.name}f.description{Faker::Name.description}endfactory:accjson,class:Hashdo"@type""accountResource""createdAt""2014-08-07T14:31:58""createdBy""2""disabled""false"endend下面是我正在尝试构建的

ruby - 初始化' : rack-test requires a rack application, 但没有给出 (ArgumentError)

从Selenium切换到PhantomJs/Poltergeist时,我一直收到此错误。有人知道我做错了什么吗?如果我将驱动程序切换到selenium,脚本将完美运行。每当我注释掉default_driver=:selenium并替换为javascript_driver=:poltergeist时,我都会遇到此错误。initialize':rack-testrequiresarackapplication,butnonewasgiven(ArgumentError)这一切都在一个ruby​​文件中,没有rails。require'rubygems'require'capybara're

ruby - 如何使用 RSpec 模拟/ stub 文件目录及其内容?

前一段时间我问了“HowtotestobtainingalistoffileswithinadirectoryusingRSpec?”,虽然我得到了一些有用的答案,但我仍然卡住了,因此提出了一个新问题,其中包含有关我正在尝试做的事情的更多细节。我正在编写我的第一个RubyGem。它有一个模块,其中包含一个类方法,该方法返回一个数组,该数组包含指定目录中的非隐藏文件列表。像这样:files=Foo.bar:directory=>'./public'该数组还包含一个表示文件元数据的元素。这实际上是从文件内容生成的哈希值的哈希值,其想法是即使更改单个文件也会更改哈希值。我已经编写了待定的RS

ruby - RSpec stub : return in a sequence

我知道以下事情有效:返回一个参数subject.should_receive(:get_user_choice){|choices|choices.to_a[0]}和一个序列(它将在第一次调用时返回0,第二次“退出”)subject.should_receive(:get_user_choice).and_return(0,"exit")但是如何组合它们呢?如果我想第一次返回参数然后返回“exit”怎么办 最佳答案 或者:subject.should_receive(:get_user_choice).ordered.and_ret