spec/spec_helper.rb in mrjoy-bundler-audit-0.3.1 vs spec/spec_helper.rb in mrjoy-bundler-audit-0.3.2
- old
+ new
@@ -1,5 +1,9 @@
+require 'simplecov'
+require 'json'
+SimpleCov.start
+
require 'rspec'
require 'bundler/audit/version'
module Helpers
def sh(command, options={})
@@ -19,8 +23,50 @@
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.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))
+ end
+end