diff options
| author | Danilo Sousa <dsgoncalves@uoldiveo.com> | 2016-02-18 17:01:25 -0200 | 
|---|---|---|
| committer | Danilo Sousa <dsgoncalves@uoldiveo.com> | 2016-02-18 17:01:25 -0200 | 
| commit | 695883a75783e19de70e60314fab49661c387a22 (patch) | |
| tree | 6d1a73e712d824d0e28df6667e9f15731505e952 | |
| parent | a626c212f9e64434b828dadcb0cb3bd879beb612 (diff) | |
create tests for `GithubRepo#validate_cfg!` method
| -rw-r--r-- | lib/oxidized/hook/githubrepo.rb | 2 | ||||
| -rw-r--r-- | 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' | 
