<commit_before>require 'spec_helper'

describe Guard::Jasmine do

  let(:guard) { Guard::Jasmine.new }

  let(:runner) { Guard::Jasmine::Runner }
  let(:inspector) { Guard::Jasmine::Inspector }
  let(:formatter) { Guard::Jasmine::Formatter }

  before do
    inspector.stub(:clean).and_return { |specs| specs }
    runner.stub(:run).and_return [true, []]
    formatter.stub(:notify)
  end

  describe '#initialize' do
    context 'when no options are provided' do
      it 'sets a default :jasmine_url option' do
        guard.options[:jasmine_url].should eql 'http://localhost:3000/jasmine'
      end

      it 'sets a default :phantomjs_bin option' do
        guard.options[:phantomjs_bin].should eql '/usr/local/bin/phantomjs'
      end

      it 'sets a default :all_on_start option' do
        guard.options[:all_on_start].should be_true
      end

      it 'sets a default :notifications option' do
        guard.options[:notification].should be_true
      end

      it 'sets a default :hide_success option' do
        guard.options[:hide_success].should be_false
      end

      it 'sets a default :keep_failed option' do
        guard.options[:keep_failed].should be_true
      end

      it 'sets a default :all_after_pass option' do
        guard.options[:all_after_pass].should be_true
      end

      it 'sets last run failed to false' do
        guard.last_run_failed.should be_false
      end

      it 'sets last failed paths to empty' do
        guard.last_failed_paths.should be_empty
      end
    end

    context 'with other options than the default ones' do
      let(:guard) { Guard::Jasmine.new(nil, { :jasmine_url    => 'http://192.168.1.5/jasmine',
                                              :phantomjs_bin  => '~/bin/phantomjs',
                                              :all_on_start   => false,
                                              :notification   => false,
                                              :hide_success   => true,
                                              :keep_failed    => false,
                                              :all_after_pass => false }) }

      it 'sets the :jasmine_url option' do
        guard.options[:jasmine_url].should eql 'http://192.168.1.5/jasmine'
      end

      it 'sets the :phantomjs_bin option' do
        guard.options[:phantomjs_bin].should eql '~/bin/phantomjs'
      end

      it 'sets the :all_on_start option' do
        guard.options[:all_on_start].should be_false
      end

      it 'sets the :notifications option' do
        guard.options[:notification].should be_false
      end

      it 'sets the :hide_success option' do
        guard.options[:hide_success].should be_true
      end

      it 'sets a default :keep_failed option' do
        guard.options[:keep_failed].should be_false
      end

      it 'sets a default :all_after_pass option' do
        guard.options[:all_after_pass].should be_false
      end
    end
  end

  describe '.start' do
    context 'with the Jasmine runner available' do
      let(:http) { mock('http') }

      before do
        http.stub_chain(:request, :code).and_return 200
        Net::HTTP.stub(:start).and_yield http
      end

      it 'does show that the runner is available' do
        formatter.should_receive(:info).with "Jasmine test runner is available at http://localhost:3000/jasmine"
        guard.start
      end
    end

    context 'without the Jasmine runner available' do
      let(:http) { mock('http') }

      context 'because the connection is refused' do
        before do
          http.stub_chain(:request, :code).and_return 404
          Net::HTTP.stub(:start).and_raise Errno::ECONNREFUSED
        end

        it 'does show that the runner is not available' do
          formatter.should_receive(:error).with "Jasmine test runner not available at http://localhost:3000/jasmine"
          guard.start
        end
      end

      context 'because the http status is not OK' do
        before do
          http.stub_chain(:request, :code).and_return 404
          Net::HTTP.stub(:start).and_yield http
        end

        it 'does show that the runner is not available' do
          formatter.should_receive(:error).with "Jasmine test runner not available at http://localhost:3000/jasmine"
          guard.start
        end
      end

      context 'with notifications enabled' do
        it 'shows a failing system notification' do
          formatter.should_receive(:notify).with("Jasmine test runner not available at http://localhost:3000/jasmine",
                                                 :title    => 'Jasmine test runner not available',
                                                 :image    => :failed,
                                                 :priority => 2)
          guard.start
        end
      end
    end

    context 'with :all_on_start set to true' do
      let(:guard) { Guard::Jasmine.new(nil, { :all_on_start => true }) }

      context 'with the Jasmine runner available' do
        before do
          guard.stub(:jasmine_runner_available?).and_return true
        end

        it 'triggers .run_all' do
          guard.should_receive(:run_all)
          guard.start
        end
      end

      context 'without the Jasmine runner available' do
        before do
          guard.stub(:jasmine_runner_available?).and_return false<commit_msg>Fix local failing spec: Make the check fail.<commit_after>require 'spec_helper'

