Sha256: 75ddbc8a09f2d3bf574cc5cca6180a38469fc92fbbd4f9009e698c37331e9e79
Contents?: true
Size: 1.75 KB
Versions: 2
Compression:
Stored size: 1.75 KB
Contents
lib_dir = File.join(File.dirname(__FILE__), "..", "lib" ) $LOAD_PATH.unshift lib_dir unless $LOAD_PATH.include?(lib_dir) require 'remote_logger' # Module that extends RSpec with my own extensions/macros module SpecMacros # Wrapper for *it* method that extracts description from example source code, such as: # spec{ use{ result = function(arg1 = 4, arg2 = 'string') }} def spec &block it description_from(*block.source_location), &block end # reads description line from source file and drops external brackets (like *spec*{}, *use*{}) def description_from(file, line) File.open(file) do |f| f.lines.to_a[line-1].gsub( Regexp.new('(spec.*?{)|(use.*?{)|}'), '' ).lstrip.rstrip end end end Spec::Runner.configure { |config| config.extend(SpecMacros) } module RemoteLoggerTest # Test related Constants: TEST_NAME = 'MyLogger' TEST_STRING = 'This is test string' # Checks that given block does not raise any errors def use lambda {yield}.should_not raise_error end # Returns empty block (for use in spec descriptions) def any_block lambda {|*args| args} end # Sets expectations of receiving timestamped message on both logfile mock and stdout def logger_should_log message formatted_message = Time.now.strftime message # logfile = mock('logfile').as_null_object # File.stub(:new).and_return(logfile) @logfile_mock.should_receive(:print).with(Regexp.new(formatted_message)) $stdout.should_receive(:print).with(Regexp.new(formatted_message)) end def logger_should_not_log message formatted_message = Time.now.strftime message @logfile_mock.should_not_receive(:print).with(Regexp.new(formatted_message)) $stdout.should_not_receive(:print).with(Regexp.new(formatted_message)) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
remote_logger-0.0.5 | spec/spec_helper.rb |
remote_logger-0.0.4 | spec/spec_helper.rb |