spec/spec_helper.rb in mrjoy-bundler-audit-0.3.3 vs spec/spec_helper.rb in mrjoy-bundler-audit-0.3.4

- old
+ new

@@ -8,73 +8,33 @@ require 'json' SimpleCov.start end require 'rspec' +require 'tmpdir' require 'bundler/audit' require 'bundler/audit/version' module Helpers def sh(command, options={}) Bundler.with_clean_env do + ENV["SIMPLECOV_COMMAND_NAME"] = example.full_description result = `#{command} 2>&1` raise "FAILED #{command}\n#{result}" if $?.success? == !!options[:fail] result end end def decolorize(string) string.gsub(/\e\[\d+m/, "") end - - def executable - File.expand_path(File.join('..','..','bin','bundle-audit'), __FILE__) - end - - def audit_in_directory(additions, directory, options={}) - Dir.chdir(directory) { decolorize(sh([executable, additions].compact.join(' '), options)) } - end - - def mocked_user_path - File.expand_path('../../tmp/data', __FILE__) - end - - def expect_update_to_clone_repo! - Bundler::Audit::Database. - should_receive(:system). - with('git', 'clone', Bundler::Audit::Database::VENDORED_PATH, mocked_user_path). - and_call_original - end - - def expect_update_to_update_repo! - Bundler::Audit::Database. - should_receive(:system). - with('git', 'pull', 'origin', 'master'). - and_call_original - end - - def fake_a_commit_in_the_user_repo - Dir.chdir(mocked_user_path) do - system 'git', 'commit', '--allow-empty', '-m', 'Dummy commit.' - end - end - - def roll_user_repo_back(num_commits) - Dir.chdir(mocked_user_path) do - system 'git', 'checkout', "HEAD~#{num_commits}" - system 'git', 'branch', '-f', 'master', 'HEAD' - system 'git', 'checkout', 'master' - end - end end include Bundler::Audit RSpec.configure do |config| - include Helpers + config.include Helpers - config.before(:each) do - stub_const("Bundler::Audit::Database::URL", Bundler::Audit::Database::VENDORED_PATH) - stub_const("Bundler::Audit::Database::USER_PATH", mocked_user_path) - FileUtils.rm_rf mocked_user_path if(File.exist?(mocked_user_path)) + config.before(:suite) do + Database.path = Dir.mktmpdir('ruby-advisory-db') end end