Sha256: 580dcdf232071bbc0cf81e6425fe815c0c5c4015c8ea5506b0315b802c1dddef

Contents?: true

Size: 695 Bytes

Versions: 3

Compression:

Stored size: 695 Bytes

Contents

require 'spec_helper'
module Myrrha
  describe Coercions, "error_handler" do

    subject{ rules.apply(12, Float) }

    context 'with the default error handler' do
      let(:rules){ 
        Coercions.new
      }

      it "raises a Myrrha::Error when coercion fails" do
        lambda{
          subject
        }.should raise_error(Myrrha::Error, /Unable to coerce `12` to Float/)
      end
    end

    context 'with a user-defined error handler' do
      let(:rules){ 
        Coercions.new{|c|
          c.error_handler = lambda{|*args| args }
        }
      }

      it "calls the handler when coercion fails" do
        subject.should eq([12, Float, nil])
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
myrrha-3.1.0 spec/coercions/test_error_handler.rb
myrrha-3.0.0 spec/coercions/test_error_handler.rb
myrrha-3.0.0.rc7 spec/coercions/test_error_handler.rb