From 087ca6ecf94cb09195754f6aa5547e1023760d86 Mon Sep 17 00:00:00 2001 From: James Little Date: Thu, 3 Nov 2016 10:47:11 -0400 Subject: [PATCH 1/2] More logging --- lib/bagit.rb | 8 ++++++++ lib/bagit/manifest.rb | 5 ++++- lib/bagit/valid.rb | 9 ++++----- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/bagit.rb b/lib/bagit.rb index cf776b1..f9189d3 100644 --- a/lib/bagit.rb +++ b/lib/bagit.rb @@ -11,4 +11,12 @@ module BagIt # The version of the BagIt specification the code is conforming to. SPEC_VERSION = '0.97' + + def logger + Logging.logger + end + + def self.logger + @logger ||= Logger.new(STDOUT) + end end diff --git a/lib/bagit/manifest.rb b/lib/bagit/manifest.rb index f488abd..b0a1b7f 100644 --- a/lib/bagit/manifest.rb +++ b/lib/bagit/manifest.rb @@ -37,12 +37,15 @@ def manifest! rel_path = encode_filename(Pathname.new(f).relative_path_from(Pathname.new(bag_dir)).to_s) # sha1 + BagIt::logger.info('Creating sha1 manifest') sha1 = Digest::SHA1.file f File.open(manifest_file(:sha1), 'a') { |io| io.puts "#{sha1} #{rel_path}" } - + BagIt::logger.info("#{sha1} #{rel_path}".green) # md5 + BagIt::logger.info('Creating md5 manifest') md5 = Digest::MD5.file f File.open(manifest_file(:md5), 'a') { |io| io.puts "#{md5} #{rel_path}" } + BagIt::logger.info("#{md5} #{rel_path}") end tagmanifest! end diff --git a/lib/bagit/valid.rb b/lib/bagit/valid.rb index e9d843c..1d3e646 100644 --- a/lib/bagit/valid.rb +++ b/lib/bagit/valid.rb @@ -1,7 +1,6 @@ require 'validatable' require 'open-uri' require 'cgi' -require 'logger' module BagIt @@ -21,23 +20,23 @@ def decode_filename(s) # Return true if the manifest cover all files and all files are # covered. def complete? - logger = Logger.new(STDOUT) + if manifest_files == [] errors.add :completeness, "there are no manifest files" end unmanifested_files.each do |file| - logger.error("#{file} is present but not manifested".red) + BagIt::logger.error("#{file} is present but not manifested".red) errors.add :completeness, "#{file} is present but not manifested" end empty_manifests.each do |file| - logger.error("#{file} is manifested but not present".red) + BagIt::logger.error("#{file} is manifested but not present".red) errors.add :completeness, "#{file} is manifested but not present" end tag_empty_manifests.each do |file| - logger.error("#{file} is a manifested tag but not present".red) + BagIt::logger.error("#{file} is a manifested tag but not present".red) errors.add :completeness, "#{file} is a manifested tag but not present" end From 0790d353eee03b04bfd7e73c1fd7697a57833fb4 Mon Sep 17 00:00:00 2001 From: James Little Date: Thu, 3 Nov 2016 11:05:27 -0400 Subject: [PATCH 2/2] Add simplecov + coveralls --- .gitignore | 3 ++- bagit.gemspec | 2 ++ spec/logger_spec.rb | 9 +++++++++ spec/spec_helper.rb | 14 ++++++++++++-- spec/util/bagit_matchers.rb | 16 ---------------- 5 files changed, 25 insertions(+), 19 deletions(-) create mode 100644 spec/logger_spec.rb diff --git a/.gitignore b/.gitignore index a713501..371fa2c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ vendor Gemfile.lock .bundle .project -.idea \ No newline at end of file +.idea +coverage \ No newline at end of file diff --git a/bagit.gemspec b/bagit.gemspec index 06a9b99..85cb3e8 100644 --- a/bagit.gemspec +++ b/bagit.gemspec @@ -22,6 +22,8 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rake', '~> 10.4' spec.add_development_dependency 'rspec', '~> 3' spec.add_development_dependency 'coveralls' + spec.add_development_dependency 'simplecov' + spec.add_development_dependency 'simplecov-rcov' spec.files = `git ls-files`.split($/) spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } diff --git a/spec/logger_spec.rb b/spec/logger_spec.rb new file mode 100644 index 0000000..9b1dd39 --- /dev/null +++ b/spec/logger_spec.rb @@ -0,0 +1,9 @@ +# coding: utf-8 +require 'spec_helper' + +describe "logger" do + it "should let you log through the BagIt module" do + BagIt::logger.info("this is a string to log") + end +end + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 29ff3b8..3d80a57 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,10 +1,20 @@ require 'rubygems' require 'bundler' require 'coveralls' - +require 'simplecov' Bundler.require(:default, :test) -Coveralls.wear! +SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ + SimpleCov::Formatter::HTMLFormatter, + Coveralls::SimpleCov::Formatter +] +SimpleCov.start + + + +#Coveralls.wear! + + require File.expand_path('./util/bagit_matchers', File.dirname(__FILE__)) diff --git a/spec/util/bagit_matchers.rb b/spec/util/bagit_matchers.rb index 89e990f..7a8ac63 100644 --- a/spec/util/bagit_matchers.rb +++ b/spec/util/bagit_matchers.rb @@ -12,14 +12,6 @@ def matches?(target) @expected.include? @target end - def failure_message - "expected <#{@target}> to be in collection <#{@expected}>" - end - - def failure_message_when_negated - "expected <#{@target}> to not be in collection <#{@expected}>" - end - alias negative_failure_message failure_message_when_negated end @@ -35,14 +27,6 @@ def matches?(target) File.exist? target end - def failure_message - "expected <#{@target}> to exist, but it doesn't" - end - - def failure_message_when_negated - "expected <#{@target}> to not exist but it does" - end - alias negative_failure_message failure_message_when_negated end