assert 2.18.0 → 2.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +66 -37
- data/assert.gemspec +4 -3
- data/lib/assert/actual_value.rb +140 -0
- data/lib/assert/assertions.rb +80 -20
- data/lib/assert/context.rb +31 -37
- data/lib/assert/context/let_dsl.rb +13 -0
- data/lib/assert/context/method_missing.rb +19 -0
- data/lib/assert/context/subject_dsl.rb +23 -24
- data/lib/assert/macros/methods.rb +4 -4
- data/lib/assert/result.rb +5 -1
- data/lib/assert/stub.rb +16 -0
- data/lib/assert/suite.rb +7 -10
- data/lib/assert/test.rb +0 -8
- data/lib/assert/version.rb +1 -1
- data/test/helper.rb +23 -25
- data/test/support/factory.rb +15 -0
- data/test/system/stub_tests.rb +332 -333
- data/test/system/test_tests.rb +99 -109
- data/test/unit/actual_value_tests.rb +371 -0
- data/test/unit/assert_tests.rb +111 -43
- data/test/unit/assertions/assert_block_tests.rb +30 -31
- data/test/unit/assertions/assert_changes_tests.rb +97 -0
- data/test/unit/assertions/assert_empty_tests.rb +33 -32
- data/test/unit/assertions/assert_equal_tests.rb +94 -74
- data/test/unit/assertions/assert_file_exists_tests.rb +32 -33
- data/test/unit/assertions/assert_includes_tests.rb +38 -37
- data/test/unit/assertions/assert_instance_of_tests.rb +34 -33
- data/test/unit/assertions/assert_kind_of_tests.rb +34 -33
- data/test/unit/assertions/assert_match_tests.rb +34 -33
- data/test/unit/assertions/assert_nil_tests.rb +30 -31
- data/test/unit/assertions/assert_raises_tests.rb +55 -55
- data/test/unit/assertions/assert_respond_to_tests.rb +36 -35
- data/test/unit/assertions/assert_same_tests.rb +86 -81
- data/test/unit/assertions/assert_true_false_tests.rb +60 -60
- data/test/unit/assertions_tests.rb +26 -24
- data/test/unit/config_helpers_tests.rb +43 -38
- data/test/unit/config_tests.rb +38 -34
- data/test/unit/context/let_dsl_tests.rb +10 -0
- data/test/unit/context/setup_dsl_tests.rb +70 -81
- data/test/unit/context/subject_dsl_tests.rb +15 -43
- data/test/unit/context/suite_dsl_tests.rb +15 -16
- data/test/unit/context/test_dsl_tests.rb +50 -52
- data/test/unit/context_info_tests.rb +23 -15
- data/test/unit/context_tests.rb +184 -179
- data/test/unit/default_runner_tests.rb +2 -5
- data/test/unit/default_suite_tests.rb +57 -53
- data/test/unit/factory_tests.rb +5 -3
- data/test/unit/file_line_tests.rb +33 -35
- data/test/unit/macro_tests.rb +14 -10
- data/test/unit/result_tests.rb +159 -183
- data/test/unit/runner_tests.rb +64 -64
- data/test/unit/suite_tests.rb +56 -59
- data/test/unit/test_tests.rb +118 -139
- data/test/unit/utils_tests.rb +43 -45
- data/test/unit/view_helpers_tests.rb +54 -52
- data/test/unit/view_tests.rb +22 -23
- metadata +29 -7
    
        data/test/unit/assert_tests.rb
    CHANGED
    
    | @@ -7,19 +7,21 @@ require "much-stub" | |
| 7 7 | 
             
            module Assert
         | 
| 8 8 | 
             
              class UnitTests < Assert::Context
         | 
| 9 9 | 
             
                desc "Assert"
         | 
