首页 \ 问答 \ 您将如何测试部分RSpec?(How would you go about testing partial, RSpec?)

您将如何测试部分RSpec?(How would you go about testing partial, RSpec?)

让我说我有一个非常复杂的视图,具有非常复杂的测试规范。 我想为它添加另一个功能,我想用RSpec推动开发。

我想在Employee类中添加联系人。

在employee.html.erb的某处我添加了一行:

#lots of data rendered so far

<%= render @employee.contacts %>

#even more here

目前我还不知道_contact.html.erb部分需要看起来像什么。 要直接从我的员工主视图规范show.html.erb_spec.rb测试它,我将不得不做很多设置填充或模拟不同的数据库员工是从(项目,部门等)构建的。

我现在需要测试的只是部分,我不关心这个员工目前所属的部门,项目和其他事情,我不想花时间嘲笑他们。 我稍后可能会将它添加到我的主要规范中并创建测试整个视图所需的一切,但不仅仅是喷射。

您是否有任何技术或方法来创建Employee实例,向其添加一些联系人,以及仅针对部分测试视图? 无需担心Employee构建的所有其他事情。

IGEL答案的最新消息:

我同意你的意见,并且测试期望(...)。接收(:render)对于请求规范是100%的,如果我已经有了部分模板,我就不会再进一步​​了。 我只是想走极端,通过RSpec推动我的div和跨度。 不测试新功能的行为,但它看起来。 你认为它不值得吗?

我根本不测试视图(结构),但我看过一些像Rails Tutorial这样的文档,Michael不仅测试行为,还测试结构。 我以为我会试一试:)


Lets say I have a very complicated view with a very complicated test spec. I would like add another feature to it and I would like to drive the development with RSpec.

I would like to add contacts to Employee class.

Somewhere in the employee.html.erb I add the line:

#lots of data rendered so far

<%= render @employee.contacts %>

#even more here

At the moment I don't really know what _contact.html.erb partial needs to look like. To test it directly from my main view spec for employees, show.html.erb_spec.rb, I would have to do a lot of set up populating or mocking different database employee is build from(projects, departments etc.).

All I need to test for now is that partial, I don't care about departments, projects and other things this employee currently belongs to and I don't want to spend my time on mocking them all up. I will probably add it to my main spec later on and create everything needed to test the entire view but not just jet.

Do you have any technique or way for creating an instance of Employee, adding a few Contacts to it, and testing the view for just the partial? Without worrying about all the other things the Employee is built from.

UPDATE FOR IGEL ANSWER:

I agree with you, and testing for expect(...).to receive(:render) is 100% enough for request spec and I would go no further if I already had a partial template. I just wanted to go extreme and drive my div's and span's through RSpec. Not testing for behaviour of new feature but it look. Do you suggest its not worth it?

I don't test views(structure) at all but I have seen a few documents like Rails Tutorial where Michael is not only testing behaviour but as well structure. I thought I'll give it a go:)


原文:
更新时间:2021-12-12 19:12

最满意答案

尝试改变Android工作室的主题,你可以这样做
File->Settings->Editor->Colors & Fonts->在方案名称中选择Darcula并申请查看一个很棒的黑暗背景主题编辑器在Mac Android Studio -> Preferences ->

您可以从http://ideacolorthemes.org/下载新主题

下载.jar文件后,转到文件 - >导入设置...并选择下载的文件。


Try to change the theme of Android studio, you can do so by
File->Settings->Editor->Colors & Fonts-> In scheme name select Darcula and apply to see a awesome dark background theme editor On mac Android Studio -> Preferences ->

You can download new themes from http://ideacolorthemes.org/

Once you have downloaded the .jar file, go to File -> Import Settings... and choose the file downloaded.

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)