require 'spec_helper' shared_examples_for "Protocol1#read_instruction examples" do context "when the opcode is 41" do let(:io) { StringIO.new(41.chr) } it "must return Python::Pickle::Instructions::EMPTY_TUPLE" do expect(subject.read_instruction).to be( Python::Pickle::Instructions::EMPTY_TUPLE ) end end context "when the opcode is 71" do let(:float) { 1234.5678 } let(:packed) { [float].pack('G') } let(:io) { StringIO.new("#{71.chr}#{packed}\n") } it "must return a Python::Pickle::Instructions::BinFloat object" do expect(subject.read_instruction).to eq( Python::Pickle::Instructions::BinFloat.new(float) ) end end context "when the opcode is 75" do let(:int) { 0xff } let(:io) { StringIO.new("#{75.chr}#{int.chr}") } it "must return a Python::Pickle::Instructions::BinInt1 object" do expect(subject.read_instruction).to eq( Python::Pickle::Instructions::BinInt1.new(int) ) end end context "when the opcode is 84" do let(:string) { "hello\0world".b } let(:length) { string.bytesize } let(:packed) { [length, string].pack('L