Sha256: f3ffc028b11d731701f0047e223ab7ef815ecafdf0545acf0b340b7d54d3b6d3

Contents?: true

Size: 1.94 KB

Versions: 2

Compression:

Stored size: 1.94 KB

Contents

require 'spec_helper'

describe GenomerPluginValidate do

  describe "#run" do

    after do
      GenomerPluginValidate::Group.send(:remove_const,'Example')
    end

    before do
      @example = GenomerPluginValidate::Group::Example = Class.new
    end

    subject do
      described_class.new([arg].compact,{}).run
    end

    context "passed no arguments" do

      let(:arg) do
        nil
      end

      before do
        def @example.description
          "Some description"
        end
      end

      it "should return the help message" do
        msg = <<-EOS
          USAGE: genomer validate <GROUP>
          
          Available validation groups:
        EOS
        subject.should include msg.unindent
      end

      it "should include the descriptions annotation groups" do
        msg = '  example        Some description'
        subject.should include msg
      end

    end

    context "passed an unknown validation group name" do

      let(:arg) do
        "unknown"
      end

      it "should raise and Genomer::Error" do
        lambda{subject.to_s}.should raise_error Genomer::Error,
          "Unknown validation group 'unknown'"
      end

    end

    context "passed a known validation group name" do

      let(:validator) do
        c = Class.new(Genomer::Plugin)
        any_instance_of(c) do |instance|
          mock(instance).run{ [['some_error_1', 'some_error_2'],['another_error_1']]}
        end
        c
      end

      before do
        mock(GenomerPluginValidate::Group).groups{{'example' => @example}}
        mock(@example).validators{ ['example'] }
        mock(GenomerPluginValidate::Validator).validators{{'example' => validator}}
      end

      let(:arg) do
        "example"
      end

      it "should return a string output of validation error array" do
        subject.should ==<<-EOS.unindent.strip
           some_error_1
           some_error_2
           another_error_1
        EOS
      end

    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
genomer-plugin-validate-0.0.2 spec/genomer-plugin-validate_spec.rb
genomer-plugin-validate-0.0.1 spec/genomer-plugin-validate_spec.rb