From 695883a75783e19de70e60314fab49661c387a22 Mon Sep 17 00:00:00 2001 From: Danilo Sousa Date: Thu, 18 Feb 2016 17:01:25 -0200 Subject: create tests for `GithubRepo#validate_cfg!` method --- lib/oxidized/hook/githubrepo.rb | 2 +- spec/githubrepo_spec.rb | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/oxidized/hook/githubrepo.rb b/lib/oxidized/hook/githubrepo.rb index 80ae665..0c98460 100644 --- a/lib/oxidized/hook/githubrepo.rb +++ b/lib/oxidized/hook/githubrepo.rb @@ -1,6 +1,6 @@ class GithubRepo < Oxidized::Hook def validate_cfg! - cfg.has_key?('remote_repo') or raise KeyError, 'remote_repo is required' + raise KeyError, 'hook.remote_repo is required' unless cfg.has_key?('remote_repo') end def run_hook(ctx) diff --git a/spec/githubrepo_spec.rb b/spec/githubrepo_spec.rb index 36207d3..4674035 100644 --- a/spec/githubrepo_spec.rb +++ b/spec/githubrepo_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' require 'rugged' require 'oxidized/hook/githubrepo' -describe Oxidized::GithubRepo do +describe GithubRepo do let(:credentials) { mock() } let(:remote) { mock() } let(:remotes) { mock() } @@ -17,6 +17,18 @@ describe Oxidized::GithubRepo do Oxidized.setup_logger end + describe '#validate_cfg!' do + before do + gr.expects(:respond_to?).with(:validate_cfg!).returns(false) # `cfg=` call + end + + it 'raise a error when `remote_repo` is not configured' do + Oxidized.config.hooks.github_repo_hook = { type: 'githubrepo' } + gr.cfg = Oxidized.config.hooks.github_repo_hook + proc { gr.validate_cfg! }.must_raise(KeyError) + end + end + describe "#fetch_and_merge_remote" do before(:each) do Oxidized.config.hooks.github_repo_hook.remote_repo = 'git@github.com:username/foo.git' -- cgit v1.2.1