我需要测试以下帮助器:
def display_all_courses
@courses = Course.all
output = ""
for course in @courses do
output << content_tag(:li, :id => course.title.gsub(" ", "-").downcase.strip) do
concat content_tag(:h1, course.title)
concat link_to("Edit", edit_course_path(course))
end
end
return output
end
Run Code Online (Sandbox Code Playgroud)
我想知道是否有办法可以测试这个输出.基本上,我只是想测试帮助器给我正确数量的li元素,也许是没有任何课程的情况.
我的第一个想法是做这样的事情:
describe DashboardHelper do
describe display_all_courses do
it "should return an list of all the courses" do
7.times{Factory(:course)
html = helper.display_all_courses
html.should have_selector(:li)
end
end
end
Run Code Online (Sandbox Code Playgroud)
这很好用.但是,如果我将:count选项添加到have_selector调用它突然失败,有人可以帮我弄清楚为什么会这样吗?
我在每个需要加载我的应用程序主视图的函数中使用redirect()(来自uri helper).它重定向到相同的功能.我的目标是获得相同的清洁uri,即使我使用页面功能(调用其他控制器).这是好习惯吗?我什么时候应该使用redirect()?是否有其他解决方案可以获得类似的结果?
这是一些澄清的代码.
这是一个控制器:
<?php
class Main_controller extends Controller
{
function index()
{
$this->load->view(page);
}
function page_feature()
{
/* some stuff */
redirect('main_controller.php','refresh');
}
}
Run Code Online (Sandbox Code Playgroud)
有了这条路线规则:
$route['([a-z-A-Z1-9_]+)'] = "main_controller";
Run Code Online (Sandbox Code Playgroud)
uri是这样的:myapp.com/something在这个页面上,有一些功能可以调用(提交时)main_controller(或其他控制器)的其他功能,例如表单:
<form action="myapp.com/another_controller/method" method="post">
Run Code Online (Sandbox Code Playgroud)
在此查询"/ another_controller/method"的末尾,我使用redirect('main_controller')显示包含新数据的视图,并保留uri"myapp.com/something"而不是"myapp.com/another_controller/方法".
我想知道这是好事还是坏事,以及为什么.
如何在帮助器中写这个html?
<tr style="color:red;">
<td></td>
<td><%= error_message_on "test", "test_message", :prepend_text => "Kem cho" %></td>
</tr>
Run Code Online (Sandbox Code Playgroud) 我根据开发者页面上的说明添加了一个Facebook Like Box:https://developers.facebook.com/docs/reference/plugins/like-box/
该页面显示它应该显示该页面的最新帖子.但是,在我的网站上,它只显示页面上的"友好活动"提要,这似乎只是签到餐馆的人.这是因为它是一个"地方"吗?我可能需要将其作为业务而不是位置来调整Feed?
是否有某些设置可以改变这个或什么?其他明智的我不知道!
当我跑步时,get-help get-process -detailed我得到了完整的帮助.如果我只是想知道get-process -id参数的作用,我会跑什么?有没有办法像那样深入研究?
我今天尝试使用“帮助类样式”编写CSS,Twitter上的许多开发人员表示这是一种不良做法。
这是一个例子:
<span class="et-margin-top-30 et-width-400 et-display-inline">
<p class="et-common-frame-shadow et-inner-img-shadow">
<img class="et-common-frame-img" src="img3.jpg"/>
</p>
<h3 class="et-margin-top-10 et-fontsize-26 et-fontweight-bold">foo</h3>
<p class="et-margin-top-10">bar</p>
</span>
Run Code Online (Sandbox Code Playgroud)
为什么这是一个不好的做法?谁能告诉?我们什么时候应该使用.clear之类的帮助器类?
我想知道如何回应当前的high_voltage页面名称作为我的类<body>?
我目前的解决方案有点麻烦:
# app/views/layouts/application.html.erb
<body class="<%= yield :body_class %>">
# app/views/pages/principles.html.erb
<% content_for :body_class do %>home<% end %>
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
是否有任何内联方法来收集所有验证错误?现在我这样做:
$errors = '';
foreach($model->attributeNames() as $attr)
{
$errors .= $model->hasErrors($attr) ? $model->getErrors($attr) : '';
}
Run Code Online (Sandbox Code Playgroud)
我认为这是多余的.
我有一个threejs场景,对象的交叉检查.我将每个场景对象添加到数组中,然后由raycaster检查.
var intersects = raycaster.intersectObjects( scene.children );
Run Code Online (Sandbox Code Playgroud)
然后,我检查对象的颜色,并在与鼠标指针接触时更改它.
INTERSECTED.material.emissive.setHex( 0xff0000 );
Run Code Online (Sandbox Code Playgroud)
如果我向场景添加一个辅助对象,比如CameraHelper或GridHelper,我会得到常量错误,因为.getHex .setHex辅助对象是不可能的.
是否可以从此检查中排除辅助对象,我该怎么做?
它必须是scene.children- scene.helpers,但我无法想出办法.谢谢您的帮助.
有可能做这样的事情吗?
module MyHelper
before (:each) do
allow(Class).to receive(:method).and_return(true)
end
end
Run Code Online (Sandbox Code Playgroud)
然后在测试中,我可以执行以下操作:
RSpec.describe 'My cool test' do
include MyHelper
it 'Tests a Class Method' do
expect { Class.method }.to eq true
end
end
Run Code Online (Sandbox Code Playgroud)
编辑:这将产生以下错误:
undefined method `before' for MyHelper:Module (NoMethodError)
Run Code Online (Sandbox Code Playgroud)
本质上,我有一个案例,其中许多测试执行不同的操作,但是跨它们的通用模型对after_commit做出反应,最终会始终调用与API通讯的方法。我不想在全球范围内允许Class接收,:method因为有时我需要为特殊情况自己定义它...但是我不想不必重复我的allow / receive / and_return而是将其包装在一个通用帮助器中。 。
helper ×10
rspec ×2
ruby ×2
abstraction ×1
codeigniter ×1
css ×1
facebook ×1
gem ×1
intersection ×1
powershell ×1
raycasting ×1
redirect ×1
scene ×1
three.js ×1
uri ×1
yii ×1