spec/command/command_spec.rb in command_exec-0.0.3 vs spec/command/command_spec.rb in command_exec-0.1.0

- old
+ new

@@ -1,13 +1,12 @@ require 'spec_helper' describe Command do - let(:logger) {Logger.new('/dev/null')} + let(:logger) {Logger.new(StringIO.new)} #let(:logger) {Logger.new($stdout)} - let(:debug) {false} - #let(:debug) {true} - let(:command) { Command.new(:echo , :debug=>debug, :logger => logger, :parameter => "hello world" , :error_keywords => %q[abc def], :working_directory => '/tmp' ) } + let(:log_level) {:info} + let(:command) { Command.new(:echo , :log_level => :silent, :logger => logger, :parameter => "hello world" , :error_keywords => %q[abc def], :working_directory => '/tmp' ) } it "has a path" do command.path.should == '/bin/echo' end @@ -28,11 +27,11 @@ it "has special keywords indicating errors in stdout" do command.error_keywords.should == %q[abc def] end it "can be used to construct a command string, which can be executed" do - command = Command.new(:pdflatex, :debug => debug, :logger => logger, :parameter => "index.tex blub.tex", :options => "-a -b") + command = Command.new(:pdflatex, :log_level => :silent, :logger => logger, :parameter => "index.tex blub.tex", :options => "-a -b") command.send(:build_cmd_string).should == "/usr/bin/pdflatex -a -b index.tex blub.tex" end it "runs programms" do command.run @@ -42,21 +41,21 @@ it "returns the textual rep of a command" do command.to_txt.should == '/bin/echo hello world' end it "execute existing programs" do - command = Command.execute(:echo, :debug => debug, :logger => logger ,:parameter => "index.tex blub.tex", :options => "-- -a -b") + command = Command.execute(:echo, :log_level => :silent, :logger => logger ,:parameter => "index.tex blub.tex", :options => "-- -a -b") command.result.should == true end it "does not execute non-existing programs" do - command = Command.execute(:grep, :debug => debug, :logger => logger, :parameter => "index.tex blub.tex", :options => "-- -a -b") + command = Command.execute(:grep, :log_level => :silent, :logger => logger, :parameter => "index.tex blub.tex", :options => "-- -a -b") command.result.should == false end it "checks if errors have happend during execution" do - lambda { Command.new(:echo1, :debug => debug, :logger => logger, :parameter => "index.tex blub.tex", :options => "-- -a -b") }.should raise_error CommandNotFound + lambda { Command.new(:echo1, :log_level => :silent, :logger => logger, :parameter => "index.tex blub.tex", :options => "-- -a -b") }.should raise_error CommandNotFound end it "decides which output should be returned to the user" do logfile = StringIO.new logfile << 'Error in ... found' @@ -92,9 +91,35 @@ it "output a message" do command.send(:message, false, 'Hello_world').should == "\e[1m\e[31mFAILED\e[0m\e[0m\nHello_world" command.send(:message, true, 'Hello_world').should == "\e[1m\e[32mOK\e[0m\e[0m" command.send(:message, true ).should == "\e[1m\e[32mOK\e[0m\e[0m" end + + it "is very verbose and returns a lot of output" do + bucket = StringIO.new + logger = Logger.new(bucket) + Command.execute(:echo, :logger => logger ,:parameter => "index.tex blub.tex", :options => "-- -a -b" , :log_level => :debug) + + bucket.string.should =~ /OK/ + end + + it "is silent and returns no output" do + bucket = StringIO.new + logger = Logger.new(bucket) + Command.execute(:echo, :logger => logger ,:parameter => "index.tex blub.tex", :options => "-- -a -b" , :log_level => :silent) + + bucket.string.should == "" + end + + # not completed + #it "use a log file if given" do + # application_log_file = Tempfile.new('command_exec_test') + # application_log_file.write "ERROR" + + # binding.pry + # Command.execute(:echo, :logger => logger ,:parameter => "index.tex blub.tex", :options => "-- -a -b" , :log_level => :silent, :logfile => application_log_file, :error_keywords => %W[ERROR]) + + #end end