<commit_before>require 'spec_helper'
require 'guard/jasmine/cli'

describe Guard::Jasmine::CLI do

  let(:cli) { ::Guard::Jasmine::CLI }
  let(:runner) { ::Guard::Jasmine::Runner }
  let(:server) { ::Guard::Jasmine::Server }

  before do
    Process.stub(:exit)
    runner.stub(:run)
    server.stub(:start)
    server.stub(:stop)
    cli.stub(:which).and_return '/usr/local/bin/phantomjs'
    cli.stub(:phantomjs_bin_valid?).and_return true
    cli.stub(:runner_available?).and_return true
  end

  describe '.spec' do
    context 'with specified options' do
      context 'for the server' do
        it 'sets the server type' do
          server.should_receive(:start).with(:thin, 3001, 'test', 'spec/javascripts')
          cli.start(['spec', '--server', 'thin'])
        end

        it 'sets the server port' do
          server.should_receive(:start).with(:auto, 4321, 'test', 'spec/javascripts')
          cli.start(['spec', '--port', '4321'])
        end

        it 'sets the spec dir' do
          server.should_receive(:start).with(:auto, 4321, 'test', 'specs')
          cli.start(['spec', '--port', '4321', '-d', 'specs'])
        end
      end

      context 'for the runner' do
        it 'passes the spec paths' do
          runner.should_receive(:run).with(['spec/javascripts/a_spec.js', 'spec/javascripts/another_spec.js'], anything()).and_return [true, []]
          cli.start(['spec', 'spec/javascripts/a_spec.js', 'spec/javascripts/another_spec.js'])
        end

        it 'sets the spec dir' do
          runner.should_receive(:run).with(anything(), hash_including(:spec_dir => 'specs')).and_return [true, []]
          cli.start(['spec', '--spec_dir', 'specs'])
        end

        it 'enables focus mode' do
          runner.should_receive(:run).with(anything(), hash_including(:focus => true)).and_return [true, []]
          cli.start(['spec'])
        end

        it 'sets the jasmine url' do
          runner.should_receive(:run).with(anything(), hash_including(:jasmine_url => 'http://smackaho.st:3000/jasmine')).and_return [true, []]
          cli.start(['spec', '--url', 'http://smackaho.st:3000/jasmine'])
        end

        it 'sets the PhantomJS binary' do
          runner.should_receive(:run).with(anything(), hash_including(:phantomjs_bin => '/bin/phantomjs')).and_return [true, []]
          cli.start(['spec', '--bin', '/bin/phantomjs'])
        end

        it 'sets the timeout' do
          runner.should_receive(:run).with(anything(), hash_including(:timeout => 20000)).and_return [true, []]
          cli.start(['spec', '--timeout', '20000'])
        end

        it 'sets the server environment' do
          runner.should_receive(:run).with(anything(), hash_including(:server_env => 'development')).and_return [true, []]
          cli.start(['spec', '--server_env', 'development'])
        end

        context 'for an invalid console option' do
          it 'sets the console option to failure' do
            runner.should_receive(:run).with(anything(), hash_including(:console => :failure)).and_return [true, []]
            cli.start(['spec', '-c', 'wrong'])
          end
        end

        context 'for a valid errors option' do
          it 'sets the errors option' do
            runner.should_receive(:run).with(anything(), hash_including(:errors => :always)).and_return [true, []]
            cli.start(['spec', '-x', 'always'])
          end
        end

        context 'for an invalid errors option' do
          it 'sets the errors option to failure' do
            runner.should_receive(:run).with(anything(), hash_including(:errors => :failure)).and_return [true, []]
            cli.start(['spec', '-x', 'wrong'])
          end
        end
      end
    end

    context 'without specified options' do
      context 'for the server' do
        it 'sets the server type' do
          server.should_receive(:start).with(:auto, 3001 , 'test', 'spec/javascripts')
          cli.start(['spec'])
        end
      end

      context 'for the runner' do
        context 'without a specific spec dir' do
          it 'runs all default specs when the paths are empty' do
            runner.should_receive(:run).with(['spec/javascripts'], anything()).and_return [true, []]
            cli.start(['spec'])
          end
        end

        context 'with a specific spec dir' do
          it 'runs all specs when the paths are empty' do
            runner.should_receive(:run).with(['specs'], anything()).and_return [true, []]
            cli.start(['spec', '-d', 'specs'])
          end
        end<commit_msg>Fix CLI spec.<commit_after>require 'spec_helper'
require 'guard/jasmine/cli'