describe Guard::Jasmine do

  let(:guard) { Guard::Jasmine.new }

  let(:runner) { Guard::Jasmine::Runner }
  let(:inspector) { Guard::Jasmine::Inspector }
  let(:formatter) { Guard::Jasmine::Formatter }

  before do
    inspector.stub(:clean).and_return { |specs| specs }
    runner.stub(:run).and_return [true, []]
    formatter.stub(:notify)
  end

  describe '#initialize' do
    context 'when no options are provided' do
      it 'sets a default :jasmine_url option' do
        guard.options[:jasmine_url].should eql 'http://localhost:3000/jasmine'
      end

      it 'sets a default :phantomjs_bin option' do
        guard.options[:phantomjs_bin].should eql '/usr/local/bin/phantomjs'
      end

      it 'sets a default :all_on_start option' do
        guard.options[:all_on_start].should be_true
      end

      it 'sets a default :notifications option' do
        guard.options[:notification].should be_true
      end

      it 'sets a default :hide_success option' do
        guard.options[:hide_success].should be_false
      end

      it 'sets a default :keep_failed option' do
        guard.options[:keep_failed].should be_true
      end

      it 'sets a default :all_after_pass option' do
        guard.options[:all_after_pass].should be_true
      end

      it 'sets last run failed to false' do
        guard.last_run_failed.should be_false
      end

      it 'sets last failed paths to empty' do
        guard.last_failed_paths.should be_empty
      end
    end

    context 'with other options than the default ones' do
      let(:guard) { Guard::Jasmine.new(nil, { :jasmine_url    => 'http://192.168.1.5/jasmine',
                                              :phantomjs_bin  => '~/bin/phantomjs',
                                              :all_on_start   => false,
                                              :notification   => false,
                                              :hide_success   => true,
                                              :keep_failed    => false,
                                              :all_after_pass => false }) }

      it 'sets the :jasmine_url option' do
        guard.options[:jasmine_url].should eql 'http://192.168.1.5/jasmine'
      end

      it 'sets the :phantomjs_bin option' do
        guard.options[:phantomjs_bin].should eql '~/bin/phantomjs'
      end

      it 'sets the :all_on_start option' do
        guard.options[:all_on_start].should be_false
      end

      it 'sets the :notifications option' do
        guard.options[:notification].should be_false
      end

      it 'sets the :hide_success option' do
        guard.options[:hide_success].should be_true
      end

      it 'sets a default :keep_failed option' do
        guard.options[:keep_failed].should be_false
      end

      it 'sets a default :all_after_pass option' do
        guard.options[:all_after_pass].should be_false
      end
    end
  end

  describe '.start' do
    context 'with the Jasmine runner available' do
      let(:http) { mock('http') }

      before do
        http.stub_chain(:request, :code).and_return 200
        Net::HTTP.stub(:start).and_yield http
      end

      it 'does show that the runner is available' do
        formatter.should_receive(:info).with "Jasmine test runner is available at http://localhost:3000/jasmine"
        guard.start
      end
    end

    context 'without the Jasmine runner available' do
      let(:http) { mock('http') }

      context 'because the connection is refused' do
        before do
          Net::HTTP.stub(:start).and_raise Errno::ECONNREFUSED
        end

        it 'does show that the runner is not available' do
          formatter.should_receive(:error).with "Jasmine test runner not available at http://localhost:3000/jasmine"
          guard.start
        end
      end

      context 'because the http status is not OK' do
        before do
          http.stub_chain(:request, :code).and_return 404
          Net::HTTP.stub(:start).and_yield http
        end

        it 'does show that the runner is not available' do
          formatter.should_receive(:error).with "Jasmine test runner not available at http://localhost:3000/jasmine"
          guard.start
        end
      end

      context 'with notifications enabled' do
        before do
          Net::HTTP.stub(:start).and_raise Errno::ECONNREFUSED
        end

        it 'shows a failing system notification' do
          formatter.should_receive(:notify).with("Jasmine test runner not available at http://localhost:3000/jasmine",
                                                 :title    => 'Jasmine test runner not available',
                                                 :image    => :failed,
                                                 :priority => 2)
          guard.start
        end
      end
    end

    context 'with :all_on_start set to true' do
      let(:guard) { Guard::Jasmine.new(nil, { :all_on_start => true }) }

      context 'with the Jasmine runner available' do
        before do
          guard.stub(:jasmine_runner_available?).and_return true
        end

        it 'triggers .run_all' do
          guard.should_receive(:run_all)
          guard.start
        end
      end

      context 'without the Jasmine runner available' do
        before do
          guard.stub(:jasmine_runner_available?).and_return false
{'fraction_non_alphanumeric': 0.08710962839403207, 'fraction_numerical': 0.008247613752200908, 'mean_word_length': 1.9502460360852925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4595571', 'n_tokens_mistral': 3082, 'n_tokens_neox': 2855, 'n_words': 846}