【问题标题】:stack level too deep (SystemStackError)堆栈级别太深 (SystemStackError)
【发布时间】:2012-03-31 10:14:03
【问题描述】:

我有 Sinatra 应用程序,需要测试我的应用程序。

功能/支持/env.rb:

require_relative "../../application"

require "capybara"
require "capybara/cucumber"
require "rspec"

World do
  Capybara.app = Application

  include Capybara::DSL
  include RSpec::Matchers
end

features/one.feature:

Feature: Test homepage
  In order to make sure people can open my site
  I want to check it opened

  Scenario: Opening first page
    Given I have opened homepage    
    Then I should see site header

测试一下:

cucumber features\one.feature

结果:

Feature: Test homepage
  In order to make sure people can open my site
  I want to check it opened

  Scenario: Opening first page    # features\one.feature:5
    Given I have opened homepage  # features\one.feature:6
    Then I should see site header # features\one.feature:7

1 scenario (1 undefined)
2 steps (2 undefined)
0m0.006s

You can implement step definitions for undefined steps with these snippets:

Given /^I have opened homepage$/ do
  pending # express the regexp above with the code you wish you had
end

Then /^I should see site header$/ do
  pending # express the regexp above with the code you wish you had
end

好吧,我已经创建了 features/step_definitions/agenda_steps.rb:

Given /^I have opened homepage$/ do
  pending # express the regexp above with the code you wish you had
end

Then /^I should see site header$/ do
  pending # express the regexp above with the code you wish you had
end

测试一下:

cucumber features\one.feature

结果:

Feature: Test homepage
  In order to make sure people can open my site
  I want to check it opened

  Scenario: Opening first page    # features\one.feature:5
    Given I have opened homepage  # features/step_definitions/agenda_steps.rb:1
C:/Ruby193/bin/cucumber:19: stack level too deep (SystemStackError)

为什么以及如何解决?

更新:如果我像这样重写我的 env.rb,问题就会消失:

require_relative "../../application"

require "capybara"
require "capybara/cucumber"
require "rspec"


Capybara.app = Application
#World do
#  Capybara.app = Application
# 
#  include Capybara::DSL
#  include RSpec::Matchers
#end

【问题讨论】:

  • 您能否发布您的 Gemfile.lock 或更多,以便您使用什么版本的黄瓜、水豚和 rspec
  • 我已经在这里发布了我的 Gemfile.lock:pastebin.com/8Ni5MSdj
  • @Jacob,Rspec 用于断言,而 Capybara 只是与网络驱动程序对话。话虽如此,你肯定需要 Rspec 和 Capybara(可能还有 Selenium)

标签: ruby cucumber sinatra capybara


【解决方案1】:

我得到了相同的外观错误..as

stack level too deep (SystemStackError)
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/cucumber-1.1.4/lib/cucumber/core_ext/instance_exec.rb:73..

我在 env.rb 的第一行上添加了require 'cucumber/rails'...首先加载。

现在我不再面临这个错误。

【讨论】:

    【解决方案2】:

    我相信只有 Capybara.app = Application 不应World 内声明,如您的示例所示。

    这是我的工作env.rb

    ENV['RACK_ENV'] = 'test'
    require File.join(File.dirname(__FILE__), '..', '..', 'rvs.rb')
    
    require 'capybara'
    require 'capybara/cucumber'
    require 'rspec'
    require 'r18n-core'
    
    Capybara.app = RVS
    
    class RVSWorld
      include R18n::Helpers
      include Capybara::DSL
      include RSpec::Expectations
      include RSpec::Matchers
    end
    
    World do
      RVSWorld.new
    end
    

    如您所见,RVSWorld 类只有包含必要模块的语句。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-10
      • 2013-10-05
      • 2014-10-25
      • 2017-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多