Stack level too deep

I have a tree that I do recursion over the nodes (and then some
recursion inside the nodes…). Two problems:

  1. Stack level too deep (error message)
  2. Speed get really really lousy when the tree is deep. With a small
    shallow tree the speed is nice. I get that the overall time get long but
    the handling of each node is slow in a deep tree.

Any way around these issues? I should say that it’s running in a Rails
environment on Win, Ruby 1.8.2

/Marcus

On 2/28/06, marcus [email protected] wrote:

I have a tree that I do recursion over the nodes (and then some
recursion inside the nodes…). Two problems:

  1. Stack level too deep (error message)

what is the maximum depth of the tree? and how do you traverse it?
– henon

marcus wrote:

I have a tree that I do recursion over the nodes (and then some
recursion inside the nodes…). Two problems:

  1. Stack level too deep (error message)
  2. Speed get really really lousy when the tree is deep. With a small
    shallow tree the speed is nice. I get that the overall time get long
    but the handling of each node is slow in a deep tree.

Any way around these issues? I should say that it’s running in a Rails
environment on Win, Ruby 1.8.2

The easiest change is to use BFS instead of DFS - if that’s possible in
your scenario. Alternatives:

  • implement a DFS with your own kind of stack

  • change the way you store things to avoid such a deep recursion

Also, I guess you made sure that there is no loop, i.e. the structure is
actually a tree…

Kind regards

robert

Meinrad R. wrote:

into a loop, but it will not be as easy to read anymore.
That’s exactly the other recommendation I gave. :slight_smile:

robert

On 2/28/06, Robert K. [email protected] wrote:

  • change the way you store things to avoid such a deep recursion

[…]

i now remember that i had a similar problem with a deep recursion and
stack
depth. i solved
it by converting the recursive function into a while loop. you can
transform
every recursion
into a loop, but it will not be as easy to read anymore.
– henon

Robert K. skrev:

into a loop, but it will not be as easy to read anymore.

That’s exactly the other recommendation I gave. :slight_smile:

robert

I haven’t received the other mail(s) that is talked about. However:

I’m implementing the composite pattern using acts_as_tree and STI in
ActiveRecord. The thing that is modeled is nodes in a web site structure
that is kind of tree structured (isn’t all web sites?). So I try to loop
over the nodes to do various operations (generate navigations, publish,
distribute etc).

I’m sure that there are ways around this but then you have to code
around stuff because of the language implementation and that doesn’t
feel good at all…

/Marcus

marcus wrote:

  1. Stack level too deep (error message)

You can change the stack size of the Ruby executable with editbin. It’s
part of Visual Studio.

On Feb 28, 2006, at 11:14 AM, marcus wrote:

I’m sure that there are ways around this but then you have to code
around stuff because of the language implementation and that
doesn’t feel good at all…

Well maybe you can take smaller steps to coding around the
implementation, first code a tail-recursive version and then convert
that into an iterative version.

On 28 Aug, 04:13, Justin Ko [email protected] wrote:

I would suggest switching to capybara.

Hi Justin,

I tried changing a part of my Gemfile to this:

group :development, :test do
gem ‘rspec-rails’, ‘>= 2.0.0.beta.19’
gem ‘capybara’
end

I am not sure if this is correct or what to do next. I tried “bundle
install” and then “rspec spec/requests”. Capybara was installed but I
still got the stack level too deep error. Could you tell me what to do
or point me to an online resource where this is documented?

Thanks in advance!

Regards,

Daniel
LidströmStockholm, Sweden

I think you’re having this problem:

  • Toni

On Aug 28, 6:59 am, Daniel Lidström [email protected] wrote:

group :development, :test do

Regards,

Daniel Lidström
Stockholm, Sweden


rspec-users mailing list
[email protected]://rubyforge.org/mailman/listinfo/rspec-users

Did you remove webrat from the Gemfile?

On Aug 28, 2010, at 11:33 AM, Justin Ko wrote:

or point me to an online resource where this is documented?
Did you remove webrat from the Gemfile?
That won’t help with beta.19, which has a hard dependency on webrat.
beta.20 does not, so you can choose between webrat and capybara.

On 28 Aug, 19:32, David C. [email protected] wrote:

On Aug 28, 2010, at 11:33 AM, Justin Ko wrote:

Did you remove webrat from the Gemfile?

That won’t help with beta.19, which has a hard dependency on webrat. beta.20 does not, so you can choose between webrat and capybara.

