加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-3.1 – Rails 3.1.3和继承资源测试失败

发布时间:2020-12-17 04:21:44 所属栏目:百科 来源:网络整理
导读:我正在将Rails 3.1.3用于具有Inherited Resources 1.3.0的项目. 当我有这样的控制器时: class PostsController InheritedResources::Baseend 我用rspec测试以下内容 describe "PUT update" do describe "with invalid params" do it "re-renders the 'edit'
我正在将Rails 3.1.3用于具有Inherited Resources 1.3.0的项目.

当我有这样的控制器时:

class PostsController < InheritedResources::Base
end

我用rspec测试以下内容

describe "PUT update" do
    describe "with invalid params" do
      it "re-renders the 'edit' template" do
        post = Post.create! valid_attributes
        # Trigger the behavior that occurs when invalid params are submitted
        Post.any_instance.stub(:save).and_return(false)
        put :update,{:id => post.to_param,:post => {}},valid_session
        response.should render_template("edit")
      end
    end
  end

我收到以下错误:

3) PostsController PUT update with invalid params re-renders the 'edit' template
     Failure/Error: response.should render_template("edit")
       expecting <"edit"> but rendering with <"">
     # ./spec/controllers/posts_controller_spec.rb:115:in `block (4 levels) in <top (required)>'

为什么是这样?我是否必须将其他东西存在?

解决方法

只需添加:
Post.any_instance.stub(:errors).and_return(['error'])

紧接着:

Post.any_instance.stub(:save).and_return(false)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读