Title / Description
Code describe 'Object#stub' do before do @array = %w(aardvark bonobo chipmunk dromedary) end it 'can stub a method within the scope of a block' do @array.length.must_equal 4 @array.stub(:length, 10) do @array.length.must_equal 10 end @array.length.must_equal 4 end it 'can stub a method using a callable object to generate return values' do callable = -> { 'ant' } @array.stub(:shift, callable) do @array.shift.must_equal 'ant' @array.shift.must_equal 'ant' end @array.shift.must_equal 'aardvark' @array.shift.must_equal 'bonobo' end describe 'stubbing a non-existent method' do it 'raises an error' do -> { @array.stub(:foo, :bar) { } }.must_raise NameError end end end
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code