Skip to content

Commit 42bfe8b

Browse files
David MaloneyDavid Maloney
authored andcommitted
make portspec specs not insane
the specs for the portspec_to_portlist method need a lot of work. this gives us some btter minimum coverage
1 parent 97d08a0 commit 42bfe8b

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

spec/lib/rex/socket_spec.rb

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding:binary -*-
22
require 'rex/socket/range_walker'
3+
require 'spec_helper'
34

45
describe Rex::Socket do
56

@@ -166,30 +167,30 @@
166167

167168
describe '.portspec_to_portlist' do
168169

169-
portspec = '-1,0-10,!2-5,!7,65530-,65536'
170-
context "'#{portspec}'" do
170+
subject(:portlist) { described_class.portspec_to_portlist portspec_string}
171+
let(:portspec_string) { '-1,0-10,!2-5,!7,65530-,65536' }
171172

172-
subject { described_class.portspec_to_portlist portspec }
173+
it 'does not include negative numbers' do
174+
expect(portlist).to_not include '-1'
175+
end
173176

174-
it { should be_a(Array) }
177+
it 'does not include 0' do
178+
expect(portlist).to_not include '0'
179+
end
175180

176-
not_included = []
177-
not_included << -1
178-
not_included << 65536
179-
not_included.concat (2..5).to_a
180-
not_included << 7
181-
not_included.each do |item|
182-
it { should_not include item }
181+
it 'does not include negated numbers' do
182+
['2', '3', '4', '5', '7'].each do |port|
183+
expect(portlist).to_not include port
183184
end
185+
end
186+
187+
it 'does not include any numbers above 65535' do
188+
expect(portlist).to_not include '65536'
189+
end
184190

185-
included = []
186-
included << -1
187-
included.concat (0..10).to_a
188-
included.concat (65530..65535).to_a
189-
included << 65536
190-
included = included - not_included
191-
included.each do |item|
192-
it { should include item }
191+
it 'expands open ended ranges' do
192+
(65530..65535).each do |port|
193+
expect(portlist).to include port
193194
end
194195
end
195196
end

0 commit comments

Comments
 (0)