Module: MinitestToRspec::SexpAssertions

Included in:
Model::Base, MinitestToRspec::Subprocessors::Base
Defined in:
lib/minitest_to_rspec/sexp_assertions.rb

Overview

Useful runtime assertions regarding S-expressions.

Instance Method Summary collapse

Instance Method Details

#assert_sexp_type(type, exp) ⇒ Object



12
13
14
15
16
# File 'lib/minitest_to_rspec/sexp_assertions.rb', line 12

def assert_sexp_type(type, exp)
  unless sexp_type?(type, exp)
    raise TypeError, "Expected #{type} s-expression, got #{exp.inspect}"
  end
end

#assert_sexp_type_array(type, obj) ⇒ Object



6
7
8
9
10
# File 'lib/minitest_to_rspec/sexp_assertions.rb', line 6

def assert_sexp_type_array(type, obj)
  unless obj.is_a?(Array) && obj.all? { |x| sexp_type?(type, x) }
    raise TypeError, "Expected array of #{type} sexp, got #{obj.inspect}"
  end
end

#sexp_type?(type, exp) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/minitest_to_rspec/sexp_assertions.rb', line 18

def sexp_type?(type, exp)
  exp.is_a?(Sexp) && exp.sexp_type == type.to_sym
end