spec/port_spec.rb in ronin-1.5.0 vs spec/port_spec.rb in ronin-1.5.1
- old
+ new
@@ -1,43 +1,51 @@
require 'spec_helper'
+
require 'ronin/port'
describe Port do
let(:protocol) { 'tcp' }
- let(:number) { 80 }
+ let(:number) { 80 }
- before(:all) do
- @port = Port.create(:protocol => protocol, :number => number)
+ subject do
+ described_class.new(:protocol => protocol, :number => number)
end
- it "should require a protocol" do
- port = Port.new(:number => 1111)
+ before { subject.save }
- port.should_not be_valid
- end
+ describe "validations" do
+ it "should require a protocol" do
+ port = described_class.new(:number => port)
- it "should require a port number" do
- port = Port.new(:protocol => 'tcp')
+ expect(port).not_to be_valid
+ end
- port.should_not be_valid
- end
+ it "should require a port number" do
+ port = described_class.new(:protocol => protocol)
- it "should only allow 'tcp' and 'udp' as protocols" do
- port = Port.new(:protocol => 'foo', :number => 1111)
+ expect(port).not_to be_valid
+ end
- port.should_not be_valid
- end
+ it "should only allow 'tcp' and 'udp' as protocols" do
+ port = described_class.new(:protocol => 'foo', :number => port)
- it "should require unique protocol/port-number combinations" do
- port = Port.new(:protocol => protocol, :number => number)
+ expect(port).not_to be_valid
+ end
- port.should_not be_valid
+ it "should require unique protocol/port-number combinations" do
+ port = described_class.new(:protocol => protocol, :number => number)
+ expect(port).not_to be_valid
+ end
end
- it "should be convertable to an Integer" do
- @port.to_i.should == number
+ describe "#to_i" do
+ it "should be convertable to an Integer" do
+ expect(subject.to_i).to eq(number)
+ end
end
- it "should be convertable to a String" do
- @port.to_s.should == "#{number}/#{protocol}"
+ describe "#to_s" do
+ it "should include the number and protocol" do
+ expect(subject.to_s).to eq("#{number}/#{protocol}")
+ end
end
end