<commit_before>require 'spec_helper'

module RubyEventStore
  RSpec.describe Client do
    let(:stream_name) { 'stream_name' }

    before do
      allow(Time).to receive(:now).and_return(Time.now)
    end

    specify 'raise exception if stream name is incorrect' do
      client = RubyEventStore::Client.new(repository: InMemoryRepository.new)
      expect { client.read_stream_events_forward(nil) }.to raise_error(IncorrectStreamData)
      expect { client.read_stream_events_forward('') }.to raise_error(IncorrectStreamData)
      expect { client.read_stream_events_backward(nil) }.to raise_error(IncorrectStreamData)
      expect { client.read_stream_events_backward('') }.to raise_error(IncorrectStreamData)
    end

    specify 'return all events ordered forward' do
      client = RubyEventStore::Client.new(repository: InMemoryRepository.new)
      prepare_events_in_store(client)
      events = client.read_stream_events_forward(stream_name)
      expect(events[0]).to eq(OrderCreated.new(event_id: '0'))
      expect(events[1]).to eq(OrderCreated.new(event_id: '1'))
      expect(events[2]).to eq(OrderCreated.new(event_id: '2'))
      expect(events[3]).to eq(OrderCreated.new(event_id: '3'))
    end

    specify 'return all events ordered backward' do
      client = RubyEventStore::Client.new(repository: InMemoryRepository.new)
      prepare_events_in_store(client)
      events = client.read_stream_events_backward(stream_name)
      expect(events[0]).to eq(OrderCreated.new(event_id: '3'))
      expect(events[1]).to eq(OrderCreated.new(event_id: '2'))
      expect(events[2]).to eq(OrderCreated.new(event_id: '1'))
      expect(events[3]).to eq(OrderCreated.new(event_id: '0'))
    end

    private

    def prepare_events_in_store(client)
      4.times do |index|
        event = OrderCreated.new(event_id: index)
        client.publish_event(event, stream_name: stream_name)
      end
    end
  end
end<commit_msg>Inline let var and remove unneccessary before block<commit_after>require 'spec_helper'

module RubyEventStore
  RSpec.describe Client do

    specify 'raise exception if stream name is incorrect' do
      client = RubyEventStore::Client.new(repository: InMemoryRepository.new)
      expect { client.read_stream_events_forward(nil) }.to raise_error(IncorrectStreamData)
      expect { client.read_stream_events_forward('') }.to raise_error(IncorrectStreamData)
      expect { client.read_stream_events_backward(nil) }.to raise_error(IncorrectStreamData)
      expect { client.read_stream_events_backward('') }.to raise_error(IncorrectStreamData)
    end

    specify 'return all events ordered forward' do
      client = RubyEventStore::Client.new(repository: InMemoryRepository.new)
      prepare_events_in_store(client)
      events = client.read_stream_events_forward('stream_name')
      expect(events[0]).to eq(OrderCreated.new(event_id: '0'))
      expect(events[1]).to eq(OrderCreated.new(event_id: '1'))
      expect(events[2]).to eq(OrderCreated.new(event_id: '2'))
      expect(events[3]).to eq(OrderCreated.new(event_id: '3'))
    end

    specify 'return all events ordered backward' do
      client = RubyEventStore::Client.new(repository: InMemoryRepository.new)
      prepare_events_in_store(client)
      events = client.read_stream_events_backward('stream_name')
      expect(events[0]).to eq(OrderCreated.new(event_id: '3'))
      expect(events[1]).to eq(OrderCreated.new(event_id: '2'))
      expect(events[2]).to eq(OrderCreated.new(event_id: '1'))
      expect(events[3]).to eq(OrderCreated.new(event_id: '0'))
    end

    private

    def prepare_events_in_store(client)
      4.times do |index|
        event = OrderCreated.new(event_id: index)
        client.publish_event(event, stream_name: 'stream_name')
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11310308462958081, 'fraction_numerical': 0.00896388083311363, 'mean_word_length': 4.321178120617111, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1687881', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1175, 'n_words': 221}