<commit_before>require 'spec_helper'

module ZK::ZKEventMachine
  describe 'Client' do
    include EventedSpec::SpecHelper
    default_timeout 2.0

    before do
      @zk = ::ZK.new
      @base_path = '/zk-em-testing'
      @zk.rm_rf(@base_path)
      @zk.mkdir_p(@base_path)
      @zkem = ZK::ZKEventMachine::Client.new('localhost:2181')
    end

    after do
      @zk.rm_rf(@base_path)
      @zk.close!
    end

    describe 'connect' do
      it %[should return a deferred that fires when connected and then close] do
        em do
          @zkem.connect do
            true.should be_true
            @zkem.close! { done }
          end
        end
      end
    end

    describe 'get' do
      describe 'success' do
        before do
          @path = [@base_path, 'foo'].join('/')
          @data = 'this is data'
          @zk.create(@path, @data)
        end

        it 'should get the data and call the callback' do
          em do
            @zkem.connect do
              dfr = @zkem.get(@path)

              dfr.callback do |*a| <commit_msg>spec to make sure connect can be called multiple times<commit_after>require 'spec_helper'

module ZK::ZKEventMachine
  describe 'Client' do
    include EventedSpec::SpecHelper
    default_timeout 2.0

    before do
      @zk = ::ZK.new
      @base_path = '/zk-em-testing'
      @zk.rm_rf(@base_path)
      @zk.mkdir_p(@base_path)
      @zkem = ZK::ZKEventMachine::Client.new('localhost:2181')
    end

    after do
      @zk.rm_rf(@base_path)
      @zk.close!
    end

    describe 'connect' do
      it %[should return a deferred that fires when connected and then close] do
        em do
          @zkem.connect do
            true.should be_true
            @zkem.close! { done }
          end
        end
      end

      it %[should be able to be called mulitple times] do
        em do
          @zkem.connect do
            logger.debug { "inside first callback" }
            @zkem.connect do
              logger.debug { "inside second callback" }
              true.should be_true
              @zkem.close! { done }
            end
          end
        end
      end
    end

    describe 'get' do
      describe 'success' do
        before do
          @path = [@base_path, 'foo'].join('/')
          @data = 'this is data'
          @zk.create(@path, @data)
        end

        it 'should get the data and call the callback' do
          em do
            @zkem.connect do
              dfr = @zkem.get(@path)

              dfr.callback do |*a| 
{'fraction_non_alphanumeric': 0.096390321301071, 'fraction_numerical': 0.004760015866719556, 'mean_word_length': 1.6353187042842214, 'pattern_counts': {'":': 0, '<': 3, '<?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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7138126', 'n_tokens_mistral': 794, 'n_tokens_neox': 766, 'n_words': 225}