Skip to content

Commit b6bc862

Browse files
author
Brent Cook
committed
Land rapid7#6267, fix Rex::Parser::Ini#each_group
2 parents cd56470 + f37adf9 commit b6bc862

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

lib/rex/parser/ini.rb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,7 @@ def initialize(path = nil)
4949
end
5050
end
5151

52-
#
53-
# Enumerates the groups hash keys.
54-
#
55-
def each_group(&block)
56-
self.keys.each { |k|
57-
yield
58-
}
59-
end
52+
alias each_group each_key
6053

6154
#
6255
# Adds a group of the supplied name if it doesn't already exist.

spec/lib/rex/parser/ini_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'rex/parser/ini'
2+
3+
describe Rex::Parser::Ini do
4+
let(:ini_contents) { <<EOF
5+
# global comment
6+
global settting = blah
7+
[foo]
8+
a = b
9+
[bar]
10+
b = c
11+
12+
[baf]
13+
c = d
14+
EOF
15+
}
16+
17+
let(:ini) { described_class.from_s(ini_contents) }
18+
19+
context "#each_group" do
20+
it "enumerates the groups" do
21+
groups = []
22+
ini.each_group { |group| groups << group }
23+
groups.should eq(%w(foo bar baf))
24+
end
25+
end
26+
27+
context "#each_key" do
28+
it "enumerates the groups" do
29+
groups = []
30+
ini.each_key.map { |group| groups << group }
31+
groups.should eq(%w(foo bar baf))
32+
end
33+
end
34+
end

0 commit comments

Comments
 (0)