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

# The CocoaPods namespace
#
module Pod
  describe Command::Plugins do

    before do
      argv = CLAide::ARGV.new([])
      @command = Command::Plugins.new(argv)
    end

    it 'registers itself' do
      Command.parse(%w(plugins)).should.be.instance_of Command::Plugins
    end

    it 'exists' do
      @command.should.not.be.nil?
    end

    it 'has a json attribute that starts out nil' do
      @command.json.should.be.nil?
    end

    it 'downloads the json file' do
      json = File.read(fixture('plugins.json'))
      stub_request(:get, Command::Plugins::PLUGINS_URL).to_return(:status => 200, :body => json, :headers => {})
      @command.download_json
      @command.json.should.not.be.nil?
      @command.json.should.be.kind_of? Hash
      @command.json['plugins'].size.should.eql? 3
    end

    it 'handles empty/bad JSON' do
      stub_request(:get, Command::Plugins::PLUGINS_URL).to_return(:status => 200, :body => 'This is not JSON', :headers => {})
      @command.run
      UI.output.should.include('Could not download plugins list from cocoapods.org')
      @command.json.should.be.nil?
    end

    it 'notifies the user if the download fails' do
      stub_request(:get, Command::Plugins::PLUGINS_URL).to_return(:status => [404, 'Not Found'])
      @command.run
      UI.output.should.include('Could not download plugins list from cocoapods.org')
      @command.json.should.be.nil?
    end

    it 'prints out each plugin' do
      json_fixture = fixture('plugins.json')
      @json = JSON.parse(File.read(json_fixture))
      @command.json = @json
      @command.run
      UI.output.should.include('github.com/CocoaPods/cocoapods-fake')
      UI.output.should.include('github.com/chneukirchen/bacon')
    end

    it 'detects if a gem is installed' do
      @command.installed?('bacon').should.be.true
      @command.installed?('fake-fake-fake-gem').should.be.false
    end

  end

  describe Command::Plugins::Search do
    extend SpecHelper::PluginSearchCommand

    it 'registers itself' do
      Command.parse(%w(plugins search)).should.be.instance_of Command::Plugins::Search
    end

    it 'should require a query is passed in' do
      @command = search_command(argv)
      # rubocop:disable Lambda
      lambda { @command.validate! }
           .should.raise(CLAide::Help)
            .message.should.match(/A search query is required./)
      # rubocop:enable Lambda
    end

    it 'should require a non-empty name is passed in' do
      @command = search_command(argv(''))
      # rubocop:disable Lambda
      lambda { @command.validate! }
            .should.raise(CLAide::Help)
            .message.should.match(/A search query is required./)
      # rubocop:enable Lambda
    end

    it 'should require a valid regex' do
      @command = search_command(argv('[invalid'))
      # rubocop:disable Lambda
      lambda { @command.validate! }
           .should.raise(CLAide::Help)
            .message.should.match(/A valid regular expression is required./)
      # rubocop:enable Lambda
    end

    it 'should filter plugins by name when no full search' do
      json = File.read(fixture('plugins.json'))
      stub_request(:get, Command::Plugins::PLUGINS_URL).to_return(:status => 200, :body => json, :headers => {})
      @command = search_command(argv('search'))
      @command.run
      UI.output.should.include('-> CocoaPods Searchable Fake Gem')
    end

    it 'should filter plugins by name and description when full search' do
      json = File.read(fixture('plugins.json'))
      stub_request(:get, Command::Plugins::PLUGINS_URL).to_return(:status => 200, :body => json, :headers => {})
      @command = search_command(argv('--full', 'search'))
      @command.run
      UI.output.should.include('-> CocoaPods Fake Gem')
      UI.output.should.include('-> CocoaPods Searchable Fake Gem')
    end
  end

  describe Command::Plugins::Create do
    extend SpecHelper::PluginCreateCommand

    it 'registers itself' do
      Command.parse(%w(plugins create)).should.be.instance_of Command::Plugins::Create
    end

    it 'should require a name is passed in' do
      @command = create_command(argv)
      # rubocop:disable Lambda
      lambda { @command.validate! }
            .should.raise(CLAide::Help)
            .message.should.match(/A name for the plugin is required./)
      # rubocop:enable Lambda
    end

    it 'should require a non-empty name is passed in' do
      @command = create_command(argv(''))
      # rubocop:disable Lambda
      lambda { @command.validate! }
            .should.raise(CLAide::Help)
            .message.should.match(/A name for the plugin is required./)
      # rubocop:enable Lambda
    end
<commit_msg>Small bacon tests fixes / improvements<commit_after>require File.expand_path('../../spec_helper', __FILE__)

