【问题标题】:Testing Application Controller - Rails测试应用程序控制器 - Rails
【发布时间】:2015-01-21 19:19:05
【问题描述】:

我应该如何在我的ApplicationController 上测试这个方法:

def success
  render nothing: true, status :ok
end

我尝试使用controller.call(:success),但它返回错误。 有什么想法吗?

附加信息: 我正在使用rspec

【问题讨论】:

    标签: ruby-on-rails testing rspec tdd


    【解决方案1】:

    我会这样测试它:

    it 'responds with success' do
      expect(response).to be_success
    end
    
    it 'renders nothing' do
      expect(response).to render_template(nil)
    end
    

    【讨论】:

    • 对不起,我不够清楚。我的意思是我如何实际调用这个方法?
    • success 方法是应该调用的操作,还是您尝试对success 方法进行单元测试?
    • success 方法只是某种帮助,它没有通往它的路径。控制器(例如UserController)会调用它,所以像这样: user.save ?成功:bad_request
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-28
    • 1970-01-01
    相关资源
    最近更新 更多