Ruby on rails 为控制器运行rspec时堆栈级别太深

Ruby on rails 为控制器运行rspec时堆栈级别太深,ruby-on-rails,rspec,rspec-rails,Ruby On Rails,Rspec,Rspec Rails,当我在我的模型上运行rspec时,一切正常。我的控制器出现“堆栈级别太深”错误 但对于我的控制器,当我只添加一个示例时,就会出现“堆栈级别太深”的错误 $> rspec spec/controllers F Failures: 1) GuestsController GET 'index' should render 200 page Failure/Error: Unable to find matching line from backtrace Syst

当我在我的模型上运行rspec时,一切正常。我的控制器出现“堆栈级别太深”错误

但对于我的控制器,当我只添加一个示例时,就会出现“堆栈级别太深”的错误

$> rspec spec/controllers 
F

Failures:

  1) GuestsController GET 'index' should render 200 page
     Failure/Error: Unable to find matching line from backtrace
     SystemStackError:
       stack level too deep
     # /Users/iyanski/.rvm/gems/ruby-1.9.3-p392@littleknot/gems/actionpack-3.2.13/lib/action_dispatch/routing/url_for.rb:102

Finished in 0.02816 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/controllers/guests_controller_spec.rb:5 # GuestsController GET 'index' should render 200 page
客人\控制器\规格rb

require 'spec_helper'

describe GuestsController do
  describe "GET 'index'" do
    it "should render 200 page" do

    end
  end
end
下面是我的spec_helper.rb

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'factory_girl'

include Rails.application.routes.url_helpers

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|

  config.infer_base_class_for_anonymous_controllers = false

  config.order = "random"

  config.before(:suite) do
    DatabaseCleaner.strategy = :truncation
    DatabaseCleaner.clean_with(:truncation)
  end

  config.before(:each) do
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end

end

您认为是什么导致了这种情况?

堆栈级别太深表示您处于一个永远不会结束的循环中。所以Ruby决定打破这个循环,并给出这个错误。您的控制器代码以及您的路线将非常有用。可能您处于重定向循环中,或者您正在递归调用同一个函数,但没有正确的中断或返回语句。您在GuestController中有什么特别的功能吗?您在Controller中还做了哪些其他工作?你在用地理编码器吗?如果是,那么您需要模拟API请求。。这是唯一的代码。类来宾控制器<应用控制器;def指数;结束;最后,我仍然要为第一个控制器编写测试。对于路线。只有:资源:来宾
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'factory_girl'

include Rails.application.routes.url_helpers

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|

  config.infer_base_class_for_anonymous_controllers = false

  config.order = "random"

  config.before(:suite) do
    DatabaseCleaner.strategy = :truncation
    DatabaseCleaner.clean_with(:truncation)
  end

  config.before(:each) do
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end

end