您的位置:首页 > 运维架构 > Linux

linux 基础(第三天)

2011-04-18 22:32 141 查看
初次接触Rspec 发现网上基本资料少的可怜 找到点啥先记下备用~

assert_template 测试是否装载了正确的view

assert_tag 'form',:attributes=>{:action=>'/admin/....'} 测试View中是否有这表单,form也可以是div,td,input等html元素。

assert_response :redirect

assert_redirected_to :action=>'index' 重定向

assigns(:author).first_name :assign是辅助方法,检查author实例变量的赋值。它是个测试辅助方法,用来存取最后请求的动作里所有实例变量的赋值。

follow_redirect Rails自带的测试辅助方法,它使测试用例可以跟随控制器里的redirect_to调用到哪个目标页面。

测试 render :text => "string"
response.body.should == "string"


测试 render :nothing => true
response.should have_text(" ")


测试ajax请求

describe 'get/post 你的action的名称 using ajax' do
it 'should render template 模板名称' do
xhr :post, :action的名称, 其它需要传递给action的值的hash
response.should render_template('渲染的模板')
end
end

describe 'get/post 你的action的名称 using html' do
it 'should reject access using html' do
get/post ::action的名称, 其它需要传递给action的值的hash
response.response.should == 406
end
end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: