Sha256: 97e64f5556b75b21bc186f87aead7c4200e8457efc79f8d8646dd153741a6e55

Contents?: true

Size: 1007 Bytes

Versions: 6

Compression:

Stored size: 1007 Bytes

Contents

require 'spec_helper'

module Jschematic
  describe Errors do
    let(:errors) { Errors.new }

    it "is enumerable" do
      errors.class.should include(Enumerable)

      errors.add(:ident1, "desc1")
      errors.add(:ident2, "desc2")

      col = []
      errors.each{ |error| col << error }

      col.should == [[:ident1, "desc1"], [:ident2, "desc2"]]
    end

    describe "#add" do
      it "records an error" do
        errors.add(:ident, "description")
        errors.all.should == [[:ident, "description"]]
      end

      context "when raise on error is true" do
        let(:errors) { Errors.new(true) }

        it "raises when an error is added" do
          expect { errors.add(:ident, "description") }.to raise_error(/Error: description/)
        end
      end
    end

    describe "#reset!" do
      it "clears the collected errors" do
        errors.add(:ident, "desc")
        errors.should_not be_empty
        errors.reset!
        errors.should be_empty
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
jschematic-0.1.0 spec/jschematic/errors_spec.rb
jschematic-0.0.9 spec/jschematic/errors_spec.rb
jschematic-0.0.6 spec/jschematic/errors_spec.rb
jschematic-0.0.5 spec/jschematic/errors_spec.rb
jschematic-0.0.2 spec/jschematic/errors_spec.rb
jschematic-0.0.1 spec/jschematic/errors_spec.rb