Runtime assertions for Ruby literal.fun
ruby
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #329 from aemadrid-twx/Adrian/fix_type_error_context

Fixes "Literal::TypeError::Context does not define to_h"

authored by

Stephen Ierodiaconou and committed by
GitHub
cfb4159a 627e0214

+21 -5
+2
lib/literal/errors/type_error.rb
··· 52 52 children: @children.map(&:to_h), 53 53 } 54 54 end 55 + 56 + alias to_hash to_h 55 57 end 56 58 57 59 def initialize(context:)
+19 -5
test/type_error.test.rb
··· 1 1 # frozen_string_literal: true 2 2 3 - test "Literal::TypeError#to_h returns a hash representation" do 4 - context = Literal::TypeError::Context.new 5 - error = Literal::TypeError.new(context:) 3 + Age = Literal::Value(Integer, 18..) 6 4 7 - result = error.to_h 8 - assert_equal Hash, result.class 5 + test do 6 + Age.new(17) 7 + rescue => error 8 + assert_equal error.class, Literal::TypeError 9 + assert_equal error.message, "Type mismatch\n\n" \ 10 + " _Constraint(Integer, 18..)\n" \ 11 + " Expected: 18..\n" \ 12 + " Actual (Integer): 17\n" 13 + 14 + # deconstruct_keys 15 + key_names = [:receiver, :method, :label, :actual] 16 + exp_keys = { 17 + receiver: nil, 18 + method: nil, 19 + label: nil, 20 + actual: 17, 21 + } 22 + assert_equal error.deconstruct_keys(key_names), exp_keys 9 23 end