logstash-core 1.5.0.rc3.snapshot6-java → 1.5.0.rc4-java

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of logstash-core might be problematic. Click here for more details.

Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/lib/logstash-core.rb +2 -0
  3. data/lib/logstash/agent.rb +0 -33
  4. data/lib/logstash/config/config_ast.rb +1 -1
  5. data/lib/logstash/environment.rb +8 -30
  6. data/lib/logstash/filters/base.rb +19 -0
  7. data/lib/logstash/namespace.rb +0 -1
  8. data/lib/logstash/runner.rb +3 -51
  9. data/lib/logstash/version.rb +1 -1
  10. data/logstash-core.gemspec +54 -0
  11. data/spec/core/conditionals_spec.rb +428 -0
  12. data/spec/core/config_mixin_spec.rb +99 -0
  13. data/spec/core/config_spec.rb +108 -0
  14. data/spec/core/environment_spec.rb +44 -0
  15. data/spec/core/event_spec.rb +468 -0
  16. data/spec/core/pipeline_spec.rb +198 -0
  17. data/spec/core/plugin_spec.rb +106 -0
  18. data/spec/core/runner_spec.rb +39 -0
  19. data/spec/core/timestamp_spec.rb +83 -0
  20. data/spec/filters/base_spec.rb +318 -0
  21. data/spec/inputs/base_spec.rb +13 -0
  22. data/spec/lib/logstash/bundler_spec.rb +120 -0
  23. data/spec/lib/logstash/java_integration_spec.rb +257 -0
  24. data/spec/logstash/agent_spec.rb +37 -0
  25. data/spec/outputs/base_spec.rb +47 -0
  26. data/spec/spec_helper.rb +1 -0
  27. data/spec/util/accessors_spec.rb +215 -0
  28. data/spec/util/charset_spec.rb +74 -0
  29. data/spec/util/fieldeval_spec.rb +96 -0
  30. data/spec/util/gemfile_spec.rb +212 -0
  31. data/spec/util/json_spec.rb +97 -0
  32. data/spec/util/plugin_version_spec.rb +48 -0
  33. data/spec/util_spec.rb +34 -0
  34. metadata +84 -160
  35. data/lib/logstash-event.rb +0 -2
  36. data/lib/logstash.rb +0 -4
  37. data/lib/logstash/bundler.rb +0 -156
  38. data/lib/logstash/gemfile.rb +0 -193
  39. data/lib/logstash/pluginmanager.rb +0 -17
  40. data/lib/logstash/pluginmanager/command.rb +0 -38
  41. data/lib/logstash/pluginmanager/install.rb +0 -141
  42. data/lib/logstash/pluginmanager/list.rb +0 -44
  43. data/lib/logstash/pluginmanager/main.rb +0 -21
  44. data/lib/logstash/pluginmanager/uninstall.rb +0 -43
  45. data/lib/logstash/pluginmanager/update.rb +0 -105
  46. data/lib/logstash/pluginmanager/util.rb +0 -89
