<commit_before>require File.expand_path(File.join(File.dirname(__FILE__),'..','..','spec_helper'))

describe Scaffolder::Tool::Help do

  it "should inherit from Scaffolder::Tool" do
    described_class.superclass.should == Scaffolder::Tool
  end

  it "should return the description of the tool" do
    desc = "Help information for scaffolder commands"
    described_class.description.should == desc
  end

  USAGE = <<-MSG.gsub(/^ {6}/, '')
      usage: scaffolder [--version] COMMAND scaffold-file sequence-file
      [options]

      Commands:
    MSG

  before(:each) do
    @settings = Hash.new
    @settings.stubs(:rest).returns([])
  end

  describe "execution with no command and the version argument" do

    subject do
      @settings[:version] = true
      described_class.new(@settings)
    end

    it "should not raise an error" do
      lambda{ subject.execute }.should_not raise_error
    end

    it "should return the version number" do
      version = File.read('VERSION').strip
      subject.execute.should == "scaffolder tool version " + version
    end

  end

  describe "execution with no command" do

    subject do
      described_class.new(@settings)
    end

    it "should not raise an error" do
      lambda{ subject.execute }.should_not raise_error
    end

    it "should contain the usage information" do
      subject.execute.should include(USAGE)
    end

    it "should contain each tool information" do
      tool_subclasses.each do |cls|
        subject.execute.should include(cls.description)
      end
    end

  end

  describe "execution with an invalid command arguments" do

    subject do
      @settings[:unknown_tool] = 'unknown_command'
      described_class.new(@settings)
    end

    it "should raise an error" do
      lambda{ subject.execute }.should(raise_error(ArgumentError,
        "Unknown command 'unknown_command'.\nSee 'scaffolder help'."))
    end

  end

  describe "execution with the name of a scaffolder tool command" do

    before(:each) do
      @tool = Class.new(described_class)
      described_class.superclass.const_set('Fake',@tool)

      @man_dir = File.join(%W|#{File.dirname(__FILE__)} .. .. .. man| )
      @fake_man = File.join(@man_dir,'scaffolder-fake.1.ronn')
    end

    after(:each) do
      described_class.superclass.send(:remove_const,'Fake')
    end

    subject do
      @settings.stubs(:rest).returns(['fake'])
      described_class.new(@settings)
    end

    it "should not raise an error" do
      Kernel.stubs(:system).
        with("ronn -m #{File.expand_path(@fake_man)}")
      lambda{ subject.execute }.should_not raise_error
    end

    it "should call ronn on the command line with the man file location" do
      Kernel.expects(:system).
        with("ronn -m #{File.expand_path(@fake_man)}")
      subject.execute
    end

  end

  describe "execution with the name of a unknown command" do

    subject do
      @settings.stubs(:rest).returns(['fake'])
      described_class.new(@settings)
    end

    it "should raise an error" do
      lambda{ subject.execute }.should(raise_error(ArgumentError,
        "Unknown command 'fake'.\nSee 'scaffolder help'."))
    end

  end
end<commit_msg>Fix broken spec for test man pages<commit_after>require File.expand_path(File.join(File.dirname(__FILE__),'..','..','spec_helper'))

describe Scaffolder::Tool::Help do

  it "should inherit from Scaffolder::Tool" do
    described_class.superclass.should == Scaffolder::Tool
  end

  it "should return the description of the tool" do
    desc = "Help information for scaffolder commands"
    described_class.description.should == desc
  end

  USAGE = <<-MSG.gsub(/^ {6}/, '')
      usage: scaffolder [--version] COMMAND scaffold-file sequence-file
      [options]

      Commands:
    MSG

  before(:each) do
    @settings = Hash.new
    @settings.stubs(:rest).returns([])
  end

  describe "execution with no command and the version argument" do

    subject do
      @settings[:version] = true
      described_class.new(@settings)
    end

    it "should not raise an error" do
      lambda{ subject.execute }.should_not raise_error
    end

    it "should return the version number" do
      version = File.read('VERSION').strip
      subject.execute.should == "scaffolder tool version " + version
    end

  end

  describe "execution with no command" do

    subject do
      described_class.new(@settings)
    end

    it "should not raise an error" do
      lambda{ subject.execute }.should_not raise_error
    end

    it "should contain the usage information" do
      subject.execute.should include(USAGE)
    end

    it "should contain each tool information" do
      tool_subclasses.each do |cls|
        subject.execute.should include(cls.description)
      end
    end

  end

  describe "execution with an invalid command arguments" do

    subject do
      @settings[:unknown_tool] = 'unknown_command'
      described_class.new(@settings)
    end

    it "should raise an error" do
      lambda{ subject.execute }.should(raise_error(ArgumentError,
        "Unknown command 'unknown_command'.\nSee 'scaffolder help'."))
    end

  end

  describe "execution with the name of a scaffolder tool command" do

    before(:each) do
      @tool = Class.new(Scaffolder::Tool)
      described_class.superclass.const_set('Fake',@tool)

      @man_dir = File.join(%W|#{File.dirname(__FILE__)} .. .. .. man| )
      @fake_man = File.join(@man_dir,'scaffolder-fake.1.ronn')
    end

    after(:each) do
      described_class.superclass.send(:remove_const,'Fake')
    end

    subject do
      @settings.stubs(:rest).returns(['fake'])
      described_class.new(@settings)
    end

    it "should not raise an error" do
      Kernel.stubs(:system).with("ronn -m #{File.expand_path(@fake_man)}")
      lambda{ subject.execute }.should_not raise_error
    end

    it "should call ronn on the command line with the man file location" do
      Kernel.expects(:system).with("ronn -m #{File.expand_path(@fake_man)}")
      subject.execute
    end

  end

  describe "execution with the name of a unknown command" do

    subject do
      @settings.stubs(:rest).returns(['fake'])
      described_class.new(@settings)
    end

    it "should raise an error" do
      lambda{ subject.execute }.should(raise_error(ArgumentError,
        "Unknown command 'fake'.\nSee 'scaffolder help'."))
    end

  end
end
{'fraction_non_alphanumeric': 0.10694183864915573, 'fraction_numerical': 0.0006253908692933083, 'mean_word_length': 2.9708255741775296, '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': '4492294', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1848, 'n_words': 545}