inform 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/examples/frozbot CHANGED
@@ -10,9 +10,17 @@ class Frozbot
10
10
  end
11
11
  end
12
12
 
13
- Inform.level = :info
14
- frozbot = Inform.info("Initializing the frozbot...") do
13
+ Inform.level = :debug
14
+
15
+ Inform.info("About to start")
16
+
17
+ frozbot = Inform.info("Initializing the %{thing}...", :thing => 'frozbot') do
18
+ Inform.debug "Preparing to make a new frozbot called %{name}", :name => 'puddy'
15
19
  Frozbot.new 'puddy'
16
20
  end
17
21
 
18
- Inform.info("Frozbot is %{name}", :name => frozbot.name)
22
+ Inform.info("Frozbot called %{name} has been initialized. Go %{name}, go!", :name => frozbot.name)
23
+
24
+ Inform.warning 'Hey wait on'
25
+ Inform.error 'There is an error in the %{thing} thing.', :thing => 'frozbot'
26
+
data/inform.gemspec CHANGED
@@ -12,7 +12,9 @@ Gem::Specification.new do |s|
12
12
  s.description = s.summary
13
13
 
14
14
  s.add_development_dependency("rspec", "~> 2.6.0")
15
-
15
+ s.add_development_dependency("rake")
16
+ s.add_development_dependency("gem-release")
17
+
16
18
  s.files = `git ls-files`.split("\n")
17
19
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
20
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -1,3 +1,3 @@
1
1
  class Inform
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/inform.rb CHANGED
@@ -18,7 +18,7 @@ class Inform
18
18
 
19
19
  DEFAULT_LOG_LEVEL = :info
20
20
  LOG_LEVELS = [:debug, :info, :warning, :error]
21
-
21
+
22
22
  class << self
23
23
 
24
24
  def level
@@ -71,7 +71,8 @@ class Inform
71
71
  @need_newline = false
72
72
  end
73
73
  message += "\n" if end_with_newline
74
- print message
74
+ $stdout.print message
75
+ $stdout.flush
75
76
  end
76
77
  end
77
78
 
@@ -86,7 +87,7 @@ class Inform
86
87
  end
87
88
  message + CLEAR
88
89
  end
89
-
90
+
90
91
  def color(message, *colours)
91
92
  colours.join("") + message + CLEAR
92
93
  end
data/spec/inform_spec.rb CHANGED
@@ -3,26 +3,50 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
3
3
  def should_print method
4
4
  describe method do
5
5
  it "should print a message" do
6
- Inform.should_receive(:print).with(/a special message/)
6
+ $stdout.should_receive(:print).with(/a special message/)
7
7
  Inform.send(method, "a special message")
8
8
  end
9
+ it "should interpolate keyword arguments" do
10
+ $stdout.should_receive(:print).with(/hello.+hey.+you.+goodbye/)
11
+ Inform.send(method, "hello %{a} %{b} goodbye", :a => 'hey', :b => 'you')
12
+ end
9
13
  end
10
14
  end
11
15
 
12
16
  def should_not_print method
13
17
  describe method do
14
18
  it "should not print a message" do
15
- Inform.should_not_receive(:say)
16
- Inform.should_not_receive(:print)
19
+ $stdout.should_not_receive(:print)
17
20
  Inform.send(method, "a special message")
18
21
  end
19
22
  end
20
23
  end
21
-
22
- # TODO: refactor, deal with all combinations of message / log level
24
+
25
+ def should_accept_block method
26
+ describe ":#{method.to_s} with a block" do
27
+ it "should print out the task being executed" do
28
+ $stdout.should_receive(:print).with(/message/)
29
+ Inform.send(method, "message") { true }
30
+ end
31
+ it "should print Done once the task is complete" do
32
+ $stdout.should_receive(:print).with(/Done/)
33
+ Inform.send(method, "") { true }
34
+ end
35
+ it "should evaluate the passed block and return the result" do
36
+ Inform.send(method, "") { 'hello' }.should == 'hello'
37
+ end
38
+ it "should allow us to print messages from within a block" do
39
+ $stdout.should_receive(:print).with(/open/)
40
+ $stdout.should_receive(:print).with(/inner/)
41
+ Inform.send(method, "open") { Inform.send(method, "inner") }
42
+ end
43
+ end
44
+ end
45
+
23
46
  describe Inform do
24
47
  before :each do
25
48
  @oldlevel = Inform.level
49
+ $stdout.stub(:print => nil) # SSSSSH.
26
50
  end
27
51
  after :each do
28
52
  Inform.level = @oldlevel
@@ -40,36 +64,12 @@ describe Inform do
40
64
  end
41
65
 
42
66
  context "with log level debug" do
43
- before :each do
44
- Inform.level = :debug
45
- Inform.stub(:print => nil) # SSSSSH.
46
- end
67
+ before { Inform.level = :debug }
47
68
 
48
69
  should_print :debug
49
70
  should_print :info
50
-
51
- describe ":info with a block" do
52
- it "should print out the task being executed" do
53
- Inform.should_receive(:print).with(/message/)
54
- Inform.info("message") { true }
55
- end
56
- it "should print Done once the task is complete" do
57
- Inform.should_receive(:print).with(/Done/)
58
- Inform.info("") { true }
59
- end
60
- it "should evaluate the passed block and return the result" do
61
- Inform.info("") { 'hello' }.should == 'hello'
62
- end
63
- it "should interpolate keyword arguments" do
64
- Inform.should_receive(:print).with(/hello.+hey.+you.+goodbye/)
65
- Inform.info("hello %{a} %{b} goodbye", :a => 'hey', :b => 'you')
66
- end
67
- it "should allow us to print messages from within a block" do
68
- Inform.should_receive(:print).with(/open/)
69
- Inform.should_receive(:print).with(/inner/)
70
- Inform.info("open") { Inform.debug("inner") }
71
- end
72
- end
71
+ should_accept_block :info
72
+ # should_accept_block :debug
73
73
 
74
74
  should_print :warning
75
75
  should_print :error
@@ -79,6 +79,9 @@ describe Inform do
79
79
  before { Inform.level = :info }
80
80
  should_not_print :debug
81
81
  should_print :info
82
+ should_accept_block :info
83
+ # should_accept_block :debug
84
+
82
85
  should_print :warning
83
86
  should_print :error
84
87
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inform
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Pearson
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-06-14 00:00:00 Z
19
+ date: 2011-06-29 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: rspec
@@ -34,6 +34,34 @@ dependencies:
34
34
  version: 2.6.0
35
35
  type: :development
36
36
  version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rake
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: gem-release
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :development
64
+ version_requirements: *id003
37
65
  description: Interactive, colourised logging
38
66
  email:
39
67
  - mipearson@gmail.com