describe Guard::Jasmine::CLI do

  let(:cli) { ::Guard::Jasmine::CLI }
  let(:runner) { ::Guard::Jasmine::Runner }
  let(:server) { ::Guard::Jasmine::Server }

  before do
    Process.stub(:exit)
    runner.stub(:run)
    server.stub(:start)
    server.stub(:stop)
    cli.stub(:which).and_return '/usr/local/bin/phantomjs'
    cli.stub(:phantomjs_bin_valid?).and_return true
    cli.stub(:runner_available?).and_return true
  end

  describe '.spec' do
    context 'with specified options' do
      context 'for the server' do
        it 'sets the server type' do
          server.should_receive(:start).with(:thin, 3001, 'test', 'spec/javascripts')
          cli.start(['spec', '--server', 'thin'])
        end

        it 'sets the server port' do
          server.should_receive(:start).with(:auto, 4321, 'test', 'spec/javascripts')
          cli.start(['spec', '--port', '4321'])
        end

        it 'sets the spec dir' do
          server.should_receive(:start).with(:auto, 4321, 'test', 'specs')
          cli.start(['spec', '--port', '4321', '-d', 'specs'])
        end
      end

      context 'for the runner' do
        it 'passes the spec paths' do
          runner.should_receive(:run).with(['spec/javascripts/a_spec.js', 'spec/javascripts/another_spec.js'], anything()).and_return [true, []]
          cli.start(['spec', 'spec/javascripts/a_spec.js', 'spec/javascripts/another_spec.js'])
        end

        it 'sets the spec dir' do
          runner.should_receive(:run).with(anything(), hash_including(:spec_dir => 'specs')).and_return [true, []]
          cli.start(['spec', '--spec_dir', 'specs'])
        end

        it 'enables focus mode' do
          runner.should_receive(:run).with(anything(), hash_including(:focus => true)).and_return [true, []]
          cli.start(['spec'])
        end

        it 'sets the jasmine url' do
          runner.should_receive(:run).with(anything(), hash_including(:jasmine_url => 'http://smackaho.st:3000/jasmine')).and_return [true, []]
          cli.start(['spec', '--url', 'http://smackaho.st:3000/jasmine'])
        end

        it 'sets the PhantomJS binary' do
          runner.should_receive(:run).with(anything(), hash_including(:phantomjs_bin => '/bin/phantomjs')).and_return [true, []]
          cli.start(['spec', '--bin', '/bin/phantomjs'])
        end

        it 'sets the timeout' do
          runner.should_receive(:run).with(anything(), hash_including(:timeout => 20000)).and_return [true, []]
          cli.start(['spec', '--timeout', '20000'])
        end

        it 'sets the server environment' do
          runner.should_receive(:run).with(anything(), hash_including(:server_env => 'development')).and_return [true, []]
          cli.start(['spec', '--server_env', 'development'])
        end

        context 'for an invalid console option' do
          it 'sets the console option to failure' do
            runner.should_receive(:run).with(anything(), hash_including(:console => :failure)).and_return [true, []]
            cli.start(['spec', '--console', 'wrong'])
          end
        end

        context 'for a valid errors option' do
          it 'sets the errors option' do
            runner.should_receive(:run).with(anything(), hash_including(:errors => :always)).and_return [true, []]
            cli.start(['spec', '--errors', 'always'])
          end
        end

        context 'for an invalid errors option' do
          it 'sets the errors option to failure' do
            runner.should_receive(:run).with(anything(), hash_including(:errors => :failure)).and_return [true, []]
            cli.start(['spec', '--errors', 'wrong'])
          end
        end
      end
    end

    context 'without specified options' do
      context 'for the server' do
        it 'sets the server type' do
          server.should_receive(:start).with(:auto, 3001 , 'test', 'spec/javascripts')
          cli.start(['spec'])
        end
      end

      context 'for the runner' do
        context 'without a specific spec dir' do
          it 'runs all default specs when the paths are empty' do
            runner.should_receive(:run).with(['spec/javascripts'], anything()).and_return [true, []]
            cli.start(['spec'])
          end
        end

        context 'with a specific spec dir' do
          it 'runs all specs when the paths are empty' do
            runner.should_receive(:run).with(['specs'], anything()).and_return [true, []]
            cli.start(['spec', '-d', 'specs'])
          end
        end
{'fraction_non_alphanumeric': 0.15631481279336318, 'fraction_numerical': 0.009169304661063202, 'mean_word_length': 2.530635838150289, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '3078624', 'n_tokens_mistral': 2855, 'n_tokens_neox': 2637, 'n_words': 665}