Runtime assertions for Ruby literal.fun
ruby
5
fork

Configure Feed

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

`TypeError#to_h` calls `Context#to_h` but it wasn't defined on it (#344)

or alternatively

```
{
receiver:, method:, label:, expected:, actual:, children: children.map(&:to_h)
}
```

maybe reads nicer but obv uses the ivar accessor methods which the rest
of the class doesn't

authored by

Stephen Ierodiaconou and committed by
GitHub
627e0214 48216ed9

+20
+11
lib/literal/errors/type_error.rb
··· 41 41 expected.record_literal_type_errors(child) if expected.respond_to?(:record_literal_type_errors) 42 42 @children << child 43 43 end 44 + 45 + def to_h 46 + { 47 + receiver: @receiver, 48 + method: @method, 49 + label: @label, 50 + expected: @expected, 51 + actual: @actual, 52 + children: @children.map(&:to_h), 53 + } 54 + end 44 55 end 45 56 46 57 def initialize(context:)
+9
test/type_error.test.rb
··· 1 + # frozen_string_literal: true 2 + 3 + test "Literal::TypeError#to_h returns a hash representation" do 4 + context = Literal::TypeError::Context.new 5 + error = Literal::TypeError.new(context:) 6 + 7 + result = error.to_h 8 + assert_equal Hash, result.class 9 + end