pt_logger 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pt_logger/base.rb +22 -2
- data/lib/pt_logger/version.rb +1 -1
- data/spec/support/credentials_helper.rb +4 -2
- data/spec/unit/base_spec.rb +43 -2
- metadata +2 -2
data/lib/pt_logger/base.rb
CHANGED
@@ -1,15 +1,35 @@
|
|
1
1
|
module PtLogger
|
2
2
|
|
3
3
|
# Command: log +message+ to Pivotal Tracker.
|
4
|
+
#
|
5
|
+
# The +message+ to log can the result of block evaluation:
|
6
|
+
#
|
7
|
+
# log do
|
8
|
+
# "evaluate the message to log here with implicit PT:999999 story id"
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# Or the +message+ to log can be passed as an arguent:
|
12
|
+
#
|
13
|
+
# log(message)
|
14
|
+
#
|
15
|
+
# An explicit story ID can be provided in both block and args form:
|
16
|
+
#
|
17
|
+
# log(story_id) do
|
18
|
+
# "evaluate the message to log here"
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# log(message,story_id)
|
22
|
+
#
|
4
23
|
# If +story_id+ is provided, logs to that story, else logs to a story ID
|
5
24
|
# referenced in the message itself (as #999 or PT:999).
|
6
25
|
#
|
7
26
|
# Returns true if log was successful, else false.
|
8
27
|
# Supresses any StandardErrors that may occur during logging.
|
9
28
|
#
|
10
|
-
def self.log(
|
29
|
+
def self.log(*args)
|
11
30
|
if pt = PtLogger::Logger.new
|
12
|
-
|
31
|
+
message = block_given? ? yield : args.shift
|
32
|
+
pt.append_story_note(message,args.shift)
|
13
33
|
else
|
14
34
|
false
|
15
35
|
end
|
data/lib/pt_logger/version.rb
CHANGED
@@ -22,6 +22,8 @@ NOTE: real PT credentials are not configured so if the integration tests are mis
|
|
22
22
|
they will fail. Set real PT credentials with environment variables:
|
23
23
|
|
24
24
|
export TEST_PTLOGGER_API_KEY=your_api_key
|
25
|
+
export TEST_PTLOGGER_PROJECT_ID=your_project_id
|
26
|
+
export TEST_PTLOGGER_STORY_ID=your_story_id
|
25
27
|
|
26
28
|
}
|
27
29
|
false
|
@@ -38,12 +40,12 @@ they will fail. Set real PT credentials with environment variables:
|
|
38
40
|
|
39
41
|
# Returns the project ID to use for tests
|
40
42
|
def test_project_id
|
41
|
-
'703897'
|
43
|
+
ENV['TEST_PTLOGGER_PROJECT_ID'] || '703897'
|
42
44
|
end
|
43
45
|
|
44
46
|
# Returns the story ID to use for tests
|
45
47
|
def test_story_id
|
46
|
-
'47387051'
|
48
|
+
ENV['TEST_PTLOGGER_STORY_ID'] || '47387051'
|
47
49
|
end
|
48
50
|
|
49
51
|
end
|
data/spec/unit/base_spec.rb
CHANGED
@@ -6,17 +6,56 @@ describe PtLogger do
|
|
6
6
|
|
7
7
|
describe "##log" do
|
8
8
|
subject { resource_class.log(message) }
|
9
|
-
|
9
|
+
|
10
|
+
context "with implicit story ID" do
|
10
11
|
let(:expected_story_id) { 12345678 }
|
11
12
|
let(:message) { "test message for story ##{expected_story_id}" }
|
12
13
|
let(:expected_message) { "[PtLogger] #{message}" }
|
13
|
-
|
14
|
+
|
15
|
+
context "when message passed as parameter" do
|
16
|
+
before do
|
17
|
+
logger_class.any_instance.should_receive(:send_story_note!).with(expected_message,expected_story_id).and_return(nil)
|
18
|
+
end
|
19
|
+
it { should be_true }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when message passed as block" do
|
23
|
+
subject { resource_class.log do
|
24
|
+
message
|
25
|
+
end }
|
26
|
+
before do
|
27
|
+
logger_class.any_instance.should_receive(:send_story_note!).with(expected_message,expected_story_id).and_return(nil)
|
28
|
+
end
|
29
|
+
it { should be_true }
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
context "with explicit story ID" do
|
35
|
+
let(:expected_story_id) { 12345678 }
|
36
|
+
let(:message) { "test message" }
|
37
|
+
let(:expected_message) { "[PtLogger] #{message}" }
|
38
|
+
|
39
|
+
context "when message passed as parameter" do
|
40
|
+
subject { resource_class.log(message,expected_story_id) }
|
41
|
+
before do
|
42
|
+
logger_class.any_instance.should_receive(:send_story_note!).with(expected_message,expected_story_id).and_return(nil)
|
43
|
+
end
|
44
|
+
it { should be_true }
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when message passed as block" do
|
48
|
+
subject { resource_class.log(expected_story_id) do
|
49
|
+
message
|
50
|
+
end }
|
14
51
|
before do
|
15
52
|
logger_class.any_instance.should_receive(:send_story_note!).with(expected_message,expected_story_id).and_return(nil)
|
16
53
|
end
|
17
54
|
it { should be_true }
|
18
55
|
end
|
56
|
+
|
19
57
|
end
|
58
|
+
|
20
59
|
context "when story_id is not defined" do
|
21
60
|
let(:message) { "test message without ID" }
|
22
61
|
it { should be_false }
|
@@ -25,6 +64,7 @@ describe PtLogger do
|
|
25
64
|
subject
|
26
65
|
end
|
27
66
|
end
|
67
|
+
|
28
68
|
context "when some kind of logging error occurs" do
|
29
69
|
let(:message) { "test message without ID" }
|
30
70
|
before do
|
@@ -32,6 +72,7 @@ describe PtLogger do
|
|
32
72
|
end
|
33
73
|
it { should be_false }
|
34
74
|
end
|
75
|
+
|
35
76
|
end
|
36
77
|
|
37
78
|
describe "#log_if" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pt_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|