<commit_before>require 'spec_helper'
require 'thor'

describe Clamshell::Dsl do

  before :all do
    Clamshell.ui = Clamshell::UI.new(Thor::Shell::Basic.new)
  end

  describe "builder" do

    out = <<-O.gsub /^\s+/, ''  # trim leading whitespace
      export PATH=/usr/bin
      export PATH=${PATH}/usr/bin
      export PATH=/usr/bin${PATH}
      O

    out.rstrip!   # Removes last newline from heredoc

    it "should print to standard out" do
      capture(:stdout) do
        Clamshell::Dsl.build(FIXTURES_DIR + '/Dependencies.list')
      end.should == out + "\n"    # Shell.ui adds a newline
    end

    describe "#--shell_out=file" do
      it "should print to a file" do
        Clamshell.settings[:shell_out] = "temp_file"

        file = mock('file')
        File.should_receive(:open).with("temp_file", "w").and_yield(file)
        file.should_receive(:write).with(out)
        Clamshell::Dsl.build(FIXTURES_DIR + '/Dependencies.list')

        Clamshell.settings[:shell_out] = nil
      end
    end
  end

  after :all do
    Clamshell.ui = Clamshell::SilentUI.new
  end
end
<commit_msg>Add test writing to an invalid location<commit_after>require 'spec_helper'
require 'thor'

describe Clamshell::Dsl do

  before :all do
    Clamshell.ui = Clamshell::UI.new(Thor::Shell::Basic.new)
  end

  describe "builder" do

    out = <<-O.gsub /^\s+/, ''  # trim leading whitespace
      export PATH=/usr/bin
      export PATH=${PATH}/usr/bin
      export PATH=/usr/bin${PATH}
      O

    out.rstrip!   # Removes last newline from heredoc

    it "should print to standard out" do
      capture(:stdout) do
        Clamshell::Dsl.build(FIXTURES_DIR + '/Dependencies.list')
      end.should == out + "\n"    # Shell.ui adds a newline
    end

    describe "#--shell_out=file" do
      it "should print to a file" do
        Clamshell.settings[:shell_out] = "temp_file"

        file = mock('file')
        File.should_receive(:open).with("temp_file", "w").and_yield(file)
        file.should_receive(:write).with(out)
        Clamshell::Dsl.build(FIXTURES_DIR + '/Dependencies.list')
      end

      it "should raise an error when it can't write" do
        Clamshell.settings[:shell_out] = "/root/temp_file"
        lambda do
          Clamshell::Dsl.build(FIXTURES_DIR + '/Dependencies.list')
        end.should raise_error(StandardError, /Permission denied/)

      end

      after :each do
        Clamshell.settings[:shell_out] = nil
      end
    end
  end

  after :all do
    Clamshell.ui = Clamshell::SilentUI.new
  end
end

{'fraction_non_alphanumeric': 0.1238694455367676, 'fraction_numerical': 0.0, 'mean_word_length': 2.6394849785407724, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3681598', 'n_tokens_mistral': 881, 'n_tokens_neox': 827, 'n_words': 201}