Module: TinyTest::TestCase::Util
- Defined in:
- lib/tinytest.rb
Class Method Summary collapse
- .assertion_match_test(expected, actual) ⇒ Object
- .assertion_send_dispatch(receiver, message, *args) ⇒ Object
- .assertion_send_inspection(receiver, message, *args) ⇒ Object
- .build_message(message = nil, hook_end = nil, &default) ⇒ Object
- .describe_exception(ex) ⇒ Object
- .normalize_in_delta_epsilon_arguments(expected, actual, delta, message) ⇒ Object
- .normalize_raises_arguments(exceptions, &block) ⇒ Object
Class Method Details
.assertion_match_test(expected, actual) ⇒ Object
640 641 642 643 644 |
# File 'lib/tinytest.rb', line 640 def self.assertion_match_test(expected, actual) expected =~ actual rescue TypeError /#{Regexp.escape(expected)}/ =~ actual end |
.assertion_send_dispatch(receiver, message, *args) ⇒ Object
657 658 659 |
# File 'lib/tinytest.rb', line 657 def self.assertion_send_dispatch(receiver, , *args) receiver.__send__(, *args) end |
.assertion_send_inspection(receiver, message, *args) ⇒ Object
661 662 663 |
# File 'lib/tinytest.rb', line 661 def self.assertion_send_inspection(receiver, , *args) "#{receiver.inspect}.#{}(#{args.map{|e| e.inspect }.join(', ')})" end |
.build_message(message = nil, hook_end = nil, &default) ⇒ Object
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 |
# File 'lib/tinytest.rb', line 683 def self.( = nil, hook_end = nil, &default) if lambda{ = .to_s << '.' unless .empty? << "\n#{default.call}." .strip! = hook_end.call() if hook_end } else lambda{ = "#{default.call}." = hook_end.call() if hook_end } end end |
.describe_exception(ex) ⇒ Object
672 673 674 675 676 677 678 679 680 681 |
# File 'lib/tinytest.rb', line 672 def self.describe_exception(ex) bt = ex.backtrace.reject{|s| i = s.index(__FILE__) and i == 0 } [ "Class: <#{ex.class}>", "Message: <#{ex.}>", "---Backtrace---", bt.join("\n"), "---------------", ].join("\n") end |
.normalize_in_delta_epsilon_arguments(expected, actual, delta, message) ⇒ Object
646 647 648 649 650 651 652 653 654 655 |
# File 'lib/tinytest.rb', line 646 def self.normalize_in_delta_epsilon_arguments(expected, actual, delta, ) unless begin delta = Float(delta) rescue TypeError, ArgumentError delta, = 0.001, delta end end return expected, actual, Float(delta), end |
.normalize_raises_arguments(exceptions, &block) ⇒ Object
665 666 667 668 669 670 |
# File 'lib/tinytest.rb', line 665 def self.normalize_raises_arguments(exceptions, &block) exceptions = [*exceptions] raise ArgumentError, "wrong number of arguments(0 for 1)" if exceptions.empty? raise LocalJumpError, "no block given (yield)" unless block_given? exceptions end |