Forum: Ruby Stack level too deep

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
marcus (Guest)
on 2006-02-28 09:18
(Received via mailing list)
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
Meinrad R. (Guest)
on 2006-02-28 09:29
(Received via mailing list)
On 2/28/06, marcus <removed_email_address@domain.invalid> 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
Robert K. (Guest)
on 2006-02-28 10:56
(Received via mailing list)
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. (Guest)
on 2006-02-28 12:58
(Received via mailing list)
On 2/28/06, Robert K. <removed_email_address@domain.invalid> 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. (Guest)
on 2006-02-28 13:33
(Received via mailing list)
Meinrad R. wrote:
> into a loop, but it will not be as easy to read anymore.
That's exactly the other recommendation I gave. :-)

    robert
marcus (Guest)
on 2006-02-28 18:16
(Received via mailing list)
Robert K. skrev:
>> into a loop, but it will not be as easy to read anymore.
>
> That's exactly the other recommendation I gave. :-)
>
>     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
Eric C. (Guest)
on 2006-03-01 00:34
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.
Logan C. (Guest)
on 2006-03-01 04:19
(Received via mailing list)
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.
Daniel Lidström (Guest)
on 2010-08-29 08:02
(Received via mailing list)
On 28 Aug, 04:13, Justin Ko <removed_email_address@domain.invalid> 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
Toni T. (Guest)
on 2010-08-29 10:25
(Received via mailing list)
I think you're having this problem:
http://github.com/rspec/rspec-rails/issues#issue/140

- Toni
Justin Ko (Guest)
on 2010-08-29 14:09
(Received via mailing list)
On Aug 28, 6:59 am, Daniel Lidström <removed_email_address@domain.invalid> 
wrote:
> group :development, :test do
>
> Regards,
>
> Daniel Lidström
> Stockholm, Sweden
> _______________________________________________
> rspec-users mailing list
> removed_email_address@domain.invalid://rubyforge.org/mailman/listinfo/rspec-users

Did you remove webrat from the Gemfile?
David C. (Guest)
on 2010-08-29 14:34
(Received via mailing list)
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.
Daniel Lidström (Guest)
on 2010-08-29 15:57
(Received via mailing list)
On 28 Aug, 19:32, David C. <removed_email_address@domain.invalid> 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?
Toni T. (Guest)
on 2010-08-29 16:31
(Received via mailing list)
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
Daniel Lidström (Guest)
on 2010-08-29 17:53
(Received via mailing list)
On 28 Aug, 21:21, Toni T. <removed_email_address@domain.invalid> 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
Justin Ko (Guest)
on 2012-06-01 14:42
(Received via mailing list)
On Aug 28, 2:44pm, Daniel L. <removed_email_address@domain.invalid> 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'
> removed_email_address@domain.invalid://rubyforge.org/mailman/listinfo/rspec-users
Did you run bundle install?
This topic is locked and can not be replied to.