@@ -0,0 +1 @@
1
+ require "logstash/devutils/rspec/spec_helper"
@@ -0,0 +1,215 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+ require "logstash/util/accessors"
4
+
5
+ describe LogStash::Util::Accessors, :if => true do
6
+
7
+ context "using simple field" do
8
+
9
+ it "should get value of word key" do
10
+ str = "hello"
11
+ data = { "hello" => "world" }
12
+ accessors = LogStash::Util::Accessors.new(data)
13
+ expect(accessors.get(str)).to eq(data[str])
14
+ end
15
+
16
+ it "should get value of key with spaces" do
17
+ str = "hel lo"
18
+ data = { "hel lo" => "world" }
19
+ accessors = LogStash::Util::Accessors.new(data)
20
+ expect(accessors.get(str)).to eq(data[str])
21
+ end
22
+
23
+ it "should get value of numeric key string" do
24
+ str = "1"
25
+ data = { "1" => "world" }
26
+ accessors = LogStash::Util::Accessors.new(data)
27
+ expect(accessors.get(str)).to eq(data[str])
28
+ end
29
+
30
+ it "should handle delete" do
31
+ str = "simple"
32
+ data = { "simple" => "things" }
33
+ accessors = LogStash::Util::Accessors.new(data)
34
+ expect(accessors.del(str)).to eq("things")
35
+ expect(data).to be_empty
36
+ end
37
+
38
+ it "should handle delete on non-existent field" do
39
+ str = "[foo][bar]"
40
+ data = { "hello" => "world" }
41
+ accessors = LogStash::Util::Accessors.new(data)
42
+ expect(accessors.del(str)).to be_nil
43
+ expect(data).not_to be_empty
44
+ # assert no side effects
45
+ expect(accessors.get("foo")).to be_nil
46
+ expect(accessors.get("hello")).to eq("world")
47
+ end
48
+
49
+ it "should set string value" do
50
+ str = "simple"
51
+ data = {}
52
+ accessors = LogStash::Util::Accessors.new(data)
53
+ expect(accessors.set(str, "things")).to eq("things")
54
+ expect(data).to eq({ "simple" => "things" })
55
+ end
56
+
57
+ it "should set array value" do
58
+ str = "simple"
59
+ data = {}
60
+ accessors = LogStash::Util::Accessors.new(data)
61
+ expect(accessors.set(str, ["foo", "bar"])).to eq(["foo", "bar"])
62
+ expect(data).to eq({ "simple" => ["foo", "bar"]})
63
+ end
64
+ end
65
+
66
+ context "using field path" do
67
+
68
+ it "should get shallow string value of word key" do
69
+ str = "[hello]"
70
+ data = { "hello" => "world" }
71
+ accessors = LogStash::Util::Accessors.new(data)
72
+ expect(accessors.get(str)).to eq("world")
73
+ end
74
+
75
+ it "should get shallow string value of key with spaces" do
76
+ str = "[hel lo]"
77
+ data = { "hel lo" => "world" }
78
+ accessors = LogStash::Util::Accessors.new(data)
79
+ expect(accessors.get(str)).to eq("world")
80
+ end
81
+
82
+ it "should get shallow string value of numeric key string" do
83
+ str = "[1]"
84
+ data = { "1" => "world" }
85
+ accessors = LogStash::Util::Accessors.new(data)
86
+ expect(accessors.get(str)).to eq("world")
87
+ end
88
+
89
+ it "should get deep string value" do
90
+ str = "[hello][world]"
91
+ data = { "hello" => { "world" => "foo", "bar" => "baz" } }
92
+ accessors = LogStash::Util::Accessors.new(data)
93
+ expect(accessors.get(str)).to eq(data["hello"]["world"])
94
+ end
95
+
96
+ it "should return nil when getting a non-existant field (with no side-effects on original data)" do
97
+ str = "[hello][world]"
98
+ data = {}
99
+ accessors = LogStash::Util::Accessors.new(data)
100
+ expect(accessors.get(str)).to be_nil
101
+ expect(data).to be_empty
102
+ expect(accessors.set(str, "foo")).to eq("foo")
103
+ expect(data).to eq({ "hello" => {"world" => "foo"} })
104
+ end
105
+
106
+ it "should handle delete" do
107
+ str = "[hello][world]"
108
+ data = { "hello" => { "world" => "foo", "bar" => "baz" } }
109
+ accessors = LogStash::Util::Accessors.new(data)
110
+ expect(accessors.del(str)).to eq("foo")
111
+
112
+ # Make sure the "world" key is removed.
113
+ expect(data["hello"]).to eq({ "bar" => "baz" })
114
+ end
115
+
116
+ it "should set shallow string value" do
117
+ str = "[hello]"
118
+ data = {}
119
+ accessors = LogStash::Util::Accessors.new(data)
120
+ expect(accessors.set(str, "foo")).to eq("foo")
121
+ expect(data).to eq({ "hello" => "foo" })
122
+ end
123
+
124
+ it "should strict_set shallow string value" do
125
+ str = "[hello]"
126
+ data = {}
127
+ accessors = LogStash::Util::Accessors.new(data)
128
+ expect(accessors.strict_set(str, "foo")).to eq("foo")
129
+ expect(data).to eq({ "hello" => "foo"})
130
+ end
131
+
132
+ it "should set deep string value" do
133
+ str = "[hello][world]"
134
+ data = {}
135
+ accessors = LogStash::Util::Accessors.new(data)
136
+ expect(accessors.set(str, "foo")).to eq("foo")
137
+ expect(data).to eq({ "hello" => { "world" => "foo" } })
138
+ end
139
+
140
+ it "should set deep array value" do
141
+ str = "[hello][world]"
142
+ data = {}
143
+ accessors = LogStash::Util::Accessors.new(data)
144
+ expect(accessors.set(str, ["foo", "bar"])).to eq(["foo", "bar"])
145
+ expect(data).to eq({ "hello" => { "world" => ["foo", "bar"] } })
146
+ end
147
+
148
+ it "should strict_set deep array value" do
149
+ str = "[hello][world]"
150
+ data = {}
151
+ accessors = LogStash::Util::Accessors.new(data)
152
+ expect(accessors.strict_set(str, ["foo", "bar"]) ).to eq(["foo", "bar"])
153
+ expect(data).to eq({ "hello" => { "world" => ["foo", "bar"] } })
154
+ end
155
+
156
+ it "should set element within array value" do
157
+ str = "[hello][0]"
158
+ data = {"hello" => ["foo", "bar"]}
159
+ accessors = LogStash::Util::Accessors.new(data)
160
+ expect(accessors.set(str, "world") ).to eq("world")
161
+ expect(data).to eq({"hello" => ["world", "bar"]})
162
+ end
163
+
164
+ it "should retrieve array item" do
165
+ data = { "hello" => { "world" => ["a", "b"], "bar" => "baz" } }
166
+ accessors = LogStash::Util::Accessors.new(data)
167
+ expect(accessors.get("[hello][world][0]")).to eq(data["hello"]["world"][0])
168
+ expect(accessors.get("[hello][world][1]")).to eq(data["hello"]["world"][1])
169
+ end
170
+
171
+ it "should retrieve array item containing hash" do
172
+ data = { "hello" => { "world" => [ { "a" => 123 }, { "b" => 345 } ], "bar" => "baz" } }
173
+ accessors = LogStash::Util::Accessors.new(data)
174
+ expect(accessors.get("[hello][world][0][a]")).to eq(data["hello"]["world"][0]["a"])
175
+ expect(accessors.get("[hello][world][1][b]")).to eq(data["hello"]["world"][1]["b"])
176
+ end
177
+
178
+ it "should handle delete of array element" do
179
+ str = "[geocoords][0]"
180
+ data = { "geocoords" => [4, 2] }
181
+ accessors = LogStash::Util::Accessors.new(data)
182
+ expect(accessors.del(str)).to eq(4)
183
+ expect(data).to eq({ "geocoords" => [2] })
184
+ end end
185
+
186
+ context "using invalid encoding" do
187
+ it "strinct_set should raise on non UTF-8 string encoding" do
188
+ str = "[hello]"
189
+ data = {}
190
+ accessors = LogStash::Util::Accessors.new(data)
191
+ expect { accessors.strict_set(str, "foo".encode("US-ASCII")) }.to raise_error
192
+ end
193
+
194
+ it "strinct_set should raise on non UTF-8 string encoding in array" do
195
+ str = "[hello]"
196
+ data = {}
197
+ accessors = LogStash::Util::Accessors.new(data)
198
+ expect { accessors.strict_set(str, ["foo", "bar".encode("US-ASCII")]) }.to raise_error
199
+ end
200
+
201
+ it "strinct_set should raise on invalid UTF-8 string encoding" do
202
+ str = "[hello]"
203
+ data = {}
204
+ accessors = LogStash::Util::Accessors.new(data)
205
+ expect { accessors.strict_set(str, "foo \xED\xB9\x81\xC3") }.to raise_error
206
+ end
207
+
208
+ it "strinct_set should raise on invalid UTF-8 string encoding in array" do
209
+ str = "[hello]"
210
+ data = {}
211
+ accessors = LogStash::Util::Accessors.new(data)
212
+ expect { accessors.strict_set(str, ["foo", "bar \xED\xB9\x81\xC3"]) }.to raise_error
213
+ end
214
+ end
215
+ end
@@ -0,0 +1,74 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+ require "logstash/util/charset"
4
+
5
+ describe LogStash::Util::Charset do
6
+ let(:logger) { double("logger") }
7
+
8
+ context "with valid UTF-8 source encoding" do
9
+ subject {LogStash::Util::Charset.new("UTF-8")}
10
+
11
+ it "should return untouched data" do
12
+ ["foobar", "κόσμε"].each do |data|
13
+ expect(data.encoding.name).to eq("UTF-8")
14
+ expect(subject.convert(data)).to eq(data)
15
+ expect(subject.convert(data).encoding.name).to eq("UTF-8")
16
+ end
17
+ end
18
+ end
19
+
20
+ context "with invalid UTF-8 source encoding" do
21
+ subject do
22
+ LogStash::Util::Charset.new("UTF-8").tap do |charset|
23
+ charset.logger = logger
24
+ end
25
+ end
26
+
27
+ it "should escape invalid sequences" do
28
+ ["foo \xED\xB9\x81\xC3", "bar \xAD"].each do |data|
29
+ expect(data.encoding.name).to eq("UTF-8")
30
+ expect(data.valid_encoding?).to eq(false)
31
+ expect(logger).to receive(:warn).exactly(2).times
32
+ #logger.should_receive(:warn).twice
33
+ expect(subject.convert(data)).to eq(data.inspect[1..-2])
34
+ expect(subject.convert(data).encoding.name).to eq("UTF-8")
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+ context "with valid non UTF-8 source encoding" do
41
+ subject {LogStash::Util::Charset.new("ISO-8859-1")}
42
+
43
+ it "should encode to UTF-8" do
44
+ samples = [
45
+ ["foobar", "foobar"],
46
+ ["\xE0 Montr\xE9al", "à Montréal"],
47
+ ]
48
+ samples.map{|(a, b)| [a.force_encoding("ISO-8859-1"), b]}.each do |(a, b)|
49
+ expect(a.encoding.name).to eq("ISO-8859-1")
50
+ expect(b.encoding.name).to eq("UTF-8")
51
+ expect(a.valid_encoding?).to eq(true)
52
+ expect(subject.convert(a).encoding.name).to eq("UTF-8")
53
+ expect(subject.convert(a)).to eq(b)
54
+ end
55
+ end
56
+ end
57
+
58
+ context "with invalid non UTF-8 source encoding" do
59
+ subject {LogStash::Util::Charset.new("ASCII-8BIT")}
60
+
61
+ it "should encode to UTF-8 and replace invalid chars" do
62
+ samples = [
63
+ ["\xE0 Montr\xE9al", "� Montr�al"],
64
+ ["\xCE\xBA\xCF\x8C\xCF\x83\xCE\xBC\xCE\xB5", "����������"],
65
+ ]
66
+ samples.map{|(a, b)| [a.force_encoding("ASCII-8BIT"), b]}.each do |(a, b)|
67
+ expect(a.encoding.name).to eq("ASCII-8BIT")
68
+ expect(b.encoding.name).to eq("UTF-8")
69
+ expect(subject.convert(a).encoding.name).to eq("UTF-8")
70
+ expect(subject.convert(a)).to eq(b)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,96 @@
1
+ require "spec_helper"
2
+ require "logstash/util/fieldreference"
3
+
4
+ describe LogStash::Util::FieldReference, :if => true do
5
+
6
+ context "using simple accessor" do
7
+
8
+ it "should retrieve value" do
9
+ str = "hello"
10
+ m = eval(subject.compile(str))
11
+ data = { "hello" => "world" }
12
+ expect(m.call(data)).to eq(data[str])
13
+ end
14
+
15
+ it "should handle delete in block" do
16
+ str = "simple"
17
+ m = eval(subject.compile(str))
18
+ data = { "simple" => "things" }
19
+ m.call(data) { |obj, key| obj.delete(key) }
20
+ expect(data).to be_empty
21
+ end
22
+
23
+ it "should handle assignment in block" do
24
+ str = "simple"
25
+ m = eval(subject.compile(str))
26
+ data = {}
27
+ expect(m.call(data) { |obj, key| obj[key] = "things" }).to eq("things")
28
+ expect(data).to eq({ "simple" => "things" })
29
+ end
30
+
31
+ it "should handle assignment using set" do
32
+ str = "simple"
33
+ data = {}
34
+ expect(subject.set(str, "things", data)).to eq("things")
35
+ expect(data).to eq({ "simple" => "things" })
36
+ end
37
+ end
38
+
39
+ context "using accessor path" do
40
+
41
+ it "should retrieve shallow value" do
42
+ str = "[hello]"
43
+ m = eval(subject.compile(str))
44
+ data = { "hello" => "world" }
45
+ expect(m.call(data)).to eq("world")
46
+ end
47
+
48
+ it "should retrieve deep value" do
49
+ str = "[hello][world]"
50
+ m = eval(subject.compile(str))
51
+ data = { "hello" => { "world" => "foo", "bar" => "baz" } }
52
+ expect(m.call(data)).to eq(data["hello"]["world"])
53
+ end
54
+
55
+ it "should handle delete in block" do
56
+ str = "[hello][world]"
57
+ m = eval(subject.compile(str))
58
+ data = { "hello" => { "world" => "foo", "bar" => "baz" } }
59
+ m.call(data) { |obj, key| obj.delete(key) }
60
+
61
+ # Make sure the "world" key is removed.
62
+ expect(data["hello"]).to eq({ "bar" => "baz" })
63
+ end
64
+
65
+ it "should not handle assignment in block" do
66
+ str = "[hello][world]"
67
+ m = eval(subject.compile(str))
68
+ data = {}
69
+ expect(m.call(data) { |obj, key| obj[key] = "things" }).to be_nil
70
+ expect(data).to be_empty
71
+ end
72
+
73
+ it "should set shallow value" do
74
+ str = "[hello]"
75
+ data = {}
76
+ expect(subject.set(str, "foo", data)).to eq("foo")
77
+ expect(data).to eq({ "hello" => "foo" })
78
+ end
79
+
80
+ it "should set deep value" do
81
+ str = "[hello][world]"
82
+ data = {}
83
+ expect(subject.set(str, "foo", data)).to eq("foo")
84
+ expect(data).to eq({ "hello" => { "world" => "foo" } })
85
+ end
86
+
87
+ it "should retrieve array item" do
88
+ data = { "hello" => { "world" => ["a", "b"], "bar" => "baz" } }
89
+ m = eval(subject.compile("[hello][world][0]"))
90
+ expect(m.call(data)).to eq(data["hello"]["world"][0])
91
+
92
+ m = eval(subject.compile("[hello][world][1]"))
93
+ expect(m.call(data)).to eq(data["hello"]["world"][1])
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,212 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+ require "pluginmanager/gemfile"
4
+
5
+ describe "logstash Gemfile Manager" do
6
+
7
+ context LogStash::Gemfile do
8
+
9
+ context "load" do
10
+
11
+ it "should load and return self" do
12
+ file = <<-END
13
+ source "https://rubygems.org"
14
+ gemspec :a => "a"
15
+ gem "test", "> 1.0", "< 2.0", :b => "b"
16
+ END
17
+
18
+ gemfile = LogStash::Gemfile.new(StringIO.new(file)).load
19
+ expect(gemfile).to be_an(LogStash::Gemfile)
20
+ end
21
+
22
+ it "should add sources" do
23
+ file = <<-END
24
+ source "a"
25
+ source "b"
26
+ END
27
+
28
+ gemfile = LogStash::Gemfile.new(StringIO.new(file)).load
29
+ expect(gemfile.gemset.sources.size).to eq(2)
30
+ expect(gemfile.gemset.sources).to eq(["a", "b"])
31
+ end
32
+
33
+ it "should add gemspec" do
34
+ file = <<-END
35
+ gemspec "foo"
36
+ END
37
+
38
+ gemfile = LogStash::Gemfile.new(StringIO.new(file)).load
39
+ expect(gemfile.gemset.gemspec).to eq("foo")
40
+ end
41
+
42
+ it "should raise on multiple gemspec" do
43
+ file = <<-END
44
+ gemspec "foo"
45
+ gemspec "boom"
46
+ END
47
+
48
+ expect{LogStash::Gemfile.new(StringIO.new(file)).load}.to raise_error(LogStash::GemfileError)
49
+ end
50
+
51
+ it "should add gems" do
52
+ file = <<-END
53
+ gem "foo"
54
+ gem "bar"
55
+ END
56
+
57
+ gemfile = LogStash::Gemfile.new(StringIO.new(file)).load
58
+ expect(gemfile.gemset.gems.size).to eq(2)
59
+ expect(gemfile.gemset.gems[0].name).to eq("foo")
60
+ expect(gemfile.gemset.gems[1].name).to eq("bar")
61
+ end
62
+
63
+ it "should raise on duplicate gem name" do
64
+ file = <<-END
65
+ gem "foo"
66
+ gem "foo"
67
+ END
68
+
69
+ expect{LogStash::Gemfile.new(StringIO.new(file)).load}.to raise_error(LogStash::GemfileError)
70
+ end
71
+
72
+ it "should add gems with only name" do
73
+ file = <<-END
74
+ gem "foo"
75
+ END
76
+
77
+ gemfile = LogStash::Gemfile.new(StringIO.new(file)).load
78
+
79
+ expect(gemfile.gemset.gems[0].name).to eq("foo")
80
+ expect(gemfile.gemset.gems[0].requirements.empty?).to eq(true)
81
+ expect(gemfile.gemset.gems[0].options.empty?).to eq(true)
82
+ end
83
+
84
+ it "should add gems with name and requirements" do
85
+ file = <<-END
86
+ gem "foo", "a"
87
+ gem "bar", "a", "b"
88
+ END
89
+
90
+ gemfile = LogStash::Gemfile.new(StringIO.new(file)).load
91
+
92
+ expect(gemfile.gemset.gems[0].name).to eq("foo")
93
+ expect(gemfile.gemset.gems[0].requirements).to eq(["a"])
94
+ expect(gemfile.gemset.gems[0].options.empty?).to eq(true)
95
+
96
+ expect(gemfile.gemset.gems[1].name).to eq("bar")
97
+ expect(gemfile.gemset.gems[1].requirements).to eq(["a", "b"])
98
+ expect(gemfile.gemset.gems[1].options.empty?).to eq(true)
99
+ end
100
+
101
+ it "should add gems with name and options" do
102
+ file = <<-END
103
+ gem "foo", :a => "a"
104
+ gem "bar", :a => "a", :b => "b"
105
+ END
106
+
107
+ gemfile = LogStash::Gemfile.new(StringIO.new(file)).load
108
+
109
+ expect(gemfile.gemset.gems[0].name).to eq("foo")
110
+ expect(gemfile.gemset.gems[0].requirements.empty?).to eq(true)
111
+ expect(gemfile.gemset.gems[0].options).to eq({:a => "a"})
112
+
113
+ expect(gemfile.gemset.gems[1].name).to eq("bar")
114
+ expect(gemfile.gemset.gems[1].requirements.empty?).to eq(true)
115
+ expect(gemfile.gemset.gems[1].options).to eq({:a => "a", :b => "b"})
116
+ end
117
+
118
+ it "should add gems with name, requirements and options" do
119
+ file = <<-END
120
+ gem "foo", "> 1.0", :b => "b"
121
+ gem "bar", "> 2.0", "< 3.0", :c => "c", :d => "d"
122
+ END
123
+
124
+ gemfile = LogStash::Gemfile.new(StringIO.new(file)).load
125
+ expect(gemfile.gemset.gems.size).to eq(2)
126
+
127
+ expect(gemfile.gemset.gems[0].name).to eq("foo")
128
+ expect(gemfile.gemset.gems[0].requirements).to eq(["> 1.0"])
129
+ expect(gemfile.gemset.gems[0].options).to eq({:b => "b"})
130
+
131
+ expect(gemfile.gemset.gems[1].name).to eq("bar")
132
+ expect(gemfile.gemset.gems[1].requirements).to eq(["> 2.0", "< 3.0"])
133
+ expect(gemfile.gemset.gems[1].options).to eq({:c => "c", :d => "d"})
134
+ end
135
+ end
136
+
137
+ describe "Locally installed gems" do
138
+ subject { LogStash::Gemfile.new(StringIO.new(file)).load.locally_installed_gems }
139
+
140
+ context "has gems defined with a path" do
141
+ let(:file) {
142
+ %Q[
143
+ source "https://rubygems.org"
144
+ gemspec :a => "a", "b" => 1
145
+ gem "foo", "> 1.0", :path => "/tmp/foo"
146
+ gem "bar", :path => "/tmp/bar"
147
+ gem "no-fun"
148
+ ]
149
+ }
150
+
151
+ it "returns the list of gems" do
152
+ expect(subject.collect(&:name)).to eq(["foo", "bar"])
153
+ end
154
+ end
155
+
156
+ context "no gems defined with a path" do
157
+ let(:file) {
158
+ %Q[
159
+ source "https://rubygems.org"
160
+ gemspec :a => "a", "b" => 1
161
+ gem "no-fun"
162
+ ]
163
+ }
164
+
165
+ it "return an empty list" do
166
+ expect(subject.size).to eq(0)
167
+ end
168
+ end
169
+
170
+ context "keep a backup of the original file" do
171
+
172
+ end
173
+ end
174
+
175
+ context "save" do
176
+ it "should save" do
177
+ file = <<-END
178
+ source "https://rubygems.org"
179
+ gemspec :a => "a", "b" => 1
180
+ gem "foo", "> 1.0", "< 2.0", :b => "b"
181
+ gem "bar"
182
+ END
183
+
184
+ io = StringIO.new(file)
185
+ gemfile = LogStash::Gemfile.new(io).load
186
+ gemfile.save
187
+ expect(file).to eq(
188
+ LogStash::Gemfile::HEADER + \
189
+ "source \"https://rubygems.org\"\n" + \
190
+ "gemspec :a => \"a\", \"b\" => 1\n" + \
191
+ "gem \"foo\", \"> 1.0\", \"< 2.0\", :b => \"b\"\n" + \
192
+ "gem \"bar\"\n"
193
+ )
194
+ end
195
+ end
196
+ end
197
+
198
+ context LogStash::DSL do
199
+ context "parse" do
200
+ it "should parse Gemfile content string" do
201
+ gemfile = <<-END
202
+ source "https://rubygems.org"
203
+ gemspec
204
+ gem "foo"
205
+ END
206
+
207
+ gemset = LogStash::DSL.parse(gemfile)
208
+ expect(gemset).to be_an(LogStash::Gemset)
209
+ end
210
+ end
211
+ end
212
+ end