spec/binary/struct_spec.rb in ronin-support-0.5.1 vs spec/binary/struct_spec.rb in ronin-support-0.5.2

- old
+ new

@@ -12,32 +12,32 @@ struct.new end it "should return the layout" do - subject.class.layout.should == [ + expect(subject.class.layout).to eq([ :x, :y - ] + ]) end context "when given fields" do it "should populate fields" do - subject.class.fields.should == { + expect(subject.class.fields).to eq({ :x => [:uint, nil], :y => [:uint, nil] - } + }) end it "should define reader methods" do - subject.should respond_to(:x) - subject.should respond_to(:y) + expect(subject).to respond_to(:x) + expect(subject).to respond_to(:y) end it "should define writer methods" do - subject.should respond_to(:x=) - subject.should respond_to(:y=) + expect(subject).to respond_to(:x=) + expect(subject).to respond_to(:y=) end end end describe "field?" do @@ -46,12 +46,12 @@ struct.class_eval { layout :x, :uint } struct end it "should determine if fields exist" do - subject.field?(:x).should == true - subject.field?(:foo).should == false + expect(subject.field?(:x)).to be(true) + expect(subject.field?(:foo)).to be(false) end end describe "endian" do subject do @@ -59,18 +59,18 @@ struct.class_eval { endian :little } struct end it "should return the endianness of the Struct" do - subject.endian.should == :little + expect(subject.endian).to eq(:little) end context "when given an argument" do it "should set the endianness" do subject.endian :big - subject.endian.should == :big + expect(subject.endian).to eq(:big) end end end describe "typedefs" do @@ -85,15 +85,15 @@ struct end it "should register a new type in typedefs" do - subject.typedefs.should have_key(:test_t) + expect(subject.typedefs).to have_key(:test_t) end it "should resolve the existing type" do - subject.typedefs[:test_t].should == :uint32 + expect(subject.typedefs[:test_t]).to eq(:uint32) end end describe "#initialize" do subject do @@ -117,44 +117,44 @@ struct.new end it "should set integers to 0" do - subject[:int].should == 0 + expect(subject[:int]).to eq(0) end it "should set arrays of integers to [0, ...]" do - subject[:int_array].should == [0, 0] + expect(subject[:int_array]).to eq([0, 0]) end it "should set floats to 0.0" do - subject[:float].should == 0.0 + expect(subject[:float]).to eq(0.0) end it "should set arrays of floats to [0.0, ...]" do - subject[:float_array].should == [0.0, 0.0] + expect(subject[:float_array]).to eq([0.0, 0.0]) end it "should set chars to '\\0'" do - subject[:char].should == "\0" + expect(subject[:char]).to eq("\0") end it "should set arrays of chars to ''" do - subject[:char_array].should == '' + expect(subject[:char_array]).to eq('') end it "should set strings to ''" do - subject[:string].should == '' + expect(subject[:string]).to eq('') end it "should initialize nested structs" do - subject[:struct][:int].should == 0 + expect(subject[:struct][:int]).to eq(0) end it "should initialize arrays of nested structs" do - subject[:struct_array][0][:int].should == 0 - subject[:struct_array][1][:int].should == 0 + expect(subject[:struct_array][0][:int]).to eq(0) + expect(subject[:struct_array][1][:int]).to eq(0) end end describe "#[]" do subject do @@ -165,28 +165,28 @@ end struct.new end - before(:all) do + before do subject.instance_variable_set('@x',10) end it "should access the instance variable" do - subject[:x].should == 10 + expect(subject[:x]).to eq(10) end it "should still call the underlying reader method" do - subject.should_receive(:x).and_return(10) + expect(subject).to receive(:x).and_return(10) subject[:x] end it "should raise ArgumentError for unknown fields" do - lambda { + expect { subject[:foo] - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end end describe "#[]=" do subject do @@ -197,30 +197,30 @@ end struct.new end - before(:each) do + before do subject.instance_variable_set('@x',0) end it "should set the underlying instance variable" do subject[:x] = 20 - subject.instance_variable_get('@x').should == 20 + expect(subject.instance_variable_get('@x')).to eq(20) end it "should still call the underlying writer method" do - subject.should_receive(:x=).with(20) + expect(subject).to receive(:x=).with(20) subject[:x] = 20 end it "should raise ArgumentError for unknown fields" do - lambda { + expect { subject[:foo] = 20 - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end end describe "#values" do let(:x) { 10 } @@ -234,17 +234,17 @@ end struct.new end - before(:each) do + before do subject.x = x subject.y = y end it "should return the values of the fields" do - subject.values.should == [x, y] + expect(subject.values).to eq([x, y]) end context "nested structs" do let(:z) { 30 } @@ -262,16 +262,16 @@ end struct.new end - before(:each) do + before do subject.z.int = z end it "should nest the values of nested structs" do - subject.values.should == [x, y, [z]] + expect(subject.values).to eq([x, y, [z]]) end end context "arrays of nested structs" do let(:z) { 30 } @@ -290,17 +290,17 @@ end struct.new end - before(:each) do + before do subject.z[0].int = z subject.z[1].int = z end it "should nest the values of nested structs" do - subject.values.should == [x, y, [[z], [z]]] + expect(subject.values).to eq([x, y, [[z], [z]]]) end end end describe "#clear" do @@ -318,25 +318,25 @@ end struct.new end - before(:all) do + before do subject.x = 100 subject.y = 15.0 subject.z.int = -1 subject.clear end it "should reset fields to their default values" do - subject.x.should == 0 - subject.y.should == 0.0 + expect(subject.x).to eq(0) + expect(subject.y).to eq(0.0) end it "should reinitialize nested structs" do - subject.z.int.should == 0 + expect(subject.z.int).to eq(0) end end describe "#pack" do context "arrays of chars" do @@ -350,16 +350,16 @@ end struct.new end - before(:each) do + before do subject.chars = string end it "should pack arrays of chars into a String" do - subject.pack.should == packed + expect(subject.pack).to eq(packed) end end context "structs" do let(:packed) { "\x0a\x00\x14\x00\x00\x00" } @@ -377,17 +377,17 @@ end struct.new end - before(:each) do + before do subject.int = 10 subject.struct.int = 20 end it "should pack the nested struct fields" do - subject.pack.should == packed + expect(subject.pack).to eq(packed) end end context "arrays of structs" do let(:packed) { "\x0a\x00\x14\x00\x00\x00\x1e\x00\x00\x00" } @@ -405,18 +405,18 @@ end struct.new end - before(:each) do + before do subject.int = 10 subject.struct[0].int = 20 subject.struct[1].int = 30 end it "should pack the nested fields" do - subject.pack.should == packed + expect(subject.pack).to eq(packed) end end end describe "#unpack" do @@ -434,11 +434,11 @@ end it "should unpack arrays of chars into a String" do subject.unpack(packed) - subject.chars.should == string + expect(subject.chars).to eq(string) end end context "structs" do let(:packed) { "\x0a\x00\x14\x00\x00\x00" } @@ -459,12 +459,12 @@ end it "should unpack the nested struct fields" do subject.unpack(packed) - subject.int.should == 10 - subject.struct.int.should == 20 + expect(subject.int).to eq(10) + expect(subject.struct.int).to eq(20) end end context "arrays of structs" do let(:packed) { "\x0a\x00\x14\x00\x00\x00\x1e\x00\x00\x00" } @@ -485,12 +485,12 @@ end it "should unpack the nested fields" do subject.unpack(packed) - subject.int.should == 10 - subject.struct[0].int.should == 20 - subject.struct[1].int.should == 30 + expect(subject.int).to eq(10) + expect(subject.struct[0].int).to eq(20) + expect(subject.struct[1].int).to eq(30) end end end end