require 'spec_helper'

require 'protobuf/code_generator'

describe 'protoc-gen-ruby' do
  let(:binpath) { ::File.expand_path('../../../bin/protoc-gen-ruby', __FILE__) }
  let(:request_bytes) { ::Google::Protobuf::Compiler::CodeGeneratorRequest.new(:file_to_generate => [ "test/foo.proto" ]) }
  let(:expected_file) { ::Google::Protobuf::Compiler::CodeGeneratorResponse::File.new(:name => 'test/foo.pb.rb') }
  let(:expected_response_bytes) { ::Google::Protobuf::Compiler::CodeGeneratorRequest.encode(:files => [ expected_file ]) }

  it 'reads the serialized request bytes and outputs serialized response bytes' do
    ::IO.popen(binpath, 'w+') do |pipe|
      pipe.write(request_bytes)
      expect(pipe.read(expected_response_bytes.size)).to eq expected_response_bytes
    end
  end
end


require 'spec_helper'

require 'protobuf/code_generator'

describe 'protoc-gen-ruby' do
  let(:binpath) { ::File.expand_path('../../../bin/protoc-gen-ruby', __FILE__) }
  let(:package) { 'test' }
  let(:request_bytes) do
    ::Google::Protobuf::Compiler::CodeGeneratorRequest.encode(
      :proto_file => [{ :package => package }],
    )
  end

  it 'reads the serialized request bytes and outputs serialized response bytes' do
    ::IO.popen(binpath, 'w+') do |pipe|
      pipe.write(request_bytes)
      pipe.close_write # needed so we can implicitly read until EOF
      response_bytes = pipe.read
      response = ::Google::Protobuf::Compiler::CodeGeneratorResponse.decode(response_bytes)
      expect(response.file.first.content).to include("module #{package.titleize}")
    end
  end
end

Fix flakey spec by closing write pipe, generating an empty test module
Fix flakey spec by closing write pipe, generating an empty test module

Signed-off-by: Tamir Duberstein <c96a05aaafbe4b3abc1841a4083a1b0f402c2ba6@squareup.com>
