spec/inform_spec.rb in inform-0.0.2 vs spec/inform_spec.rb in inform-0.0.3

- old
+ new

@@ -1,30 +1,54 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper')) def should_print method describe method do it "should print a message" do - Inform.should_receive(:print).with(/a special message/) + $stdout.should_receive(:print).with(/a special message/) Inform.send(method, "a special message") end + it "should interpolate keyword arguments" do + $stdout.should_receive(:print).with(/hello.+hey.+you.+goodbye/) + Inform.send(method, "hello %{a} %{b} goodbye", :a => 'hey', :b => 'you') + end end end def should_not_print method describe method do it "should not print a message" do - Inform.should_not_receive(:say) - Inform.should_not_receive(:print) + $stdout.should_not_receive(:print) Inform.send(method, "a special message") end end end - -# TODO: refactor, deal with all combinations of message / log level + +def should_accept_block method + describe ":#{method.to_s} with a block" do + it "should print out the task being executed" do + $stdout.should_receive(:print).with(/message/) + Inform.send(method, "message") { true } + end + it "should print Done once the task is complete" do + $stdout.should_receive(:print).with(/Done/) + Inform.send(method, "") { true } + end + it "should evaluate the passed block and return the result" do + Inform.send(method, "") { 'hello' }.should == 'hello' + end + it "should allow us to print messages from within a block" do + $stdout.should_receive(:print).with(/open/) + $stdout.should_receive(:print).with(/inner/) + Inform.send(method, "open") { Inform.send(method, "inner") } + end + end +end + describe Inform do before :each do @oldlevel = Inform.level + $stdout.stub(:print => nil) # SSSSSH. end after :each do Inform.level = @oldlevel end @@ -38,48 +62,27 @@ lambda {Inform.level = :warble}.should raise_error /unrecognized/i end end context "with log level debug" do - before :each do - Inform.level = :debug - Inform.stub(:print => nil) # SSSSSH. - end + before { Inform.level = :debug } should_print :debug should_print :info + should_accept_block :info + # should_accept_block :debug - describe ":info with a block" do - it "should print out the task being executed" do - Inform.should_receive(:print).with(/message/) - Inform.info("message") { true } - end - it "should print Done once the task is complete" do - Inform.should_receive(:print).with(/Done/) - Inform.info("") { true } - end - it "should evaluate the passed block and return the result" do - Inform.info("") { 'hello' }.should == 'hello' - end - it "should interpolate keyword arguments" do - Inform.should_receive(:print).with(/hello.+hey.+you.+goodbye/) - Inform.info("hello %{a} %{b} goodbye", :a => 'hey', :b => 'you') - end - it "should allow us to print messages from within a block" do - Inform.should_receive(:print).with(/open/) - Inform.should_receive(:print).with(/inner/) - Inform.info("open") { Inform.debug("inner") } - end - end - should_print :warning should_print :error end context "with log level set to :info" do before { Inform.level = :info } should_not_print :debug should_print :info + should_accept_block :info + # should_accept_block :debug + should_print :warning should_print :error end context "with log level set to :warning" do \ No newline at end of file