<commit_before>require File.dirname(__FILE__) + '/../spec_helper'
require File.dirname(__FILE__) + '/fixtures/ensure'

describe "The ensure keyword" do
  it "executes as a result of a throw within it's block" do
    i = []
    catch(:exit) do
      begin
        i << :begin
        throw :exit
      ensure
        i << :ensure
      end
      i << :after_ensure
    end    
    i.should == [:begin,:ensure]
  end

  it "is run when calling a block that contains a return" do
    t = EnsureSpec::Test.new
    t.do_test.should == :did_test
    t.values.should == [:start, :in_block, :end]
  end
end
<commit_msg>Add spec for exception handling inside ensure block.<commit_after>require File.dirname(__FILE__) + '/../spec_helper'
require File.dirname(__FILE__) + '/fixtures/ensure'

describe "The ensure keyword" do
  it "executes as a result of a throw within it's block" do
    i = []
    catch(:exit) do
      begin
        i << :begin
        throw :exit
      ensure
        i << :ensure
      end
      i << :after_ensure
    end    
    i.should == [:begin,:ensure]
  end

  it "is run when calling a block that contains a return" do
    t = EnsureSpec::Test.new
    t.do_test.should == :did_test
    t.values.should == [:start, :in_block, :end]
  end
  
  it "propagates the original exception even when exceptions are caught inside the ensure block" do
    code = lambda do
      begin
        raise EOFError, "foo"
      ensure
        "".size rescue nil
      end
    end
    code.should raise_error(EOFError)
  end
end

{'fraction_non_alphanumeric': 0.1026814911706998, 'fraction_numerical': 0.0, 'mean_word_length': 2.3849557522123894, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4424742', 'n_tokens_mistral': 479, 'n_tokens_neox': 473, 'n_words': 164}