Skip to content

Instantly share code, notes, and snippets.

@pex
Last active August 29, 2015 14:00
Show Gist options
  • Save pex/103e76939b881d9a1ee0 to your computer and use it in GitHub Desktop.
Save pex/103e76939b881d9a1ee0 to your computer and use it in GitHub Desktop.
"Stack level is too deep" when stubbing rather complex chained method and a prepended module
STACK = []
module Concerns
module Done
def on_done
STACK << 'Concerns::Done'
end
end
module DonePrepender
def on_done
STACK << 'Concerns::DonePrepender'
ensure
super
end
end
end
module Foo
class Base
include ::Concerns::Done
def on_done
STACK << 'Foo:Base'
end
end
class Bar < Base
prepend ::Concerns::DonePrepender
def on_done
super
STACK << 'Foo:Bar'
end
end
end
describe Foo::Bar do
subject { STACK }
let(:call) { Foo::Bar.new.on_done }
context 'calling through' do
before { call }
it { should eq %w(Concerns::DonePrepender Foo:Base Foo:Bar) }
end
context 'stubbing on_done' do
before { Foo::Bar.any_instance.stub(:on_done) }
it 'is stubbale' do
expect { call }.to_not raise_error
end
end
end
/usr/local/opt/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/bundler/gems/rspec-support-2d12b1e23680/lib/rspec/support/caller_filter.rb:8: warning: already initialized constant RSpec::CallerFilter::RSPEC_LIBS
/usr/local/Cellar/rbenv/HEAD/versions/2.0.0-p353/lib/ruby/gems/2.0.0/bundler/gems/rspec-support-2d12b1e23680/lib/rspec/support/caller_filter.rb:8: warning: previous definition of RSPEC_LIBS was here
/usr/local/opt/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/bundler/gems/rspec-support-2d12b1e23680/lib/rspec/support/caller_filter.rb:17: warning: already initialized constant RSpec::CallerFilter::ADDITIONAL_TOP_LEVEL_FILES
/usr/local/Cellar/rbenv/HEAD/versions/2.0.0-p353/lib/ruby/gems/2.0.0/bundler/gems/rspec-support-2d12b1e23680/lib/rspec/support/caller_filter.rb:17: warning: previous definition of ADDITIONAL_TOP_LEVEL_FILES was here
/usr/local/opt/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/bundler/gems/rspec-support-2d12b1e23680/lib/rspec/support/caller_filter.rb:19: warning: already initialized constant RSpec::CallerFilter::LIB_REGEX
/usr/local/Cellar/rbenv/HEAD/versions/2.0.0-p353/lib/ruby/gems/2.0.0/bundler/gems/rspec-support-2d12b1e23680/lib/rspec/support/caller_filter.rb:19: warning: previous definition of LIB_REGEX was here
.F
Failures:
1) Foo::Bar stubbing on_done is stubbale
Failure/Error: expect { call }.to_not raise_error
NoMethodError:
undefined method `format_backtrace' for RSpec::Core::BacktraceFormatter:Class
# ./spec.rb:51:in `block (3 levels) in <top (required)>'
Failures:
1) Foo::Bar stubbing on_done is stubbale
Failure/Error: expect { call }.to_not raise_error
expected no Exception, got #<SystemStackError: stack level too deep> with backtrace:
# /usr/local/opt/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-support-3.0.0.beta2/lib/rspec/support.rb:19
#
# Showing full backtrace because every line was filtered out.
# See docs for RSpec::Configuration#backtrace_exclusion_patterns and
# RSpec::Configuration#backtrace_inclusion_patterns for more information.
# ./spec.rb:51:in `block (3 levels) in <top (required)>'
Finished in 0.0183 seconds
2 examples, 1 failure
Failed examples:
rspec ./spec.rb:50 # Foo::Bar stubbing on_done is stubbale
Failures:
1) Foo::Bar stubbing on_done is stubbale
Failure/Error: expect { call }.to_not raise_error
expected no Exception, got #<SystemStackError: stack level too deep> with backtrace:
# /usr/local/opt/rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-mocks-2.14.6/lib/rspec/mocks/any_instance/message_chains.rb:52
# ./spec.rb:51:in `block (3 levels) in <top (required)>'
Finished in 0.07066 seconds
2 examples, 1 failure
Failed examples:
rspec ./spec.rb:50 # Foo::Bar stubbing on_done is stubbale
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment