Skip to content

Commit 183ef4b

Browse files
author
Frank Natividad
committed
Changes:
1. Expanded spec to create and delete a new log_name for entries created during tests. 2. Removed unnecessary comments.
1 parent 01cd1d8 commit 183ef4b

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

logging/spec/quickstart_spec.rb

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,42 @@ def wait_until times: 5, delay: 1, &condition
2626
raise "Condition not met. Waited #{times} times with #{delay} sec delay"
2727
end
2828

29-
it "logs a new entry" do
30-
entry_filter = 'logName:"my-log" textPayload:"Hello, world!"'
31-
gcloud = Google::Cloud.new ENV["GOOGLE_CLOUD_PROJECT"]
32-
logging = gcloud.logging
29+
before(:all) do
30+
@gcloud = Google::Cloud.new ENV["GOOGLE_CLOUD_PROJECT"]
31+
@logging = @gcloud.logging
32+
@entry = @logging.entry
3333

34-
expect(Google::Cloud).to receive(:new).with("YOUR_PROJECT_ID").
35-
and_return(gcloud)
34+
time_now = Time.now.to_f.to_s.split('.').first
35+
@log_name = "sub-name-#{time_now}"
36+
end
3637

37-
entries = logging.entries filter: entry_filter
38-
unless entries.empty?
39-
logging.delete_log "my-log"
38+
after(:all) do
39+
if @logging.entries(filter: "logName:\"#{@log_name}\"").any?
40+
@logging.delete_log @log_name
4041
end
42+
end
4143

42-
expect(logging.entries(filter: entry_filter)).to be_empty
44+
it "logs a new entry" do
45+
entry_filter = "logName:\"#{@log_name}\" textPayload:\"Hello, world!\""
46+
47+
expect(Google::Cloud).to receive(:new).with("YOUR_PROJECT_ID").
48+
and_return(@gcloud)
49+
expect(@gcloud).to receive(:logging).and_return(@logging)
50+
expect(@logging).to receive(:entry).and_return(@entry)
51+
expect(@entry).to receive(:log_name) { @log_name }
52+
expect(@logging.entries(filter: entry_filter)).to be_empty
4353

4454
expect {
4555
load File.expand_path("../quickstart.rb", __dir__)
4656
}.to output(
4757
"Logged Hello, world!\n"
4858
).to_stdout
4959

50-
wait_until(delay: 2) do
51-
logging.entries(filter: entry_filter).any?
60+
wait_until do
61+
@logging.entries(filter: entry_filter).any?
5262
end
5363

54-
entries = logging.entries filter: entry_filter
64+
entries = @logging.entries filter: entry_filter
5565
expect(entries).to_not be_empty
5666
end
5767

0 commit comments

Comments
 (0)