jjzjj

android_stubs_current_intermediat

全部标签

ruby - 如何使用 Rspec Mocks stub 给定类的任何实例

以下代码引发错误:undefinedmethod'any_instance'forString:Classrequire'rspec'RSpec.configuredo|config|config.mock_with:rspecenddescribeStringdoit'stubs'doString.any_instance.stub(:foo).and_return(1)''.foo.shouldeq(1)endend如何将Mocks模块包含到类或对象类中? 最佳答案 any_instance最近被添加到rspec,所以你的例子现

ruby - 如何使用 Ruby MiniTest stub 引发错误的方法?

我正在尝试测试模型方法引发错误时触发的RailsController分支。defmy_controller_method@my_object=MyObject.find(params[:id])beginresult=@my_object.my_model_method(params)rescueExceptions::CustomError=>eflash.now[:error]=e.messageredirect_tomy_object_path(@my_object)andreturnend#...restirrelevantend如何获得Miniteststub以引发此错误?i

ruby-on-rails - 哪里用 `FactoryGirl.build_stubbed` 哪里用RSpec的 `mock`/`double`

我很好奇人们在编写RSpec规范时倾向于在哪里使用FactoryGirl.build_stubbed以及他们在哪里使用double。也就是说,是否有最佳实践,例如“仅在相应的模型规范中使用FactoryGirl方法?”当您发现自己在spec/models/bar_spec.rb中使用FactoryGirl.create(:foo)时,是否有代码味道?如果您在spec/models/bar_spec.rb中使用FactoryGirl.build_stubbed(:foo),代码味道会不会变小?如果您在foos_controller_spec.rb中使用FactoryGirl.create

ruby-on-rails - 如何在 rspec 功能测试中访问(设计)current_user?

在设计文档中,他们提供了有关在测试Controller时如何访问current_user的提示:https://github.com/plataformatec/devise/wiki/How-To:-Test-controllers-with-Rails-3-and-4-%28and-RSpec%29但是,在进行功能测试时呢?我正在尝试测试我的一个Controller的创建方法,并且在该Controller中使用了current_user变量。问题是devise中建议的宏使用了@request变量,并且对于功能规范来说它是nil。什么是解决方法?编辑:这是我目前的规范:feature

ruby-on-rails - RSpec: stub 私有(private)方法

我尝试用RSpec2测试一个类,它有一些私有(private)方法,这些方法是从一些公共(public)方法调用的。我用测试公共(public)方法@foo.should_receive(:start_training).exactly(2).times他们是否被调用以及调用频率。我的问题是,这种方法不适用于私有(private)方法。那么,有什么方法可以将@foo.send(:private_method)与should_receive结合使用吗?或者任何其他语法? 最佳答案 should_receive(:method)无论:m

ruby - RSpec stub : Return the parameter

虽然我的问题很简单,但我没能在这里找到答案:如何stub方法并返回参数本身(例如在执行数组操作的方法上)?像这样:interface.stub!(:get_trace).with().and_return() 最佳答案 注意:stub方法已被弃用。请看thisanswer以现代方式做到这一点。stub!可以接受一个block。block接收参数;block的返回值是stub的返回值:classInterfaceenddescribeInterfacedoit"shouldhaveastubthatreturnsitsargument

ruby-on-rails - Rails : how to get the current host, 或用它构建 URL?

这个问题在这里已经有了答案:GettingtheHostnameorIPinRubyonRails(12个答案)关闭8年前。我需要使用主机构建具有不同端口的URL。例如,如果主机是example.com,我需要生成类似http://example.com:8080/的URL我需要它是便携的,所以当我在本地环境中时,它会显示http://localhost:8080/相反。有什么想法吗?

如何使用蓝牙连接将字符从UWP应用程序传输到Android应用?

我正在为RaspberryPi开发其UWP应用程序的应用程序,因此我想从UWP应用程序发送和接收字符到Android应用程序。因此,请告诉我什么是UWP应用程序的代码。提前致谢:)看答案此站点向您展示如何发送和接收串行蓝牙数据。github上的来源

ruby-on-rails - 测试时我应该在 Factory girl 中 stub 模型还是在规范文件中 stub ?

几乎我遇到的每一个规范文件我最终都会写这样的东西:before:eachdo@cimg=Factory.build:cimg_valid@cimg.stub(:validate_img).and_returntrue@cimg.stub(:validate_img_url).and_returntrue@cimg.stub(:save_images).and_returntrue@cimg.stub(:process_image).and_returntrue@cimg.stub(:img).and_returntrueend我的意思是,我从Factory.build获得的模型是完全有

如何以android中的数组的形式获取firebase中节点的数据

以这种格式,我在Firebase中有一个数据库。我必须以阵列列表的形式显示所有部门,例如导演,体育。代码:mAuth=FirebaseAuth.getInstance();mdatabase=FirebaseDatabase.getInstance().getReference().child("Department");mdatabase.addValueEventListener(newValueEventListener(){@OverridepublicvoidonDataChange(DataSnapshotdataSnapshot){ListDepartment=(ArrayLis