Thanks for the responses so far. Here’s what I have done:

  • Switched to beta 20:

daniel@ubuntu/home/daniel/programming/rails_projects/sample_app$ cat
Gemfile
source ‘http://rubygems.org

gem ‘rails’, ‘3.0.0.rc’

Bundle edge Rails instead:

gem ‘rails’, :git => ‘git://github.com/rails/rails.git’

gem ‘sqlite3-ruby’, :require => ‘sqlite3’

group :development, :test do
gem ‘rspec-rails’, ‘>= 2.0.0.beta.20’
gem ‘capybara’
end

  • Updated rspec:

daniel@ubuntu/home/daniel/programming/rails_projects/sample_app$ rails
generate rspec:install
identical .rspec
exist spec
conflict spec/spec_helper.rb
Overwrite /home/daniel/programming/rails_projects/sample_app/spec/
spec_helper.rb? (enter “h” for help) [Ynaqdh] Y
force spec/spec_helper.rb
exist autotest
identical autotest/discover.rb

  • Then run the tests again:

daniel@ubuntu/home/daniel/programming/rails_projects/sample_app$ rspec
-b spec
FFFF.F.F.F

Failures:

  1. LayoutLinks should have a Home page at ‘/’
    Failure/Error: response.should have_selector(‘title’, :content =>
    “Home”)
    undefined method `has_selector?’ for
    #ActionDispatch::TestResponse:0x7f0f4ca18cb0

    /usr/lib/ruby/gems/1.8/gems/rspec-expectations-2.0.0.beta.20/

lib/rspec/matchers/has.rb:11:in __send__' # /usr/lib/ruby/gems/1.8/gems/rspec-expectations-2.0.0.beta.20/ lib/rspec/matchers/has.rb:11:in matches?’
# /usr/lib/ruby/gems/1.8/gems/rspec-expectations-2.0.0.beta.20/
lib/rspec/expectations/handler.rb:11:in handle_matcher' # /usr/lib/ruby/gems/1.8/gems/rspec-expectations-2.0.0.beta.20/ lib/rspec/expectations/extensions/kernel.rb:27:in should’
# ./spec/requests/layout_links_spec.rb:7
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/example.rb:52:in instance_eval' # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/example.rb:52 # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/example.rb:86:in call’
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/example.rb:86:in with_around_hooks' # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/example.rb:48 # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/example.rb:80:in call’
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/example.rb:80:in with_pending_capture' # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/example.rb:79:in catch’
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/example.rb:79:in with_pending_capture' # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/example.rb:47:in run’
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/example_group.rb:222:in run_examples' # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/example_group.rb:219:in map’
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/example_group.rb:219:in run_examples' # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/example_group.rb:210:in run’
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/command_line.rb:43:in run_examples' # /home/daniel/.gem/ruby/1.8/gems/activesupport-3.0.0.rc/lib/ active_support/dependencies.rb:219:in inject’
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/command_line.rb:43:in each' # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/command_line.rb:43:in inject’
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/command_line.rb:43:in run_examples' # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/command_line.rb:26:in run’
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/reporter.rb:11:in report' # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/command_line.rb:23:in run’
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/runner.rb:46:in run_in_process' # /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/ core/runner.rb:37:in run’
# /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/
core/runner.rb:10
# /usr/bin/rspec:19
.
.
.

I don’t know what to do from here?

On 28 Aug, 21:21, Toni T. [email protected] wrote:

Have selector is a webrat matcher. If you’re not using webrat you
can’t use it. Capybara’s matcher is have_css. I suggest you take a
look at capybara docs.

  • Toni

Aha, that makes perfect sense Toni. Thanks!

Daniel

Have selector is a webrat matcher. If you’re not using webrat you
can’t use it. Capybara’s matcher is have_css. I suggest you take a
look at capybara docs.

  • Toni

On Aug 28, 2:44pm, Daniel L. [email protected] wrote:

  • Switched to beta 20:
    gem ‘sqlite3-ruby’, :require => ‘sqlite3’
    identical .rspec
    daniel@ubuntu/home/daniel/programming/rails_projects/sample_app$ rspec
    lib/rspec/matchers/has.rb:11:in `send
    core/example.rb:52

    /usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/

core/example_group.rb:219:in `run_examples’

/usr/lib/ruby/gems/1.8/gems/rspec-core-2.0.0.beta.20/lib/rspec/

core/runner.rb:37:in `run’
[email protected]://rubyforge.org/mailman/listinfo/rspec-users
Did you run bundle install?