# The CocoaPods namespace
#
module Pod
  describe Command::Plugins do

    before do
      argv = CLAide::ARGV.new([])
      @command = Command::Plugins.new(argv)
    end

    it 'registers itself' do
      Command.parse(%w(plugins)).should.be.instance_of Command::Plugins
    end

    it 'exists' do
      @command.should.not.be.nil?
    end

    it 'has a json attribute that starts out nil' do
      @command.json.should.be.nil?
    end

    it 'downloads the json file' do
      json = File.read(fixture('plugins.json'))
      stub_request(:get, Command::Plugins::PLUGINS_URL).to_return(:status => 200, :body => json, :headers => {})
      @command.download_json
      @command.json.should.not.be.nil?
      @command.json.should.be.kind_of? Hash
      @command.json['plugins'].size.should.eql? 3
    end

    it 'handles empty/bad JSON' do
      stub_request(:get, Command::Plugins::PLUGINS_URL).to_return(:status => 200, :body => 'This is not JSON', :headers => {})
      @command.run
      UI.output.should.include('Could not download plugins list from cocoapods.org')
      @command.json.should.be.nil?
    end

    it 'notifies the user if the download fails' do
      stub_request(:get, Command::Plugins::PLUGINS_URL).to_return(:status => [404, 'Not Found'])
      @command.run
      UI.output.should.include('Could not download plugins list from cocoapods.org')
      @command.json.should.be.nil?
    end

    it 'prints out each plugin' do
      json_fixture = fixture('plugins.json')
      @json = JSON.parse(File.read(json_fixture))
      @command.json = @json
      @command.run
      UI.output.should.include('github.com/CocoaPods/cocoapods-fake')
      UI.output.should.include('github.com/chneukirchen/bacon')
    end

    it 'detects if a gem is installed' do
      @command.installed?('bacon').should.be.true
      @command.installed?('fake-fake-fake-gem').should.be.false
    end

  end

  describe Command::Plugins::Search do
    extend SpecHelper::PluginSearchCommand

    before do
      UI.output = ''
    end

    it 'registers itself' do
      Command.parse(%w(plugins search)).should.be.instance_of Command::Plugins::Search
    end

    it 'should require a query is passed in' do
      @command = search_command(argv)
      # rubocop:disable Lambda
      lambda { @command.validate! }
           .should.raise(CLAide::Help)
            .message.should.match(/A search query is required./)
      # rubocop:enable Lambda
    end

    it 'should require a non-empty query is passed in' do
      @command = search_command(argv(''))
      # rubocop:disable Lambda
      lambda { @command.validate! }
            .should.raise(CLAide::Help)
            .message.should.match(/A search query is required./)
      # rubocop:enable Lambda
    end

    it 'should require a valid regex' do
      @command = search_command(argv('[invalid'))
      # rubocop:disable Lambda
      lambda { @command.validate! }
           .should.raise(CLAide::Help)
            .message.should.match(/A valid regular expression is required./)
      # rubocop:enable Lambda
    end

    it 'should filter plugins by name when no full search' do
      json = File.read(fixture('plugins.json'))
      stub_request(:get, Command::Plugins::PLUGINS_URL).to_return(:status => 200, :body => json, :headers => {})
      @command = search_command(argv('search'))
      @command.run
      UI.output.should.not.include('-> CocoaPods Fake Gem')
      UI.output.should.include('-> CocoaPods Searchable Fake Gem')
      UI.output.should.not.include('-> Bacon')
    end

    it 'should filter plugins by name and description when full search' do
      json = File.read(fixture('plugins.json'))
      stub_request(:get, Command::Plugins::PLUGINS_URL).to_return(:status => 200, :body => json, :headers => {})
      @command = search_command(argv('--full', 'search'))
      @command.run
      UI.output.should.include('-> CocoaPods Fake Gem')
      UI.output.should.include('-> CocoaPods Searchable Fake Gem')
      UI.output.should.not.include('-> Bacon')
    end
  end

  describe Command::Plugins::Create do
    extend SpecHelper::PluginCreateCommand

    before do
      UI.output = ''
    end

    it 'registers itself' do
      Command.parse(%w(plugins create)).should.be.instance_of Command::Plugins::Create
    end

    it 'should require a name is passed in' do
      @command = create_command(argv)
      # rubocop:disable Lambda
      lambda { @command.validate! }
            .should.raise(CLAide::Help)
            .message.should.match(/A name for the plugin is required./)
      # rubocop:enable Lambda
    end

    it 'should require a non-empty name is passed in' do
      @command = create_command(argv(''))
      # rubocop:disable Lambda
      lambda { @command.validate! }
            .should.raise(CLAide::Help)
            .message.should.match(/A name for the plugin is required./)
      # rubocop:enable Lambda
    end

{'fraction_non_alphanumeric': 0.12589340412497446, 'fraction_numerical': 0.0032673065141923625, 'mean_word_length': 2.826171875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3282029', 'n_tokens_mistral': 3062, 'n_tokens_neox': 2970, 'n_words': 726}