Class: Liza::Test
Direct Known Subclasses
Defined Under Namespace
Classes: Tree
Constant Summary collapse
- LOG_BUILDING =
false- LOG_ASSERTION =
true- LOG_ASSERTION_MESSAGE =
true- LOG_CALL_BLOCK =
true
Instance Attribute Summary collapse
-
#assertions ⇒ Integer
Returns the number of assertions made by the instance, initializing to 0 if not set.
-
#test_words ⇒ Object
readonly
Returns the value of attribute test_words.
Class Method Summary collapse
-
._assertion_errored(e) ⇒ Object
Records an assertion that resulted in an error.
-
._assertion_failed(msg) ⇒ Object
Records a failed assertion with an associated message.
-
._assertion_passed ⇒ Object
Records a successful assertion.
-
._assertion_todo(msg) ⇒ Object
Records a "to-do" assertion message.
- ._log_test_block(test_block) ⇒ Object
- .after(&block) ⇒ Object
- .after_stack ⇒ Object
- .before(&block) ⇒ Object
- .before_stack ⇒ Object
- .call(class_index, class_count) ⇒ Object
-
.color ⇒ Object
color.
- .division ⇒ Object
- .group(*words, &block) ⇒ Object
- .log_test_building(node, test_block) ⇒ Object
- .log_test_building? ⇒ Boolean
- .subject_class ⇒ Object
- .subsystem ⇒ Object
- .system ⇒ Object
- .test(*words, &block) ⇒ Object
- .test_node ⇒ Object
-
.test_tree ⇒ Object
def self.test_tree; @test_tree ||= Liza::TestTreePart.new nil, before_stack, after_stack end.
-
.totals ⇒ Hash
Returns or initializes a hash that tracks the totals for various test outcomes.
Instance Method Summary collapse
- #_caller_line_split(s) ⇒ Object
-
#_groups ⇒ Array
Provides or initializes an array to manage test group contexts.
-
#_inc_assertions ⇒ Object
Increments the count of assertions by one.
- #_log_test_assertion_tag(method_name) ⇒ Object
- #_log_test_block(test_block) ⇒ Object
-
#assert(b, msg = "it should have been true", kaller: nil) ⇒ Boolean
Asserts that a condition is true.
-
#assert!(b, msg = "it should have been true") ⇒ Object
Performs an assertion and stops the test execution if it fails.
-
#assert_equality(a, b, msg = nil, kaller: nil) ⇒ Boolean
Asserts that
aandbare equal. -
#assert_equality!(a, b, msg = nil) ⇒ void
Asserts that
aandbare equal, stopping execution on failure. -
#assert_gt(a, b, msg = nil, kaller: nil) ⇒ Boolean
Asserts that
ais greater thanb. -
#assert_lt(a, b, msg = nil, kaller: nil) ⇒ Boolean
Asserts that
ais lesser thanb. -
#assert_no_raise(msg = nil, kaller: nil) { ... } ⇒ Boolean
Asserts that no exception is raised when executing the given block.
-
#assert_no_raise!(msg = nil) { ... } ⇒ void
Asserts that no exception is raised when executing the given block, stopping execution on failure.
-
#assert_raises(exception_klass, msg = nil, kaller: nil) { ... } ⇒ Boolean
Asserts that the given block raises an exception of the specified class.
-
#assert_raises!(e, msg = nil) ⇒ void
Asserts that the given block raises an exception, stopping execution on failure.
- #call ⇒ Object
-
#critical(passed) ⇒ Object
Halt test execution if a condition fails by throwing :critical symbol.
- #division ⇒ Object
-
#group(kaller: nil, **_words) {|block| ... } ⇒ Object
Executes a block within a test group context.
-
#initialize(test_words, before_stack, after_stack, &test_block) ⇒ Test
constructor
A new instance of Test.
- #log_test_assertion(method_name, kaller) ⇒ Object
- #log_test_assertion? ⇒ Boolean
- #log_test_assertion_message(b, msg) ⇒ Object
- #log_test_assertion_message? ⇒ Boolean
- #log_test_assertion_result ⇒ Object
- #log_test_building? ⇒ Boolean
- #log_test_call(prefix, &block) ⇒ Object
- #log_test_call_block? ⇒ Boolean
- #log_test_call_rescue(e) ⇒ Object
-
#refute(b, msg = "it should have been false", kaller: nil) ⇒ Boolean
Asserts that a condition is false.
-
#refute!(b, msg = "it should have been false") ⇒ Object
Performs a refutation and stops the test execution if it fails.
-
#refute_equality(a, b, msg = nil, kaller: nil) ⇒ Boolean
Asserts that
aandbare not equal. -
#refute_equality!(a, b, msg = nil) ⇒ void
Asserts that
aandbare not equal, stopping execution on failure. -
#refute_gt(a, b, msg = nil, kaller: nil) ⇒ Boolean
Asserts that
ais not greater thanb. -
#refute_lt(a, b, msg = nil, kaller: nil) ⇒ Boolean
Asserts that
ais not lesser thanb. -
#refute_no_raise(msg = nil, kaller: nil) { ... } ⇒ Boolean
Refutes that no exception is raised when executing the given block.
-
#refute_no_raise!(msg = nil) { ... } ⇒ void
Refutes that no exception is raised when executing the given block, stopping execution on success.
-
#refute_raises(exception_klass, msg = nil, kaller: nil) { ... } ⇒ Boolean
Asserts that the given block does not raise an exception of the specified class.
-
#refute_raises!(e, msg = nil) ⇒ void
Asserts that the given block does not raise an exception, stopping execution on failure.
- #subject ⇒ Object
- #subject_class ⇒ Object
- #system ⇒ Object
-
#todo(msg) ⇒ Object
Marks a test as a "to-do" with an associated message.
Methods inherited from Unit
_erbs_for, add, #add, cl, #cl, class_methods_defined, const_added, const_missing, constants_defined, define_error, descendants_select, erbs_available, erbs_defined, erbs_for, errors, #fetch, fetch, get, #get, instance_methods_defined, #log, log, log?, #log?, log_array, #log_array, log_hash, #log_hash, #log_level, log_level, #log_level?, log_level?, log_levels, #log_levels, #log_render_convert, #log_render_format, #log_render_in, #log_render_out, method_added, methods_defined, namespace, part, #raise_error, raise_error, reload!, #reload!, #render, #render!, #render_stack, renderable_formats_for, renderable_names, section, sections, #set, set, #settings, settings, singleton_method_added, #sleep, sleep, stick, #stick, sticks, #sticks, subclasses_select, subunits, system?, test_class, time_diff, #time_diff
Constructor Details
#initialize(test_words, before_stack, after_stack, &test_block) ⇒ Test
Returns a new instance of Test.
645 646 647 |
# File 'lib/liza/helper_units/test.rb', line 645 def initialize test_words, before_stack, after_stack, &test_block @test_words, @before_stack, @after_stack, @test_block = test_words, before_stack, after_stack, test_block end |
Instance Attribute Details
#assertions ⇒ Integer
Returns the number of assertions made by the instance, initializing to 0 if not set.
51 52 53 |
# File 'lib/liza/helper_units/test.rb', line 51 def assertions @assertions ||= 0 end |
#test_words ⇒ Object (readonly)
Returns the value of attribute test_words.
643 644 645 |
# File 'lib/liza/helper_units/test.rb', line 643 def test_words @test_words end |
Class Method Details
._assertion_errored(e) ⇒ Object
Records an assertion that resulted in an error.
39 40 41 |
# File 'lib/liza/helper_units/test.rb', line 39 def self._assertion_errored e self.totals[:errors] << e end |
._assertion_failed(msg) ⇒ Object
Records a failed assertion with an associated message.
32 33 34 |
# File 'lib/liza/helper_units/test.rb', line 32 def self._assertion_failed msg self.totals[:fails] << msg end |
._assertion_passed ⇒ Object
Records a successful assertion.
25 26 27 |
# File 'lib/liza/helper_units/test.rb', line 25 def self._assertion_passed self.totals[:passes] << 1 end |
._assertion_todo(msg) ⇒ Object
Records a "to-do" assertion message.
20 21 22 |
# File 'lib/liza/helper_units/test.rb', line 20 def self._assertion_todo msg self.totals[:todos] << msg end |
._log_test_block(test_block) ⇒ Object
772 773 774 |
# File 'lib/liza/helper_units/test.rb', line 772 def self._log_test_block test_block test_block.source_location.join(":").gsub("#{App.root}/", "") end |
.after(&block) ⇒ Object
874 875 876 877 |
# File 'lib/liza/helper_units/test.rb', line 874 def self.after &block raise ArgumentError, "No block given" unless block_given? test_node.add_after(&block) end |
.after_stack ⇒ Object
848 |
# File 'lib/liza/helper_units/test.rb', line 848 def self.after_stack; @after_stack ||= superclass.after_stack.dup end |
.before(&block) ⇒ Object
869 870 871 872 |
# File 'lib/liza/helper_units/test.rb', line 869 def self.before &block raise ArgumentError, "No block given" unless block_given? test_node.add_before(&block) end |
.before_stack ⇒ Object
847 |
# File 'lib/liza/helper_units/test.rb', line 847 def self.before_stack; @before_stack ||= superclass.before_stack.dup end |
.call(class_index, class_count) ⇒ Object
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 |
# File 'lib/liza/helper_units/test.rb', line 616 def self.call class_index, class_count counter_class = "#{class_index.to_s.rjust 3, "0"}/#{class_count.to_s.rjust 3, "0"}" log stick :bold, :white, "+ #{counter_class} #{self} class" array = [test_tree] while array.any? node = array.pop i = 0 node.tests.each do |test_words, test_block| counter_instance = "#{(i+=1).to_s.rjust 2, '0'}/#{node.tests.size.to_s.rjust 2, '0'}" label = test_words.to_a.flatten.join(" ")[0..25] log " #{ counter_class } #{ counter_instance } #{ label.ljust(27)} #{_log_test_block test_block}" log_test_building node, test_block if log_test_building? instance = new test_words, node.before_stack, node.after_stack, &test_block instance.call end array.concat node.children end end |
.color ⇒ Object
color
934 935 936 937 938 939 |
# File 'lib/liza/helper_units/test.rb', line 934 def self.color subject_class.color rescue # a workaround for when subject_class is not a Unit :white end |
.division ⇒ Object
687 688 689 690 691 |
# File 'lib/liza/helper_units/test.rb', line 687 def self.division subject_class.division rescue Liza::Controller end |
.group(*words, &block) ⇒ Object
856 857 858 859 860 861 862 |
# File 'lib/liza/helper_units/test.rb', line 856 def self.group *words, &block raise ArgumentError, "No block given" unless block_given? previous = test_node @test_node = test_node.branch_out words instance_exec(&block) @test_node = previous end |
.log_test_building(node, test_block) ⇒ Object
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 |
# File 'lib/liza/helper_units/test.rb', line 734 def self.log_test_building node, test_block log stick :red, :white, :b, " the building blocks are" node.before_stack.each do |stack| stack.each do |bl| log stick :red, :white, :b, " before block #{_log_test_block bl}" end end log stick :red, :white, :b, " test block #{_log_test_block test_block}" node.after_stack.each do |stack| stack.each do |bl| log stick :red, :white, :b, " after block #{_log_test_block bl}" end end end |
.log_test_building? ⇒ Boolean
697 698 699 |
# File 'lib/liza/helper_units/test.rb', line 697 def self.log_test_building? LOG_BUILDING end |
.subject_class ⇒ Object
815 816 817 818 819 820 821 822 |
# File 'lib/liza/helper_units/test.rb', line 815 def self.subject_class @subject_class ||= if first_namespace == "Liza" Liza.const_get last_namespace[0..-5] else Object.const_get name[0..-5] end end |
.subsystem ⇒ Object
928 929 930 |
# File 'lib/liza/helper_units/test.rb', line 928 def self.subsystem subject_class.subsystem end |
.system ⇒ Object
832 833 834 835 836 |
# File 'lib/liza/helper_units/test.rb', line 832 def self.system subject_class.system rescue System end |
.test(*words, &block) ⇒ Object
864 865 866 867 |
# File 'lib/liza/helper_units/test.rb', line 864 def self.test *words, &block raise ArgumentError, "No block given" unless block_given? test_node.add_test words, &block end |
.test_node ⇒ Object
850 |
# File 'lib/liza/helper_units/test.rb', line 850 def self.test_node; @test_node ||= test_tree end |
.test_tree ⇒ Object
def self.test_tree; @test_tree ||= Liza::TestTreePart.new nil, before_stack, after_stack end
852 |
# File 'lib/liza/helper_units/test.rb', line 852 def self.test_tree; @test_tree ||= Tree.new nil, before_stack, after_stack end |
.totals ⇒ Hash
Returns or initializes a hash that tracks the totals for various test outcomes.
8 9 10 11 12 13 14 15 |
# File 'lib/liza/helper_units/test.rb', line 8 def self.totals @totals ||= { errors: [], todos: [], fails: [], passes: [], } end |
Instance Method Details
#_caller_line_split(s) ⇒ Object
801 802 803 804 805 |
# File 'lib/liza/helper_units/test.rb', line 801 def _caller_line_split s x = s.split ":in `" x[1] = x[1][0..-2] x end |
#_groups ⇒ Array
Provides or initializes an array to manage test group contexts.
75 76 77 |
# File 'lib/liza/helper_units/test.rb', line 75 def _groups @_groups ||= [] end |
#_inc_assertions ⇒ Object
Increments the count of assertions by one.
56 57 58 |
# File 'lib/liza/helper_units/test.rb', line 56 def _inc_assertions self.assertions += 1 end |
#_log_test_assertion_tag(method_name) ⇒ Object
768 769 770 |
# File 'lib/liza/helper_units/test.rb', line 768 def _log_test_assertion_tag method_name "#{log_test_assertion_result} #{stick :bold, :white, method_name.to_s.ljust(20)}" end |
#_log_test_block(test_block) ⇒ Object
776 777 778 |
# File 'lib/liza/helper_units/test.rb', line 776 def _log_test_block test_block self.class._log_test_block test_block end |
#assert(b, msg = "it should have been true", kaller: nil) ⇒ Boolean
Asserts that a condition is true.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/liza/helper_units/test.rb', line 103 def assert b, msg = "it should have been true", kaller: nil if b self.class._assertion_passed @last_result = :passed else self.class._assertion_failed msg @last_result = :failed end kaller ||= caller log_test_assertion __method__, kaller if _groups.empty? b end |
#assert!(b, msg = "it should have been true") ⇒ Object
Performs an assertion and stops the test execution if it fails.
143 144 145 |
# File 'lib/liza/helper_units/test.rb', line 143 def assert! b, msg = "it should have been true" critical assert b, msg, kaller: caller end |
#assert_equality(a, b, msg = nil, kaller: nil) ⇒ Boolean
Asserts that a and b are equal.
Passes if a == b, fails otherwise. Optionally takes a custom failure message.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/liza/helper_units/test.rb', line 175 def assert_equality a, b, msg = nil, kaller: nil ret = a == b if ret self.class._assertion_passed @last_result = :passed else self.class._assertion_failed msg @last_result = :failed end kaller ||= caller log_test_assertion __method__, kaller if _groups.empty? if msg ||= "#{__method__} #{a.inspect}, #{b.inspect} (== equality)" ret, msg end ret end |
#assert_equality!(a, b, msg = nil) ⇒ void
This method returns an undefined value.
Asserts that a and b are equal, stopping execution on failure.
Calls #assert_equality and halts if the assertion fails.
240 241 242 |
# File 'lib/liza/helper_units/test.rb', line 240 def assert_equality! a, b, msg = nil critical assert_equality a, b, msg, kaller: caller end |
#assert_gt(a, b, msg = nil, kaller: nil) ⇒ Boolean
Asserts that a is greater than b.
Passes if a > b, fails otherwise. Optionally takes a custom failure message.
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
# File 'lib/liza/helper_units/test.rb', line 488 def assert_gt a, b, msg = nil, kaller: nil raise "First argument is not Comparable (#{a.class})" unless a.is_a?(Comparable) raise "Second argument is not Comparable (#{b.class})" unless b.is_a?(Comparable) ret = a > b if ret self.class._assertion_passed @last_result = :passed else self.class._assertion_failed msg @last_result = :failed end kaller ||= caller log_test_assertion __method__, kaller if _groups.empty? if msg ||= "#{__method__} #{a.inspect}, #{b.inspect} (> greater than)" ret, msg end ret end |
#assert_lt(a, b, msg = nil, kaller: nil) ⇒ Boolean
Asserts that a is lesser than b.
Passes if a > b, fails otherwise. Optionally takes a custom failure message.
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 |
# File 'lib/liza/helper_units/test.rb', line 556 def assert_lt a, b, msg = nil, kaller: nil raise "First argument is not Comparable (#{a.class})" unless a.is_a?(Comparable) raise "Second argument is not Comparable (#{b.class})" unless b.is_a?(Comparable) ret = a < b if ret self.class._assertion_passed @last_result = :passed else self.class._assertion_failed msg @last_result = :failed end kaller ||= caller log_test_assertion __method__, kaller if _groups.empty? if msg ||= "#{__method__} #{a.inspect}, #{b.inspect} (< lesser than)" ret, msg end ret end |
#assert_no_raise(msg = nil, kaller: nil) { ... } ⇒ Boolean
Asserts that no exception is raised when executing the given block.
Passes if the block executes without raising any exception.
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/liza/helper_units/test.rb', line 380 def assert_no_raise(msg = nil, kaller: nil, &block) raise ArgumentError, "No block given" unless block_given? ret = true begin yield rescue Exception => e ret = false error = e end if ret self.class._assertion_passed @last_result = :passed else self.class._assertion_failed msg @last_result = :failed end kaller ||= caller log_test_assertion __method__, kaller if _groups.empty? if msg ||= "#{__method__} - Expected no exception, got #{error.inspect}" unless ret ret, msg end ret end |
#assert_no_raise!(msg = nil) { ... } ⇒ void
This method returns an undefined value.
Asserts that no exception is raised when executing the given block, stopping execution on failure.
Calls #assert_no_raise and halts if an exception is raised.
419 420 421 |
# File 'lib/liza/helper_units/test.rb', line 419 def assert_no_raise!(msg = nil, &block) critical assert_no_raise(msg, kaller: caller, &block) end |
#assert_raises(exception_klass, msg = nil, kaller: nil) { ... } ⇒ Boolean
Asserts that the given block raises an exception of the specified class.
Fails if the block does not raise an exception or raises an unexpected type.
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/liza/helper_units/test.rb', line 271 def assert_raises exception_klass, msg = nil, kaller: nil, &block raise ArgumentError, "No block given" unless block_given? ret = false begin yield rescue => e ret = exception_klass === e error = e end if ret self.class._assertion_passed @last_result = :passed else self.class._assertion_failed msg @last_result = :failed end kaller ||= caller log_test_assertion __method__, kaller if _groups.empty? if msg ||= "#{__method__} (#{exception_klass}) #{error.inspect}" ret, msg end ret end |
#assert_raises!(e, msg = nil) ⇒ void
This method returns an undefined value.
Asserts that the given block raises an exception, stopping execution on failure.
Calls #assert_raises and halts if the assertion fails.
351 352 353 |
# File 'lib/liza/helper_units/test.rb', line 351 def assert_raises! e, msg = nil critical assert_raises e, msg, kaller: caller end |
#call ⇒ Object
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 |
# File 'lib/liza/helper_units/test.rb', line 649 def call catch :critical do @before_stack.each do |stack| log " calling stacked before blocks #{stack.map { |bl| _log_test_block bl }}" if log_test_building? stack.each do |bl| log_test_call "B&", &bl if log_test_call_block? instance_exec(&bl) end end bl = @test_block log " calling test block #{_log_test_block bl}" if log_test_building? log_test_call "T&", &bl if log_test_call_block? instance_exec(&bl) @after_stack.each do |stack| log " calling stacked after blocks #{stack.map { |bl| _log_test_block bl }}" if log_test_building? stack.each do |bl| log_test_call "A&", &bl if log_test_call_block? instance_exec(&bl) end end end rescue Exception => e self.class._assertion_errored e log_test_call_rescue e ensure puts end |
#critical(passed) ⇒ Object
Halt test execution if a condition fails by throwing :critical symbol.
158 159 160 |
# File 'lib/liza/helper_units/test.rb', line 158 def critical passed throw :critical, :critical if not passed end |
#division ⇒ Object
693 694 695 |
# File 'lib/liza/helper_units/test.rb', line 693 def division self.class.division end |
#group(kaller: nil, **_words) {|block| ... } ⇒ Object
Executes a block within a test group context.
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/liza/helper_units/test.rb', line 84 def group kaller: nil, **_words, &block block_given? || raise(ArgumentError, "No block given") _groups << block instance_exec(&block) _groups.pop kaller ||= caller log_test_assertion __method__, kaller if _groups.empty? end |
#log_test_assertion(method_name, kaller) ⇒ Object
758 759 760 761 762 763 764 765 766 |
# File 'lib/liza/helper_units/test.rb', line 758 def log_test_assertion method_name, kaller _inc_assertions prefix = "#{assertions.to_s.rjust 2, "0"} #{_log_test_assertion_tag method_name}" source_location = _caller_line_split(kaller[0])[0] source_location = source_location.gsub("#{App.root}/", "") log " #{prefix} #{source_location}" if log_test_assertion? end |
#log_test_assertion? ⇒ Boolean
705 706 707 |
# File 'lib/liza/helper_units/test.rb', line 705 def log_test_assertion? LOG_ASSERTION end |
#log_test_assertion_message(b, msg) ⇒ Object
793 794 795 796 797 798 799 |
# File 'lib/liza/helper_units/test.rb', line 793 def b, msg if b log stick :light_green, " passed #{msg}" else log stick :light_red, " failed #{msg}" end end |
#log_test_assertion_message? ⇒ Boolean
709 710 711 |
# File 'lib/liza/helper_units/test.rb', line 709 def LOG_ASSERTION_MESSAGE end |
#log_test_assertion_result ⇒ Object
780 781 782 783 784 785 786 787 788 789 790 791 |
# File 'lib/liza/helper_units/test.rb', line 780 def log_test_assertion_result case @last_result when :todo (stick " todo", :light_blue).to_s when :passed (stick "passed", :light_green).to_s when :failed (stick "failed", :light_red).to_s else raise "Unknown result: #{@last_result}" end end |
#log_test_building? ⇒ Boolean
701 702 703 |
# File 'lib/liza/helper_units/test.rb', line 701 def log_test_building? self.class.log_test_building? end |
#log_test_call(prefix, &block) ⇒ Object
752 753 754 755 756 |
# File 'lib/liza/helper_units/test.rb', line 752 def log_test_call prefix, &block source_location = block.source_location.join(":").gsub("#{App.root}/", "") source_location = source_location[0..-1] log " #{prefix} #{source_location}" end |
#log_test_call_block? ⇒ Boolean
713 714 715 |
# File 'lib/liza/helper_units/test.rb', line 713 def log_test_call_block? LOG_CALL_BLOCK end |
#log_test_call_rescue(e) ⇒ Object
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 |
# File 'lib/liza/helper_units/test.rb', line 717 def log_test_call_rescue e prefix = stick :light_yellow, "error" kaller = e.backtrace source_location = _caller_line_split(kaller[0])[0] source_location = source_location.gsub("#{App.root}/", "") log " #{prefix} #{e.class.to_s.ljust 20} #{source_location}" puts stick :light_red, "Exception!" puts stick :light_red, e.class.to_s puts stick :light_red, e. puts puts stick :light_red, e.backtrace.join("\n") end |
#refute(b, msg = "it should have been false", kaller: nil) ⇒ Boolean
Asserts that a condition is false.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/liza/helper_units/test.rb', line 124 def refute b, msg = "it should have been false", kaller: nil if b self.class._assertion_failed msg @last_result = :failed else self.class._assertion_passed @last_result = :passed end kaller ||= caller log_test_assertion __method__, kaller if _groups.empty? b end |
#refute!(b, msg = "it should have been false") ⇒ Object
Performs a refutation and stops the test execution if it fails.
151 152 153 |
# File 'lib/liza/helper_units/test.rb', line 151 def refute! b, msg = "it should have been false" critical refute b, msg, kaller: caller end |
#refute_equality(a, b, msg = nil, kaller: nil) ⇒ Boolean
Asserts that a and b are not equal.
Passes if a != b, fails otherwise. Optionally takes a custom failure message.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/liza/helper_units/test.rb', line 208 def refute_equality a, b, msg = nil, kaller: nil ret = a == b if ret self.class._assertion_failed msg @last_result = :failed else self.class._assertion_passed @last_result = :passed end kaller ||= caller log_test_assertion __method__, kaller if _groups.empty? if msg ||= "#{__method__} #{a}, #{b} (== equality)" !ret, msg end ret end |
#refute_equality!(a, b, msg = nil) ⇒ void
This method returns an undefined value.
Asserts that a and b are not equal, stopping execution on failure.
Calls #refute_equality and halts if the assertion fails.
254 255 256 |
# File 'lib/liza/helper_units/test.rb', line 254 def refute_equality! a, b, msg = nil critical refute_equality a, b, msg, kaller: caller end |
#refute_gt(a, b, msg = nil, kaller: nil) ⇒ Boolean
Asserts that a is not greater than b.
Passes if a <= b, fails otherwise. Optionally takes a custom failure message.
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
# File 'lib/liza/helper_units/test.rb', line 522 def refute_gt a, b, msg = nil, kaller: nil raise "First argument is not Comparable (#{a.class})" unless a.is_a?(Comparable) raise "Second argument is not Comparable (#{b.class})" unless b.is_a?(Comparable) ret = a <= b if ret self.class._assertion_passed @last_result = :passed else self.class._assertion_failed msg @last_result = :failed end kaller ||= caller log_test_assertion __method__, kaller if _groups.empty? if msg ||= "#{__method__} #{a.inspect}, #{b.inspect} (<= not greater than)" ret, msg end ret end |
#refute_lt(a, b, msg = nil, kaller: nil) ⇒ Boolean
Asserts that a is not lesser than b.
Passes if a >= b, fails otherwise. Optionally takes a custom failure message.
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 |
# File 'lib/liza/helper_units/test.rb', line 590 def refute_lt a, b, msg = nil, kaller: nil raise "First argument is not Comparable (#{a.class})" unless a.is_a?(Comparable) raise "Second argument is not Comparable (#{b.class})" unless b.is_a?(Comparable) ret = a >= b if ret self.class._assertion_passed @last_result = :passed else self.class._assertion_failed msg @last_result = :failed end kaller ||= caller log_test_assertion __method__, kaller if _groups.empty? if msg ||= "#{__method__} #{a.inspect}, #{b.inspect} (>= not lesser than)" ret, msg end ret end |
#refute_no_raise(msg = nil, kaller: nil) { ... } ⇒ Boolean
Refutes that no exception is raised when executing the given block.
Fails if the block executes without raising an exception.
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 |
# File 'lib/liza/helper_units/test.rb', line 433 def refute_no_raise(msg = nil, kaller: nil, &block) raise ArgumentError, "No block given" unless block_given? ret = false begin yield ret = true rescue Exception ret = false end if ret self.class._assertion_failed msg @last_result = :failed else self.class._assertion_passed @last_result = :passed end kaller ||= caller log_test_assertion __method__, kaller if _groups.empty? if msg ||= "#{__method__} - Expected an exception to be raised, but none occurred" if ret !ret, msg end ret end |
#refute_no_raise!(msg = nil) { ... } ⇒ void
This method returns an undefined value.
Refutes that no exception is raised when executing the given block, stopping execution on success.
Calls #refute_no_raise and halts if no exception is raised.
472 473 474 |
# File 'lib/liza/helper_units/test.rb', line 472 def refute_no_raise!(msg = nil, &block) critical refute_no_raise(msg, kaller: caller, &block) end |
#refute_raises(exception_klass, msg = nil, kaller: nil) { ... } ⇒ Boolean
Asserts that the given block does not raise an exception of the specified class.
Passes if no exception or an unrelated exception is raised.
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/liza/helper_units/test.rb', line 312 def refute_raises exception_klass, msg = nil, kaller: nil, &block raise ArgumentError, "No block given" unless block_given? ret = false begin yield rescue => e ret = !exception_klass === e error = e end if ret self.class._assertion_failed msg @last_result = :failed else self.class._assertion_passed @last_result = :passed end kaller ||= caller log_test_assertion __method__, kaller if _groups.empty? if msg ||= "#{__method__} (#{exception_klass}) #{error.inspect}" !ret, msg end ret end |
#refute_raises!(e, msg = nil) ⇒ void
This method returns an undefined value.
Asserts that the given block does not raise an exception, stopping execution on failure.
Calls #refute_raises and halts if the assertion fails.
364 365 366 |
# File 'lib/liza/helper_units/test.rb', line 364 def refute_raises! e, msg = nil critical refute_raises e, msg, kaller: caller end |
#subject ⇒ Object
828 829 830 |
# File 'lib/liza/helper_units/test.rb', line 828 def subject @subject ||= subject_class.new end |
#subject_class ⇒ Object
824 825 826 |
# File 'lib/liza/helper_units/test.rb', line 824 def subject_class self.class.subject_class end |
#system ⇒ Object
838 839 840 |
# File 'lib/liza/helper_units/test.rb', line 838 def system self.class.system end |
#todo(msg) ⇒ Object
Marks a test as a "to-do" with an associated message.
65 66 67 68 69 70 |
# File 'lib/liza/helper_units/test.rb', line 65 def todo msg self.class._assertion_todo msg @last_result = :todo log_test_assertion __method__, caller if _groups.empty? end |