<commit_before>require 'spec_helper'

describe Guard::Cucumber::Focuser do

  let(:focuser)     { Guard::Cucumber::Focuser }
  let(:focus_tag)   { '@focus' }
  let(:null_device) { RUBY_PLATFORM.index('mswin') ? 'NUL' : '/dev/null' }

  let(:dir)       { 'features' }
  let(:path)      { 'foo.feature' }
  let(:path_two)  { 'bar.feature' }

  describe '.focus' do
    context 'when passed an empty paths list' do
      it 'returns false' do
        focuser.focus([], '@focus').should be_false
      end
    end

    context 'when passed a paths argument' do
      let(:file) do
        StringIO.new <<-EOS
          @focus
          Scenario: Foo
          Given bar
          Scenario: Bar
          Given lorem
          @focus
          Scenario: Ipsum
          Given dolor
        EOS
      end

      let(:file_two) do
        StringIO.new <<-EOS
          @focus
          Scenario: Lorem
          Given ipsum
          @focus
          Scenario: Bar
          Given lorem
          Scenario: Dolor
          Given sit
        EOS
      end

      before do
        File.should_receive(:open).with(path, 'r').and_yield(file)
        File.should_receive(:open).with(path_two, 'r').and_yield(file_two)
      end

      it 'returns an array of paths updated to focus on line numbers' do
        paths = [path, path_two]

        focuser.focus(paths, focus_tag).should eql([
          'foo.feature:1:6',
          'bar.feature:1:4'
        ])
      end
    end
  end

  describe '.scan_path_for_focus_tag' do
    context 'file with focus tags in it' do
      let(:file) do
        StringIO.new <<-EOS
          @focus<commit_msg>Test edge cases.<commit_after>require 'spec_helper'

describe Guard::Cucumber::Focuser do

  let(:focuser)     { Guard::Cucumber::Focuser }
  let(:focus_tag)   { '@focus' }
  let(:null_device) { RUBY_PLATFORM.index('mswin') ? 'NUL' : '/dev/null' }

  let(:dir)       { 'features' }
  let(:path)      { 'foo.feature' }
  let(:path_two)  { 'bar.feature' }

  describe '.focus' do
    context 'when passed an empty paths list' do
      it 'returns false' do
        focuser.focus([], '@focus').should be_false
      end
    end

    context 'when passed a paths argument' do
      let(:file) do
        StringIO.new <<-EOS
          @focus
          Scenario: Foo
          Given bar
          Scenario: Bar
          Given focus lorem
          @focus
          Scenario: Ipsum
          Given dolor
        EOS
      end

      let(:file_two) do
        StringIO.new <<-EOS
          @focus
          Scenario: Lorem
          Given ipsum
          @focus
          Scenario: Bar
          Given lorem
          Scenario: Dolor
          Given sit focus
        EOS
      end

      before do
        File.should_receive(:open).with(path, 'r').and_yield(file)
        File.should_receive(:open).with(path_two, 'r').and_yield(file_two)
      end

      it 'returns an array of paths updated to focus on line numbers' do
        paths = [path, path_two]

        focuser.focus(paths, focus_tag).should eql([
          'foo.feature:1:6',
          'bar.feature:1:4'
        ])
      end
    end
  end

  describe '.scan_path_for_focus_tag' do
    context 'file with focus tags in it' do
      let(:file) do
        StringIO.new <<-EOS
          @focus
{'fraction_non_alphanumeric': 0.1070448307410796, 'fraction_numerical': 0.002439768222018908, 'mean_word_length': 1.7986348122866893, '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': '6183497', 'n_tokens_mistral': 1067, 'n_tokens_neox': 1024, 'n_words': 269}