RSPEC 失败并获取

发布于 2024-12-11 01:36:10 字数 799 浏览 0 评论 0原文

这是失败的 rspec 代码:

require 'spec_helper'

describe MainMenuController do

  describe "GET 'first_page'" do
    it "should be successful" do
      get 'first_page'
      response.should be_success
    end
  end

end

这是控制器代码:

class MainMenuController < ApplicationController
  def first_page
    session[:page_step] = 1
    redirect_to session[:page1]
  end

end

规范错误是:

 MainMenuController GET 'first_page' should be successful
     Failure/Error: response.should be_success
       expected success? to return true, got false
     # ./spec/controllers/main_menu_controller_spec.rb:8:in `block (3 levels) in <top (required)>'

应用程序运行良好,没有问题,该错误可能是由 Rails 自动生成的 rspec 代码引起的。对这个问题有什么想法吗?谢谢。

Here is the failed rspec code:

require 'spec_helper'

describe MainMenuController do

  describe "GET 'first_page'" do
    it "should be successful" do
      get 'first_page'
      response.should be_success
    end
  end

end

Here is the controller code:

class MainMenuController < ApplicationController
  def first_page
    session[:page_step] = 1
    redirect_to session[:page1]
  end

end

The spec error is:

 MainMenuController GET 'first_page' should be successful
     Failure/Error: response.should be_success
       expected success? to return true, got false
     # ./spec/controllers/main_menu_controller_spec.rb:8:in `block (3 levels) in <top (required)>'

The app runs fine without problem and the error may be caused by the rspec code which is automatically generated by the rails. Any idea about the problem? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流心雨 2024-12-18 01:36:10

我猜匹配器正在寻找状态 200。

但是由于您重定向,它得到 301。

因此它失败了。

尝试:

response.status.should eq 301

你会有更多细节。

I guess the matcher is looking for a status 200.

But since you redirect, it gets 301.

Thus it fails.

Try:

response.status.should eq 301

You'd have some more details.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文