| 10 | 
            -
                subject {  | 
| 10 | 
            +
                subject { unit_class }
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                let(:unit_class) { Assert }
         | 
| 11 13 |  | 
| 12 14 | 
             
                should have_imeths :config, :configure, :view, :suite, :runner
         | 
| 13 15 | 
             
                should have_imeths :stubs, :stub, :unstub, :unstub!, :stub_send
         | 
| 14 16 |  | 
| 15 17 | 
             
                should "know its config instance" do
         | 
| 16 | 
            -
                   | 
| 18 | 
            +
                  assert_that(subject.config).is_kind_of(Assert::Config)
         | 
| 17 19 | 
             
                end
         | 
| 18 20 |  | 
| 19 21 | 
             
                should "map its view, suite and runner to its config" do
         | 
| 20 | 
            -
                   | 
| 21 | 
            -
                   | 
| 22 | 
            -
                   | 
| 22 | 
            +
                  assert_that(subject.view).is(subject.config.view)
         | 
| 23 | 
            +
                  assert_that(subject.suite).is(subject.config.suite)
         | 
| 24 | 
            +
                  assert_that(subject.runner).is(subject.config.runner)
         | 
| 23 25 | 
             
                end
         | 
| 24 26 |  | 
| 25 27 | 
             
                # Note: don't really need to explicitly test the configure method as
         | 
| @@ -27,57 +29,68 @@ module Assert | |
| 27 29 | 
             
              end
         | 
| 28 30 |  | 
| 29 31 | 
             
              class StubTests < UnitTests
         | 
| 30 | 
            -
                 | 
| 31 | 
            -
                   | 
| 32 | 
            -
                  @stub_value = Factory.string
         | 
| 33 | 
            -
             | 
| 34 | 
            -
                  @myclass = Class.new do
         | 
| 32 | 
            +
                let(:class1) {
         | 
| 33 | 
            +
                  Class.new do
         | 
| 35 34 | 
             
                    def initialize(value); @value = value; end
         | 
| 36 35 | 
             
                    def mymeth; @value; end
         | 
| 37 36 | 
             
                  end
         | 
| 38 | 
            -
             | 
| 39 | 
            -
                 | 
| 37 | 
            +
                }
         | 
| 38 | 
            +
                let(:object1) { class1.new(orig_value1) }
         | 
| 39 | 
            +
                let(:orig_value1) { Factory.string }
         | 
| 40 | 
            +
                let(:stub_value1) { Factory.string }
         | 
| 40 41 |  | 
| 41 42 | 
             
                should "build a stub" do
         | 
| 42 | 
            -
                  stub1 = Assert.stub( | 
| 43 | 
            +
                  stub1 = Assert.stub(object1, :mymeth)
         | 
| 44 | 
            +
                  assert_that(stub1).is_kind_of(MuchStub::Stub)
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                should "build a stub with an on_call block" do
         | 
| 48 | 
            +
                  my_meth_called_with = nil
         | 
| 49 | 
            +
                  stub1 =
         | 
| 50 | 
            +
                    Assert.stub_on_call(object1, :mymeth) { |call|
         | 
| 51 | 
            +
                      my_meth_called_with = call
         | 
| 52 | 
            +
                    }
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                  object1.mymeth
         | 
| 43 55 | 
             
                  assert_kind_of MuchStub::Stub, stub1
         | 
| 56 | 
            +
                  assert_equal [], my_meth_called_with.args
         | 
| 44 57 | 
             
                end
         | 
| 45 58 |  | 
| 46 59 | 
             
                should "lookup stubs that have been called before" do
         | 
| 47 | 
            -
                  stub1 = Assert.stub( | 
| 48 | 
            -
                  stub2 = Assert.stub( | 
| 49 | 
            -
                   | 
| 60 | 
            +
                  stub1 = Assert.stub(object1, :mymeth)
         | 
| 61 | 
            +
                  stub2 = Assert.stub(object1, :mymeth)
         | 
| 62 | 
            +
                  assert_that(stub2).is(stub1)
         | 
| 50 63 | 
             
                end
         | 
| 51 64 |  | 
| 52 65 | 
             
                should "set the stub's do block if given a block" do
         | 
| 53 | 
            -
                  Assert.stub( | 
| 54 | 
            -
                   | 
| 55 | 
            -
                  Assert.stub( | 
| 56 | 
            -
                   | 
| 66 | 
            +
                  Assert.stub(object1, :mymeth)
         | 
| 67 | 
            +
                  assert_that { object1.mymeth }.raises(MuchStub::NotStubbedError)
         | 
| 68 | 
            +
                  Assert.stub(object1, :mymeth){ stub_value1 }
         | 
| 69 | 
            +
                  assert_that(object1.mymeth).equals(stub_value1)
         | 
| 57 70 | 
             
                end
         | 
| 58 71 |  | 
| 59 72 | 
             
                should "teardown stubs" do
         | 
| 60 | 
            -
                   | 
| 61 | 
            -
                  Assert.unstub( | 
| 62 | 
            -
                   | 
| 63 | 
            -
             | 
| 64 | 
            -
                   | 
| 65 | 
            -
                  Assert.stub( | 
| 66 | 
            -
                   | 
| 67 | 
            -
                  Assert.unstub( | 
| 68 | 
            -
                   | 
| 73 | 
            +
                  assert_that(object1.mymeth).equals(orig_value1)
         | 
| 74 | 
            +
                  Assert.unstub(object1, :mymeth)
         | 
| 75 | 
            +
                  assert_that(object1.mymeth).equals(orig_value1)
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                  assert_that(object1.mymeth).equals(orig_value1)
         | 
| 78 | 
            +
                  Assert.stub(object1, :mymeth){ stub_value1 }
         | 
| 79 | 
            +
                  assert_that(object1.mymeth).equals(stub_value1)
         | 
| 80 | 
            +
                  Assert.unstub(object1, :mymeth)
         | 
| 81 | 
            +
                  assert_that(object1.mymeth).equals(orig_value1)
         | 
| 69 82 | 
             
                end
         | 
| 70 83 |  | 
| 71 84 | 
             
                should "know and teardown all stubs" do
         | 
| 72 | 
            -
                   | 
| 85 | 
            +
                  assert_that(object1.mymeth).equals(orig_value1)
         | 
| 73 86 |  | 
| 74 | 
            -
                  Assert.stub( | 
| 75 | 
            -
                   | 
| 76 | 
            -
                   | 
| 87 | 
            +
                  Assert.stub(object1, :mymeth){ stub_value1 }
         | 
| 88 | 
            +
                  assert_that(object1.mymeth).equals(stub_value1)
         | 
| 89 | 
            +
                  assert_that(Assert.stubs.size).equals(1)
         | 
| 77 90 |  | 
| 78 91 | 
             
                  Assert.unstub!
         | 
| 79 | 
            -
                   | 
| 80 | 
            -
                   | 
| 92 | 
            +
                  assert_that(object1.mymeth).equals(orig_value1)
         | 
| 93 | 
            +
                  assert_that(Assert.stubs).is_empty
         | 
| 81 94 | 
             
                end
         | 
| 82 95 |  | 
| 83 96 | 
             
                should "auto-unstub any stubs on teardown" do
         | 
| @@ -88,21 +101,76 @@ module Assert | |
| 88 101 | 
             
                  end
         | 
| 89 102 |  | 
| 90 103 | 
             
                  context_class.run_setups("scope")
         | 
| 91 | 
            -
                   | 
| 104 | 
            +
                  assert_that(Assert.stubs.size).equals(1)
         | 
| 92 105 |  | 
| 93 106 | 
             
                  context_class.run_teardowns("scope")
         | 
| 94 | 
            -
                   | 
| 107 | 
            +
                  assert_that(Assert.stubs).is_empty
         | 
| 95 108 | 
             
                end
         | 
| 96 109 |  | 
| 97 110 | 
             
                should "be able to call a stub's original method" do
         | 
| 98 | 
            -
                  err = | 
| 99 | 
            -
             | 
| 100 | 
            -
             | 
| 111 | 
            +
                  err =
         | 
| 112 | 
            +
                    assert_that {
         | 
| 113 | 
            +
                      Assert.stub_send(object1, :mymeth)
         | 
| 114 | 
            +
                    }.raises(MuchStub::NotStubbedError)
         | 
| 115 | 
            +
                  assert_that(err.message).includes("not stubbed.")
         | 
| 116 | 
            +
                  assert_that(err.backtrace.first).includes("test/unit/assert_tests.rb")
         | 
| 101 117 |  | 
| 102 | 
            -
                  Assert.stub( | 
| 118 | 
            +
                  Assert.stub(object1, :mymeth){ stub_value1 }
         | 
| 119 | 
            +
             | 
| 120 | 
            +
                  assert_that(object1.mymeth).equals(stub_value1)
         | 
| 121 | 
            +
                  assert_that(Assert.stub_send(object1, :mymeth)).equals(orig_value1)
         | 
| 122 | 
            +
                end
         | 
| 103 123 |  | 
| 104 | 
            -
             | 
| 105 | 
            -
                   | 
| 124 | 
            +
                should "be able to add a stub tap" do
         | 
| 125 | 
            +
                  my_meth_called_with = nil
         | 
| 126 | 
            +
                  Assert.stub_tap(object1, :mymeth){ |value, *args, &block|
         | 
| 127 | 
            +
                    my_meth_called_with = args
         | 
| 128 | 
            +
                  }
         | 
| 129 | 
            +
             | 
| 130 | 
            +
                  assert_that(object1.mymeth).equals(orig_value1)
         | 
| 131 | 
            +
                  assert_that(my_meth_called_with).equals([])
         | 
| 132 | 
            +
                end
         | 
| 133 | 
            +
             | 
| 134 | 
            +
                should "be able to add a stub tap with an on_call block" do
         | 
| 135 | 
            +
                  my_meth_called_with = nil
         | 
| 136 | 
            +
                  Assert.stub_tap_on_call(object1, :mymeth){ |value, call|
         | 
| 137 | 
            +
                    my_meth_called_with = call
         | 
| 138 | 
            +
                  }
         | 
| 139 | 
            +
             | 
| 140 | 
            +
                  assert_that(object1.mymeth).equals(orig_value1)
         | 
| 141 | 
            +
                  assert_that(my_meth_called_with.args).equals([])
         | 
| 142 | 
            +
                end
         | 
| 143 | 
            +
             | 
| 144 | 
            +
                should "be able to add a stubbed spy" do
         | 
| 145 | 
            +
                  myclass = Class.new do
         | 
| 146 | 
            +
                    def one; self; end
         | 
| 147 | 
            +
                    def two(val); self; end
         | 
| 148 | 
            +
                    def three; self; end
         | 
| 149 | 
            +
                    def ready?; false; end
         | 
| 150 | 
            +
                  end
         | 
| 151 | 
            +
                  myobj = myclass.new
         | 
| 152 | 
            +
             | 
| 153 | 
            +
                  spy =
         | 
| 154 | 
            +
                    Assert.stub_spy(
         | 
| 155 | 
            +
                      myobj,
         | 
| 156 | 
            +
                      :one,
         | 
| 157 | 
            +
                      :two,
         | 
| 158 | 
            +
                      :three,
         | 
| 159 | 
            +
                      ready?: true)
         | 
| 160 | 
            +
             | 
| 161 | 
            +
                  assert_that(myobj.one).equals(spy)
         | 
| 162 | 
            +
                  assert_that(myobj.two("a")).equals(spy)
         | 
| 163 | 
            +
                  assert_that(myobj.three).equals(spy)
         | 
| 164 | 
            +
             | 
| 165 | 
            +
                  assert_that(myobj.one.two("b").three.ready?).is_true
         | 
| 166 | 
            +
             | 
| 167 | 
            +
                  assert_that(spy).is_kind_of(MuchStub::CallSpy)
         | 
| 168 | 
            +
                  assert_that(spy.one_call_count).equals(2)
         | 
| 169 | 
            +
                  assert_that(spy.two_call_count).equals(2)
         | 
| 170 | 
            +
                  assert_that(spy.three_call_count).equals(2)
         | 
| 171 | 
            +
                  assert_that(spy.ready_predicate_call_count).equals(1)
         | 
| 172 | 
            +
                  assert_that(spy.two_last_called_with.args).equals(["b"])
         | 
| 173 | 
            +
                  assert_that(spy.ready_predicate_called?).is_true
         | 
| 106 174 | 
             
                end
         | 
| 107 175 | 
             
              end
         | 
| 108 176 | 
             
            end
         | 
| @@ -6,25 +6,25 @@ module Assert::Assertions | |
| 6 6 | 
             
                include Assert::Test::TestHelpers
         | 
| 7 7 |  | 
| 8 8 | 
             
                desc "`assert_block`"
         | 
| 9 | 
            -
                 | 
| 10 | 
            -
                  desc =  | 
| 11 | 
            -
                   | 
| 12 | 
            -
                    assert_block{ true }        # pass
         | 
| 13 | 
            -
                    assert_block(desc){ false } # fail
         | 
| 9 | 
            +
                subject {
         | 
| 10 | 
            +
                  desc = desc1
         | 
| 11 | 
            +
                  Factory.test do
         | 
| 12 | 
            +
                    assert_block { true }        # pass
         | 
| 13 | 
            +
                    assert_block(desc) { false } # fail
         | 
| 14 14 | 
             
                  end
         | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
                 | 
| 15 | 
            +
                }
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                let(:desc1) { "assert block fail desc" }
         | 
| 18 18 |  | 
| 19 19 | 
             
                should "produce results as expected" do
         | 
| 20 | 
            -
                   | 
| 21 | 
            -
                  assert_equal 1, test_run_result_count(:pass)
         | 
| 22 | 
            -
                  assert_equal 1, test_run_result_count(:fail)
         | 
| 23 | 
            -
                end
         | 
| 20 | 
            +
                  subject.run(&test_run_callback)
         | 
| 24 21 |  | 
| 25 | 
            -
             | 
| 26 | 
            -
                   | 
| 27 | 
            -
                   | 
| 22 | 
            +
                  assert_that(test_run_result_count).equals(2)
         | 
| 23 | 
            +
                  assert_that(test_run_result_count(:pass)).equals(1)
         | 
| 24 | 
            +
                  assert_that(test_run_result_count(:fail)).equals(1)
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  exp = "#{desc1}\nExpected block to return a true value."
         | 
| 27 | 
            +
                  assert_that(test_run_results(:fail).first.message).equals(exp)
         | 
| 28 28 | 
             
                end
         | 
| 29 29 | 
             
              end
         | 
| 30 30 |  | 
| @@ -32,26 +32,25 @@ module Assert::Assertions | |
| 32 32 | 
             
                include Assert::Test::TestHelpers
         | 
| 33 33 |  | 
| 34 34 | 
             
                desc "`assert_not_block`"
         | 
| 35 | 
            -
                 | 
| 36 | 
            -
                  desc =  | 
| 37 | 
            -
                   | 
| 38 | 
            -
                    assert_not_block(desc){ true } # fail
         | 
| 39 | 
            -
                    assert_not_block{ false }      # pass
         | 
| 35 | 
            +
                subject {
         | 
| 36 | 
            +
                  desc = desc1
         | 
| 37 | 
            +
                  Factory.test do
         | 
| 38 | 
            +
                    assert_not_block(desc) { true } # fail
         | 
| 39 | 
            +
                    assert_not_block { false }      # pass
         | 
| 40 40 | 
             
                  end
         | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
                 | 
| 41 | 
            +
                }
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                let(:desc1) { "assert not block fail desc" }
         | 
| 44 44 |  | 
| 45 45 | 
             
                should "produce results as expected" do
         | 
| 46 | 
            -
                   | 
| 47 | 
            -
                  assert_equal 1, test_run_result_count(:pass)
         | 
| 48 | 
            -
                  assert_equal 1, test_run_result_count(:fail)
         | 
| 49 | 
            -
                end
         | 
| 46 | 
            +
                  subject.run(&test_run_callback)
         | 
| 50 47 |  | 
| 51 | 
            -
             | 
| 52 | 
            -
                   | 
| 53 | 
            -
                   | 
| 48 | 
            +
                  assert_that(test_run_result_count).equals(2)
         | 
| 49 | 
            +
                  assert_that(test_run_result_count(:pass)).equals(1)
         | 
| 50 | 
            +
                  assert_that(test_run_result_count(:fail)).equals(1)
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                  exp = "#{desc1}\nExpected block to not return a true value."
         | 
| 53 | 
            +
                  assert_that(test_run_results(:fail).first.message).equals(exp)
         | 
| 54 54 | 
             
                end
         | 
| 55 55 | 
             
              end
         | 
| 56 56 | 
             
            end
         | 
| 57 | 
            -
             | 
| @@ -0,0 +1,97 @@ | |
| 1 | 
            +
            require "assert"
         | 
| 2 | 
            +
            require "assert/assertions"
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module Assert::Assertions
         | 
| 5 | 
            +
              class AssertChangesTests < Assert::Context
         | 
| 6 | 
            +
                include Assert::Test::TestHelpers
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                desc "`assert_changes`"
         | 
| 9 | 
            +
                subject {
         | 
| 10 | 
            +
                  desc = desc1
         | 
| 11 | 
            +
                  Factory.test do
         | 
| 12 | 
            +
                    @my_var = 1
         | 
| 13 | 
            +
                    assert_changes("@my_var", from: 1, to: 2) { @my_var = 2 } # pass
         | 
| 14 | 
            +
                    @my_var = 1
         | 
| 15 | 
            +
                    assert_changes("@my_var", from: 1) { @my_var = 2 }        # pass
         | 
| 16 | 
            +
                    @my_var = 1
         | 
| 17 | 
            +
                    assert_changes("@my_var", to: 2) { @my_var = 2 }          # pass
         | 
| 18 | 
            +
                    @my_var = 1
         | 
| 19 | 
            +
                    assert_changes("@my_var", desc: desc) { @my_var = 2 }     # pass
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                    @my_var = 1
         | 
| 22 | 
            +
                    assert_changes("@my_var", from: 2, to: 1) { @my_var = 2 } # fail
         | 
| 23 | 
            +
                    @my_var = 1
         | 
| 24 | 
            +
                    assert_changes("@my_var", from: 2) { @my_var = 2 }        # fail
         | 
| 25 | 
            +
                    @my_var = 1
         | 
| 26 | 
            +
                    assert_changes("@my_var", to: 1) { @my_var = 2 }          # fail
         | 
| 27 | 
            +
                    @my_var = 1
         | 
| 28 | 
            +
                    assert_changes("@my_var", desc: desc) { @my_var = 1 }     # fail
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
                }
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                let(:desc1) { "assert changes fail desc" }
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                should "produce results as expected" do
         | 
| 35 | 
            +
                  subject.run(&test_run_callback)
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  assert_that(test_run_result_count).equals(10)
         | 
| 38 | 
            +
                  assert_that(test_run_result_count(:pass)).equals(5)
         | 
| 39 | 
            +
                  assert_that(test_run_result_count(:fail)).equals(5)
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  exp =
         | 
| 42 | 
            +
                    [
         | 
| 43 | 
            +
                      "Expected `@my_var` to change from `2`",
         | 
| 44 | 
            +
                      "Expected `@my_var` to change to `1`",
         | 
| 45 | 
            +
                      "Expected `@my_var` to change from `2`",
         | 
| 46 | 
            +
                      "Expected `@my_var` to change to `1`",
         | 
| 47 | 
            +
                      "#{desc1}\nExpected `@my_var` to change; "\
         | 
| 48 | 
            +
                      "it was `1` and didn't change",
         | 
| 49 | 
            +
                    ]
         | 
| 50 | 
            +
                  messages = test_run_results(:fail).map(&:message)
         | 
| 51 | 
            +
                  messages.each_with_index{ |msg, n| assert_that(msg).matches(/^#{exp[n]}/) }
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
              end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
              class AssertNotChangesTests < Assert::Context
         | 
| 56 | 
            +
                include Assert::Test::TestHelpers
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                desc "`assert_changes`"
         | 
| 59 | 
            +
                subject {
         | 
| 60 | 
            +
                  desc = desc1
         | 
| 61 | 
            +
                  Factory.test do
         | 
| 62 | 
            +
                    @my_var = 1
         | 
| 63 | 
            +
                    assert_not_changes("@my_var", from: 1) { @my_var = 1 }    # pass
         | 
| 64 | 
            +
                    @my_var = 1
         | 
| 65 | 
            +
                    assert_not_changes("@my_var", desc: desc) { @my_var = 1 } # pass
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                    @my_var = 1
         | 
| 68 | 
            +
                    assert_not_changes("@my_var", from: 2) { @my_var = 1 }    # fail
         | 
| 69 | 
            +
                    @my_var = 1
         | 
| 70 | 
            +
                    assert_not_changes("@my_var", from: 1) { @my_var = 2 }    # fail
         | 
| 71 | 
            +
                    @my_var = 1
         | 
| 72 | 
            +
                    assert_not_changes("@my_var", desc: desc) { @my_var = 2 } # fail
         | 
| 73 | 
            +
                  end
         | 
| 74 | 
            +
                }
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                let(:desc1) { "assert not changes fail desc" }
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                should "produce results as expected" do
         | 
| 79 | 
            +
                  subject.run(&test_run_callback)
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                  assert_that(test_run_result_count).equals(8)
         | 
| 82 | 
            +
                  assert_that(test_run_result_count(:pass)).equals(5)
         | 
| 83 | 
            +
                  assert_that(test_run_result_count(:fail)).equals(3)
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                  exp =
         | 
| 86 | 
            +
                    [
         | 
| 87 | 
            +
                      "Expected `@my_var` to not change from `2`",
         | 
| 88 | 
            +
                      "Expected `@my_var` to not change; "\
         | 
| 89 | 
            +
                      "it was `1` and changed to `2`",
         | 
| 90 | 
            +
                      "#{desc1}\nExpected `@my_var` to not change; "\
         | 
| 91 | 
            +
                      "it was `1` and changed to `2`",
         | 
| 92 | 
            +
                    ]
         | 
| 93 | 
            +
                  messages = test_run_results(:fail).map(&:message)
         | 
| 94 | 
            +
                  messages.each_with_index{ |msg, n| assert_that(msg).matches(/^#{exp[n]}/) }
         | 
| 95 | 
            +
                end
         | 
| 96 | 
            +
              end
         | 
| 97 | 
            +
            end
         | 
| @@ -8,56 +8,57 @@ module Assert::Assertions | |
| 8 8 | 
             
                include Assert::Test::TestHelpers
         | 
| 9 9 |  | 
| 10 10 | 
             
                desc "`assert_empty`"
         | 
| 11 | 
            -
                 | 
| 12 | 
            -
                   | 
| 13 | 
            -
                   | 
| 14 | 
            -
                  @test = Factory.test do
         | 
| 11 | 
            +
                subject {
         | 
| 12 | 
            +
                  args = args1
         | 
| 13 | 
            +
                  Factory.test do
         | 
| 15 14 | 
             
                    assert_empty([])    # pass
         | 
| 16 15 | 
             
                    assert_empty(*args) # fail
         | 
| 17 16 | 
             
                  end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
                 | 
| 21 | 
            -
                 | 
| 17 | 
            +
                }
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                let(:desc1) { "assert empty fail desc" }
         | 
| 20 | 
            +
                let(:args1) { [[1], desc1] }
         | 
| 21 | 
            +
                let(:config1) { subject.config }
         | 
| 22 22 |  | 
| 23 23 | 
             
                should "produce results as expected" do
         | 
| 24 | 
            -
                   | 
| 25 | 
            -
                  assert_equal 1, test_run_result_count(:pass)
         | 
| 26 | 
            -
                  assert_equal 1, test_run_result_count(:fail)
         | 
| 27 | 
            -
                end
         | 
| 24 | 
            +
                  subject.run(&test_run_callback)
         | 
| 28 25 |  | 
| 29 | 
            -
             | 
| 30 | 
            -
                   | 
| 31 | 
            -
                   | 
| 32 | 
            -
                end
         | 
| 26 | 
            +
                  assert_that(test_run_result_count).equals(2)
         | 
| 27 | 
            +
                  assert_that(test_run_result_count(:pass)).equals(1)
         | 
| 28 | 
            +
                  assert_that(test_run_result_count(:fail)).equals(1)
         | 
| 33 29 |  | 
| 30 | 
            +
                  exp =
         | 
| 31 | 
            +
                    "#{args1[1]}\nExpected #{Assert::U.show(args1[0], config1)} to be empty."
         | 
| 32 | 
            +
                  assert_that(test_run_results(:fail).first.message).equals(exp)
         | 
| 33 | 
            +
                end
         | 
| 34 34 | 
             
              end
         | 
| 35 35 |  | 
| 36 36 | 
             
              class AssertNotEmptyTests < Assert::Context
         | 
| 37 37 | 
             
                include Assert::Test::TestHelpers
         | 
| 38 38 |  | 
| 39 39 | 
             
                desc "`assert_not_empty`"
         | 
| 40 | 
            -
                 | 
| 41 | 
            -
                   | 
| 42 | 
            -
                   | 
| 43 | 
            -
             | 
| 44 | 
            -
                    assert_not_empty([1]) # pass
         | 
| 40 | 
            +
                subject {
         | 
| 41 | 
            +
                  args = args1
         | 
| 42 | 
            +
                  Factory.test do
         | 
| 43 | 
            +
                    assert_not_empty([1])   # pass
         | 
| 45 44 | 
             
                    assert_not_empty(*args) # fail
         | 
| 46 45 | 
             
                  end
         | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
                 | 
| 50 | 
            -
                 | 
| 46 | 
            +
                }
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                let(:desc1) { "assert not empty fail desc" }
         | 
| 49 | 
            +
                let(:args1) { [[], desc1] }
         | 
| 50 | 
            +
                let(:config1) { subject.config }
         | 
| 51 51 |  | 
| 52 52 | 
             
                should "produce results as expected" do
         | 
| 53 | 
            -
                   | 
| 54 | 
            -
             | 
| 55 | 
            -
                   | 
| 56 | 
            -
             | 
| 53 | 
            +
                  subject.run(&test_run_callback)
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                  assert_that(test_run_result_count).equals(2)
         | 
| 56 | 
            +
                  assert_that(test_run_result_count(:pass)).equals(1)
         | 
| 57 | 
            +
                  assert_that(test_run_result_count(:fail)).equals(1)
         | 
| 57 58 |  | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 60 | 
            -
                   | 
| 59 | 
            +
                  exp =
         | 
| 60 | 
            +
                    "#{args1[1]}\nExpected #{Assert::U.show(args1[0], config1)} to not be empty."
         | 
| 61 | 
            +
                  assert_that(test_run_results(:fail).first.message).equals(exp)
         | 
| 61 62 | 
             
                end
         | 
| 62 63 | 
             
              end
         | 
| 63 64 | 
             
            end
         |