minitest-mock_expectations 0.9.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 +7 -0
 - data/.gitignore +0 -0
 - data/.travis.yml +9 -0
 - data/Gemfile +3 -0
 - data/Gemfile.lock +22 -0
 - data/LICENSE.txt +21 -0
 - data/README.md +207 -0
 - data/Rakefile +10 -0
 - data/lib/minitest/mock_expectations.rb +7 -0
 - data/lib/minitest/mock_expectations/assertions.rb +185 -0
 - data/lib/minitest/mock_expectations/version.rb +5 -0
 - data/minitest-mock_expectations.gemspec +22 -0
 - data/test/minitest/mock_expectations/assertions_test.rb +201 -0
 - data/test/minitest/mock_expectations_test.rb +7 -0
 - data/test/test_helper.rb +4 -0
 - metadata +100 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA256:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: bea8d6f91af92ae5f55ffb36919b36e9509e6358832b0a52dde9bd5fcd65d7ff
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 1dce0a9264cc9c43aa074900b9a8be6dc5f816368c9cb4366a4c76f41328b953
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 0a3fa1196dd9a91d7924dad39649eabfab8f6ca189c38065dbbf90c0b14ed1e07a55159b92d3bef9ee4fa8f2809cf36c62a81356208616e318296a97988b1003
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 89a4de17e26c12f095c6fb5835f6142fc0ae8eb3e93153d299727de8fff5d68907a74ac74fe1841ef676d6bef9c1657d857b3d3b9cf28f518f1de2b7ea9f02c9
         
     | 
    
        data/.gitignore
    ADDED
    
    | 
         
            File without changes
         
     | 
    
        data/.travis.yml
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/Gemfile.lock
    ADDED
    
    | 
         @@ -0,0 +1,22 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            PATH
         
     | 
| 
      
 2 
     | 
    
         
            +
              remote: .
         
     | 
| 
      
 3 
     | 
    
         
            +
              specs:
         
     | 
| 
      
 4 
     | 
    
         
            +
                minitest-mock_expectations (0.9.0)
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            GEM
         
     | 
| 
      
 7 
     | 
    
         
            +
              remote: https://rubygems.org/
         
     | 
| 
      
 8 
     | 
    
         
            +
              specs:
         
     | 
| 
      
 9 
     | 
    
         
            +
                minitest (5.11.3)
         
     | 
| 
      
 10 
     | 
    
         
            +
                rake (10.5.0)
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            PLATFORMS
         
     | 
| 
      
 13 
     | 
    
         
            +
              ruby
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            DEPENDENCIES
         
     | 
| 
      
 16 
     | 
    
         
            +
              bundler (~> 1.16)
         
     | 
| 
      
 17 
     | 
    
         
            +
              minitest (~> 5.0)
         
     | 
| 
      
 18 
     | 
    
         
            +
              minitest-mock_expectations!
         
     | 
| 
      
 19 
     | 
    
         
            +
              rake (~> 10.0)
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            BUNDLED WITH
         
     | 
| 
      
 22 
     | 
    
         
            +
               1.16.2
         
     | 
    
        data/LICENSE.txt
    ADDED
    
    | 
         @@ -0,0 +1,21 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            The MIT License (MIT)
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            Copyright (c) 2018 bogdanvlviv
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            Permission is hereby granted, free of charge, to any person obtaining a copy
         
     | 
| 
      
 6 
     | 
    
         
            +
            of this software and associated documentation files (the "Software"), to deal
         
     | 
| 
      
 7 
     | 
    
         
            +
            in the Software without restriction, including without limitation the rights
         
     | 
| 
      
 8 
     | 
    
         
            +
            to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         
     | 
| 
      
 9 
     | 
    
         
            +
            copies of the Software, and to permit persons to whom the Software is
         
     | 
| 
      
 10 
     | 
    
         
            +
            furnished to do so, subject to the following conditions:
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            The above copyright notice and this permission notice shall be included in
         
     | 
| 
      
 13 
     | 
    
         
            +
            all copies or substantial portions of the Software.
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         
     | 
| 
      
 16 
     | 
    
         
            +
            IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         
     | 
| 
      
 17 
     | 
    
         
            +
            FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         
     | 
| 
      
 18 
     | 
    
         
            +
            AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         
     | 
| 
      
 19 
     | 
    
         
            +
            LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         
     | 
| 
      
 20 
     | 
    
         
            +
            OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
         
     | 
| 
      
 21 
     | 
    
         
            +
            THE SOFTWARE.
         
     | 
    
        data/README.md
    ADDED
    
    | 
         @@ -0,0 +1,207 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # minitest-mock_expectations
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            Provides method call assertions.
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            ## Installation
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            Add this line to your application's Gemfile:
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 10 
     | 
    
         
            +
            gem 'minitest-mock_expectations'
         
     | 
| 
      
 11 
     | 
    
         
            +
            ```
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            And then execute:
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            ```bash
         
     | 
| 
      
 16 
     | 
    
         
            +
            $ bundle
         
     | 
| 
      
 17 
     | 
    
         
            +
            ```
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            Or install it yourself as:
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            ```bash
         
     | 
| 
      
 22 
     | 
    
         
            +
            $ gem install minitest-mock_expectations
         
     | 
| 
      
 23 
     | 
    
         
            +
            ```
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            ## Usage
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 28 
     | 
    
         
            +
            require "minitest/mock_expectations"
         
     | 
| 
      
 29 
     | 
    
         
            +
            ```
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            Imagine we have model `Post`:
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 34 
     | 
    
         
            +
            class Post
         
     | 
| 
      
 35 
     | 
    
         
            +
              attr_accessor :title, :body
         
     | 
| 
      
 36 
     | 
    
         
            +
              attr_reader :comments
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
              def initialize(title: "", body: "", comments: [])
         
     | 
| 
      
 39 
     | 
    
         
            +
                @title = title
         
     | 
| 
      
 40 
     | 
    
         
            +
                @body = body
         
     | 
| 
      
 41 
     | 
    
         
            +
                @comments = comments
         
     | 
| 
      
 42 
     | 
    
         
            +
              end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
              def add_comment(comment)
         
     | 
| 
      
 45 
     | 
    
         
            +
                @comments << comment
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                "Thank you!"
         
     | 
| 
      
 48 
     | 
    
         
            +
              end
         
     | 
| 
      
 49 
     | 
    
         
            +
            end
         
     | 
| 
      
 50 
     | 
    
         
            +
            ```
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
            and variable `@post` that reffers to instance of `Post`:
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 55 
     | 
    
         
            +
            def setup
         
     | 
| 
      
 56 
     | 
    
         
            +
              @post = Post.new(
         
     | 
| 
      
 57 
     | 
    
         
            +
                title: "What is new in Rails 6.0",
         
     | 
| 
      
 58 
     | 
    
         
            +
                body: "https://bogdanvlviv.com/posts/ruby/rails/what-is-new-in-rails-6_0.html",
         
     | 
| 
      
 59 
     | 
    
         
            +
                comments: [
         
     | 
| 
      
 60 
     | 
    
         
            +
                  "Looking really good.",
         
     | 
| 
      
 61 
     | 
    
         
            +
                  "I'm really like this post."
         
     | 
| 
      
 62 
     | 
    
         
            +
                ]
         
     | 
| 
      
 63 
     | 
    
         
            +
              )
         
     | 
| 
      
 64 
     | 
    
         
            +
            end
         
     | 
| 
      
 65 
     | 
    
         
            +
            ```
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
            ### assert_called
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
            Asserts that the method will be called once on the object in the block:
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 72 
     | 
    
         
            +
            assert_called @post, :title do
         
     | 
| 
      
 73 
     | 
    
         
            +
              @post.title
         
     | 
| 
      
 74 
     | 
    
         
            +
            end
         
     | 
| 
      
 75 
     | 
    
         
            +
            ```
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
            In order to assert that the method will be called multiple times on the object in the block set `:times` option:
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 80 
     | 
    
         
            +
            assert_called(@post, :title, times: 2) do
         
     | 
| 
      
 81 
     | 
    
         
            +
              @post.title
         
     | 
| 
      
 82 
     | 
    
         
            +
              @post.title
         
     | 
| 
      
 83 
     | 
    
         
            +
            end
         
     | 
| 
      
 84 
     | 
    
         
            +
            ```
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
            You can stub the return value of the method in the block via `:returns` option:
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 89 
     | 
    
         
            +
            assert_called(@post, :title, returns: "What is new in Rails 5.2") do
         
     | 
| 
      
 90 
     | 
    
         
            +
              assert_equal "What is new in Rails 5.2", @object.title
         
     | 
| 
      
 91 
     | 
    
         
            +
            end
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
            assert_equal "What is new in Rails 6.0", @object.title
         
     | 
| 
      
 94 
     | 
    
         
            +
            ```
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
            ### assert_not_called
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
            Asserts that the method will not be called on the object in the block:
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 101 
     | 
    
         
            +
            assert_not_called(@post, :title) do
         
     | 
| 
      
 102 
     | 
    
         
            +
              @post.body
         
     | 
| 
      
 103 
     | 
    
         
            +
            end
         
     | 
| 
      
 104 
     | 
    
         
            +
            ```
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
            ### assert_called_with
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
            Asserts that the method will be called with the arguments once on the object in the block:
         
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
      
 110 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 111 
     | 
    
         
            +
            assert_called_with(@post, :add_comment, ["Thanks for sharing this."]) do
         
     | 
| 
      
 112 
     | 
    
         
            +
              @post.add_comment("Thanks for sharing this.")
         
     | 
| 
      
 113 
     | 
    
         
            +
            end
         
     | 
| 
      
 114 
     | 
    
         
            +
            ```
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
            You can stub the return value of the method in the block via `:returns` option:
         
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
      
 118 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 119 
     | 
    
         
            +
            assert_called_with(@post, :add_comment, ["Thanks for sharing this."], returns: "Thanks!") do
         
     | 
| 
      
 120 
     | 
    
         
            +
              assert_equal "Thanks!", @post.add_comment("Thanks for sharing this.")
         
     | 
| 
      
 121 
     | 
    
         
            +
            end
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
      
 123 
     | 
    
         
            +
            assert_equal "Thank you!", @post.add_comment("Thanks for sharing this.")
         
     | 
| 
      
 124 
     | 
    
         
            +
            ```
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
            You can also assert that the method will be called with different arguments once on the object in the block:
         
     | 
| 
      
 127 
     | 
    
         
            +
             
     | 
| 
      
 128 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 129 
     | 
    
         
            +
            assert_called_with(@post, :add_comment, [["Thanks for sharing this."], ["Thanks!"]]) do
         
     | 
| 
      
 130 
     | 
    
         
            +
              @post.add_comment("Thanks for sharing this.")
         
     | 
| 
      
 131 
     | 
    
         
            +
              @post.add_comment("Thanks!")
         
     | 
| 
      
 132 
     | 
    
         
            +
            end
         
     | 
| 
      
 133 
     | 
    
         
            +
            ```
         
     | 
| 
      
 134 
     | 
    
         
            +
             
     | 
| 
      
 135 
     | 
    
         
            +
            ### assert_called_on_instance_of
         
     | 
| 
      
 136 
     | 
    
         
            +
             
     | 
| 
      
 137 
     | 
    
         
            +
            Asserts that the method will be called once on an instance of the klass in the block:
         
     | 
| 
      
 138 
     | 
    
         
            +
             
     | 
| 
      
 139 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 140 
     | 
    
         
            +
            assert_called_on_instance_of Post, :title do
         
     | 
| 
      
 141 
     | 
    
         
            +
              @post.title
         
     | 
| 
      
 142 
     | 
    
         
            +
            end
         
     | 
| 
      
 143 
     | 
    
         
            +
            ```
         
     | 
| 
      
 144 
     | 
    
         
            +
             
     | 
| 
      
 145 
     | 
    
         
            +
            In order to assert that the method will be called multiple times on an instance of the klass in the block set `:times` option:
         
     | 
| 
      
 146 
     | 
    
         
            +
             
     | 
| 
      
 147 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 148 
     | 
    
         
            +
            assert_called_on_instance_of(Post, :title, times: 2) do
         
     | 
| 
      
 149 
     | 
    
         
            +
              @post.title
         
     | 
| 
      
 150 
     | 
    
         
            +
              @post.title
         
     | 
| 
      
 151 
     | 
    
         
            +
            end
         
     | 
| 
      
 152 
     | 
    
         
            +
            ```
         
     | 
| 
      
 153 
     | 
    
         
            +
             
     | 
| 
      
 154 
     | 
    
         
            +
            You can stub the return value of the method in the block via `:returns` option:
         
     | 
| 
      
 155 
     | 
    
         
            +
             
     | 
| 
      
 156 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 157 
     | 
    
         
            +
            assert_called_on_instance_of(Post, :title, returns: "What is new in Rails 5.2") do
         
     | 
| 
      
 158 
     | 
    
         
            +
              assert_equal "What is new in Rails 5.2", @post.title
         
     | 
| 
      
 159 
     | 
    
         
            +
            end
         
     | 
| 
      
 160 
     | 
    
         
            +
             
     | 
| 
      
 161 
     | 
    
         
            +
            assert_equal "What is new in Rails 6.0", @post.title
         
     | 
| 
      
 162 
     | 
    
         
            +
            ```
         
     | 
| 
      
 163 
     | 
    
         
            +
             
     | 
| 
      
 164 
     | 
    
         
            +
            Use nesting of the blocks in order assert that the several methods will be called on an instance of the klass in the block:
         
     | 
| 
      
 165 
     | 
    
         
            +
             
     | 
| 
      
 166 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 167 
     | 
    
         
            +
            assert_called_on_instance_of(Post, :title, times: 3) do
         
     | 
| 
      
 168 
     | 
    
         
            +
              assert_called_on_instance_of(Post, :body, times: 2) do
         
     | 
| 
      
 169 
     | 
    
         
            +
                @post.title
         
     | 
| 
      
 170 
     | 
    
         
            +
                @post.body
         
     | 
| 
      
 171 
     | 
    
         
            +
                @post.title
         
     | 
| 
      
 172 
     | 
    
         
            +
                @post.body
         
     | 
| 
      
 173 
     | 
    
         
            +
                @post.title
         
     | 
| 
      
 174 
     | 
    
         
            +
              end
         
     | 
| 
      
 175 
     | 
    
         
            +
            end
         
     | 
| 
      
 176 
     | 
    
         
            +
            ```
         
     | 
| 
      
 177 
     | 
    
         
            +
             
     | 
| 
      
 178 
     | 
    
         
            +
            ### assert_not_called_on_instance_of
         
     | 
| 
      
 179 
     | 
    
         
            +
             
     | 
| 
      
 180 
     | 
    
         
            +
            Asserts that the method will not be called once on an instance of the klass in the block:
         
     | 
| 
      
 181 
     | 
    
         
            +
             
     | 
| 
      
 182 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 183 
     | 
    
         
            +
            assert_not_called(@post, :title) do
         
     | 
| 
      
 184 
     | 
    
         
            +
              @post.body
         
     | 
| 
      
 185 
     | 
    
         
            +
            end
         
     | 
| 
      
 186 
     | 
    
         
            +
            ```
         
     | 
| 
      
 187 
     | 
    
         
            +
             
     | 
| 
      
 188 
     | 
    
         
            +
            Use nesting of the blocks in order assert that the several methods will not be called on an instance of the klass in the block:
         
     | 
| 
      
 189 
     | 
    
         
            +
             
     | 
| 
      
 190 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 191 
     | 
    
         
            +
            assert_not_called_on_instance_of(Post, :title) do
         
     | 
| 
      
 192 
     | 
    
         
            +
              assert_not_called_on_instance_of(Post, :body) do
         
     | 
| 
      
 193 
     | 
    
         
            +
              end
         
     | 
| 
      
 194 
     | 
    
         
            +
            end
         
     | 
| 
      
 195 
     | 
    
         
            +
            ```
         
     | 
| 
      
 196 
     | 
    
         
            +
             
     | 
| 
      
 197 
     | 
    
         
            +
            ## Contributing
         
     | 
| 
      
 198 
     | 
    
         
            +
             
     | 
| 
      
 199 
     | 
    
         
            +
            Bug reports and pull requests are welcome on GitHub at https://github.com/bogdanvlviv/minitest-mock_expectations. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](https://contributor-covenant.org) code of conduct.
         
     | 
| 
      
 200 
     | 
    
         
            +
             
     | 
| 
      
 201 
     | 
    
         
            +
            ## Code Status
         
     | 
| 
      
 202 
     | 
    
         
            +
             
     | 
| 
      
 203 
     | 
    
         
            +
            [](https://travis-ci.org/bogdanvlviv/minitest-mock_expectations)
         
     | 
| 
      
 204 
     | 
    
         
            +
             
     | 
| 
      
 205 
     | 
    
         
            +
            ## License
         
     | 
| 
      
 206 
     | 
    
         
            +
             
     | 
| 
      
 207 
     | 
    
         
            +
            The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
         
     | 
    
        data/Rakefile
    ADDED
    
    
| 
         @@ -0,0 +1,185 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "minitest"
         
     | 
| 
      
 2 
     | 
    
         
            +
            require "minitest/assertions"
         
     | 
| 
      
 3 
     | 
    
         
            +
            require "minitest/mock"
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            module Minitest
         
     | 
| 
      
 6 
     | 
    
         
            +
              # Provides method call assertions
         
     | 
| 
      
 7 
     | 
    
         
            +
              #
         
     | 
| 
      
 8 
     | 
    
         
            +
              # Imagine we have model +Post+:
         
     | 
| 
      
 9 
     | 
    
         
            +
              #
         
     | 
| 
      
 10 
     | 
    
         
            +
              #   class Post
         
     | 
| 
      
 11 
     | 
    
         
            +
              #     attr_accessor :title, :body
         
     | 
| 
      
 12 
     | 
    
         
            +
              #     attr_reader :comments
         
     | 
| 
      
 13 
     | 
    
         
            +
              #
         
     | 
| 
      
 14 
     | 
    
         
            +
              #     def initialize(title: "", body: "", comments: [])
         
     | 
| 
      
 15 
     | 
    
         
            +
              #       @title = title
         
     | 
| 
      
 16 
     | 
    
         
            +
              #       @body = body
         
     | 
| 
      
 17 
     | 
    
         
            +
              #       @comments = comments
         
     | 
| 
      
 18 
     | 
    
         
            +
              #     end
         
     | 
| 
      
 19 
     | 
    
         
            +
              #
         
     | 
| 
      
 20 
     | 
    
         
            +
              #     def add_comment(comment)
         
     | 
| 
      
 21 
     | 
    
         
            +
              #       @comments << comment
         
     | 
| 
      
 22 
     | 
    
         
            +
              #
         
     | 
| 
      
 23 
     | 
    
         
            +
              #       "Thank you!"
         
     | 
| 
      
 24 
     | 
    
         
            +
              #     end
         
     | 
| 
      
 25 
     | 
    
         
            +
              #   end
         
     | 
| 
      
 26 
     | 
    
         
            +
              #
         
     | 
| 
      
 27 
     | 
    
         
            +
              # and variable +@post+ that reffers to instance of +Post+:
         
     | 
| 
      
 28 
     | 
    
         
            +
              #
         
     | 
| 
      
 29 
     | 
    
         
            +
              #   def setup
         
     | 
| 
      
 30 
     | 
    
         
            +
              #     @post = Post.new(
         
     | 
| 
      
 31 
     | 
    
         
            +
              #       title: "What is new in Rails 6.0",
         
     | 
| 
      
 32 
     | 
    
         
            +
              #       body: "https://bogdanvlviv.com/posts/ruby/rails/what-is-new-in-rails-6_0.html",
         
     | 
| 
      
 33 
     | 
    
         
            +
              #       comments: [
         
     | 
| 
      
 34 
     | 
    
         
            +
              #         "Looking really good.",
         
     | 
| 
      
 35 
     | 
    
         
            +
              #         "I'm really like this post."
         
     | 
| 
      
 36 
     | 
    
         
            +
              #       ]
         
     | 
| 
      
 37 
     | 
    
         
            +
              #     )
         
     | 
| 
      
 38 
     | 
    
         
            +
              #   end
         
     | 
| 
      
 39 
     | 
    
         
            +
              module Assertions
         
     | 
| 
      
 40 
     | 
    
         
            +
                # Asserts that the method will be called once on the object in the block:
         
     | 
| 
      
 41 
     | 
    
         
            +
                #
         
     | 
| 
      
 42 
     | 
    
         
            +
                #   assert_called @post, :title do
         
     | 
| 
      
 43 
     | 
    
         
            +
                #     @post.title
         
     | 
| 
      
 44 
     | 
    
         
            +
                #   end
         
     | 
| 
      
 45 
     | 
    
         
            +
                #
         
     | 
| 
      
 46 
     | 
    
         
            +
                # In order to assert that the method will be called multiple times on the object in the block set +:times+ option:
         
     | 
| 
      
 47 
     | 
    
         
            +
                #
         
     | 
| 
      
 48 
     | 
    
         
            +
                #   assert_called(@post, :title, times: 2) do
         
     | 
| 
      
 49 
     | 
    
         
            +
                #     @post.title
         
     | 
| 
      
 50 
     | 
    
         
            +
                #     @post.title
         
     | 
| 
      
 51 
     | 
    
         
            +
                #   end
         
     | 
| 
      
 52 
     | 
    
         
            +
                #
         
     | 
| 
      
 53 
     | 
    
         
            +
                # You can stub the return value of the method in the block via +:returns+ option:
         
     | 
| 
      
 54 
     | 
    
         
            +
                #
         
     | 
| 
      
 55 
     | 
    
         
            +
                #   assert_called(@post, :title, returns: "What is new in Rails 5.2") do
         
     | 
| 
      
 56 
     | 
    
         
            +
                #     assert_equal "What is new in Rails 5.2", @object.title
         
     | 
| 
      
 57 
     | 
    
         
            +
                #   end
         
     | 
| 
      
 58 
     | 
    
         
            +
                #
         
     | 
| 
      
 59 
     | 
    
         
            +
                #   assert_equal "What is new in Rails 6.0", @object.title
         
     | 
| 
      
 60 
     | 
    
         
            +
                def assert_called(object, method_name, message = nil, times: 1, returns: nil)
         
     | 
| 
      
 61 
     | 
    
         
            +
                  times_called = 0
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                  object.stub(method_name, proc { times_called += 1; returns }) { yield }
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                  error = "Expected #{method_name} to be called #{times} times, but was called #{times_called} times"
         
     | 
| 
      
 66 
     | 
    
         
            +
                  error = "#{message}.\n#{error}" if message
         
     | 
| 
      
 67 
     | 
    
         
            +
                  assert_equal times, times_called, error
         
     | 
| 
      
 68 
     | 
    
         
            +
                end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
                # Asserts that the method will not be called on the object in the block:
         
     | 
| 
      
 71 
     | 
    
         
            +
                #
         
     | 
| 
      
 72 
     | 
    
         
            +
                #   assert_not_called(@post, :title) do
         
     | 
| 
      
 73 
     | 
    
         
            +
                #     @post.body
         
     | 
| 
      
 74 
     | 
    
         
            +
                #   end
         
     | 
| 
      
 75 
     | 
    
         
            +
                def assert_not_called(object, method_name, message = nil, &block)
         
     | 
| 
      
 76 
     | 
    
         
            +
                  assert_called(object, method_name, message, times: 0, &block)
         
     | 
| 
      
 77 
     | 
    
         
            +
                end
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
                # Asserts that the method will be called with the arguments once on the object in the block:
         
     | 
| 
      
 80 
     | 
    
         
            +
                #
         
     | 
| 
      
 81 
     | 
    
         
            +
                #   assert_called_with(@post, :add_comment, ["Thanks for sharing this."]) do
         
     | 
| 
      
 82 
     | 
    
         
            +
                #     @post.add_comment("Thanks for sharing this.")
         
     | 
| 
      
 83 
     | 
    
         
            +
                #   end
         
     | 
| 
      
 84 
     | 
    
         
            +
                #
         
     | 
| 
      
 85 
     | 
    
         
            +
                # You can stub the return value of the method in the block via +:returns+ option:
         
     | 
| 
      
 86 
     | 
    
         
            +
                #
         
     | 
| 
      
 87 
     | 
    
         
            +
                #   assert_called_with(@post, :add_comment, ["Thanks for sharing this."], returns: "Thanks!") do
         
     | 
| 
      
 88 
     | 
    
         
            +
                #     assert_equal "Thanks!", @post.add_comment("Thanks for sharing this.")
         
     | 
| 
      
 89 
     | 
    
         
            +
                #   end
         
     | 
| 
      
 90 
     | 
    
         
            +
                #
         
     | 
| 
      
 91 
     | 
    
         
            +
                #   assert_equal "Thank you!", @post.add_comment("Thanks for sharing this.")
         
     | 
| 
      
 92 
     | 
    
         
            +
                #
         
     | 
| 
      
 93 
     | 
    
         
            +
                # You can also assert that the method will be called with different arguments once on the object in the block:
         
     | 
| 
      
 94 
     | 
    
         
            +
                #
         
     | 
| 
      
 95 
     | 
    
         
            +
                #   assert_called_with(@post, :add_comment, [["Thanks for sharing this."], ["Thanks!"]]) do
         
     | 
| 
      
 96 
     | 
    
         
            +
                #     @post.add_comment("Thanks for sharing this.")
         
     | 
| 
      
 97 
     | 
    
         
            +
                #     @post.add_comment("Thanks!")
         
     | 
| 
      
 98 
     | 
    
         
            +
                #   end
         
     | 
| 
      
 99 
     | 
    
         
            +
                def assert_called_with(object, method_name, args, returns: nil)
         
     | 
| 
      
 100 
     | 
    
         
            +
                  mock = Minitest::Mock.new
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
                  if args.all? { |arg| arg.is_a?(Array) }
         
     | 
| 
      
 103 
     | 
    
         
            +
                    args.each { |arg| mock.expect(:call, returns, arg) }
         
     | 
| 
      
 104 
     | 
    
         
            +
                  else
         
     | 
| 
      
 105 
     | 
    
         
            +
                    mock.expect(:call, returns, args)
         
     | 
| 
      
 106 
     | 
    
         
            +
                  end
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
                  object.stub(method_name, mock) { yield }
         
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
      
 110 
     | 
    
         
            +
                  mock.verify
         
     | 
| 
      
 111 
     | 
    
         
            +
                end
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
                # Asserts that the method will be called once on an instance of the klass in the block:
         
     | 
| 
      
 114 
     | 
    
         
            +
                #
         
     | 
| 
      
 115 
     | 
    
         
            +
                #   assert_called_on_instance_of Post, :title do
         
     | 
| 
      
 116 
     | 
    
         
            +
                #     @post.title
         
     | 
| 
      
 117 
     | 
    
         
            +
                #   end
         
     | 
| 
      
 118 
     | 
    
         
            +
                #
         
     | 
| 
      
 119 
     | 
    
         
            +
                # In order to assert that the method will be called multiple times on an instance of the klass in the block set +:times+ option:
         
     | 
| 
      
 120 
     | 
    
         
            +
                #
         
     | 
| 
      
 121 
     | 
    
         
            +
                #   assert_called_on_instance_of(Post, :title, times: 2) do
         
     | 
| 
      
 122 
     | 
    
         
            +
                #     @post.title
         
     | 
| 
      
 123 
     | 
    
         
            +
                #     @post.title
         
     | 
| 
      
 124 
     | 
    
         
            +
                #   end
         
     | 
| 
      
 125 
     | 
    
         
            +
                #
         
     | 
| 
      
 126 
     | 
    
         
            +
                # You can stub the return value of the method in the block via +:returns+ option:
         
     | 
| 
      
 127 
     | 
    
         
            +
                #
         
     | 
| 
      
 128 
     | 
    
         
            +
                #   assert_called_on_instance_of(Post, :title, returns: "What is new in Rails 5.2") do
         
     | 
| 
      
 129 
     | 
    
         
            +
                #     assert_equal "What is new in Rails 5.2", @post.title
         
     | 
| 
      
 130 
     | 
    
         
            +
                #   end
         
     | 
| 
      
 131 
     | 
    
         
            +
                #
         
     | 
| 
      
 132 
     | 
    
         
            +
                #   assert_equal "What is new in Rails 6.0", @post.title
         
     | 
| 
      
 133 
     | 
    
         
            +
                #
         
     | 
| 
      
 134 
     | 
    
         
            +
                # Use nesting of the blocks in order assert that the several methods will be called on an instance of the klass in the block:
         
     | 
| 
      
 135 
     | 
    
         
            +
                #
         
     | 
| 
      
 136 
     | 
    
         
            +
                #   assert_called_on_instance_of(Post, :title, times: 3) do
         
     | 
| 
      
 137 
     | 
    
         
            +
                #     assert_called_on_instance_of(Post, :body, times: 2) do
         
     | 
| 
      
 138 
     | 
    
         
            +
                #       @post.title
         
     | 
| 
      
 139 
     | 
    
         
            +
                #       @post.body
         
     | 
| 
      
 140 
     | 
    
         
            +
                #       @post.title
         
     | 
| 
      
 141 
     | 
    
         
            +
                #       @post.body
         
     | 
| 
      
 142 
     | 
    
         
            +
                #       @post.title
         
     | 
| 
      
 143 
     | 
    
         
            +
                #     end
         
     | 
| 
      
 144 
     | 
    
         
            +
                #   end
         
     | 
| 
      
 145 
     | 
    
         
            +
                def assert_called_on_instance_of(klass, method_name, message = nil, times: 1, returns: nil)
         
     | 
| 
      
 146 
     | 
    
         
            +
                  times_called = 0
         
     | 
| 
      
 147 
     | 
    
         
            +
             
     | 
| 
      
 148 
     | 
    
         
            +
                  klass.send(:define_method, "stubbed_#{method_name}") do |*|
         
     | 
| 
      
 149 
     | 
    
         
            +
                    times_called += 1
         
     | 
| 
      
 150 
     | 
    
         
            +
             
     | 
| 
      
 151 
     | 
    
         
            +
                    returns
         
     | 
| 
      
 152 
     | 
    
         
            +
                  end
         
     | 
| 
      
 153 
     | 
    
         
            +
             
     | 
| 
      
 154 
     | 
    
         
            +
                  klass.send(:alias_method, "original_#{method_name}", method_name)
         
     | 
| 
      
 155 
     | 
    
         
            +
                  klass.send(:alias_method, method_name, "stubbed_#{method_name}")
         
     | 
| 
      
 156 
     | 
    
         
            +
             
     | 
| 
      
 157 
     | 
    
         
            +
                  yield
         
     | 
| 
      
 158 
     | 
    
         
            +
             
     | 
| 
      
 159 
     | 
    
         
            +
                  error = "Expected #{method_name} to be called #{times} times, but was called #{times_called} times"
         
     | 
| 
      
 160 
     | 
    
         
            +
                  error = "#{message}.\n#{error}" if message
         
     | 
| 
      
 161 
     | 
    
         
            +
             
     | 
| 
      
 162 
     | 
    
         
            +
                  assert_equal times, times_called, error
         
     | 
| 
      
 163 
     | 
    
         
            +
                ensure
         
     | 
| 
      
 164 
     | 
    
         
            +
                  klass.send(:alias_method, method_name, "original_#{method_name}")
         
     | 
| 
      
 165 
     | 
    
         
            +
                  klass.send(:undef_method, "original_#{method_name}")
         
     | 
| 
      
 166 
     | 
    
         
            +
                  klass.send(:undef_method, "stubbed_#{method_name}")
         
     | 
| 
      
 167 
     | 
    
         
            +
                end
         
     | 
| 
      
 168 
     | 
    
         
            +
             
     | 
| 
      
 169 
     | 
    
         
            +
                # Asserts that the method will not be called once on an instance of the klass in the block:
         
     | 
| 
      
 170 
     | 
    
         
            +
                #
         
     | 
| 
      
 171 
     | 
    
         
            +
                #   assert_not_called(@post, :title) do
         
     | 
| 
      
 172 
     | 
    
         
            +
                #     @post.body
         
     | 
| 
      
 173 
     | 
    
         
            +
                #   end
         
     | 
| 
      
 174 
     | 
    
         
            +
                #
         
     | 
| 
      
 175 
     | 
    
         
            +
                # Use nesting of the blocks in order assert that the several methods will not be called on an instance of the klass in the block:
         
     | 
| 
      
 176 
     | 
    
         
            +
                #
         
     | 
| 
      
 177 
     | 
    
         
            +
                #   assert_not_called_on_instance_of(Post, :title) do
         
     | 
| 
      
 178 
     | 
    
         
            +
                #     assert_not_called_on_instance_of(Post, :body) do
         
     | 
| 
      
 179 
     | 
    
         
            +
                #     end
         
     | 
| 
      
 180 
     | 
    
         
            +
                #   end
         
     | 
| 
      
 181 
     | 
    
         
            +
                def assert_not_called_on_instance_of(klass, method_name, message = nil, &block)
         
     | 
| 
      
 182 
     | 
    
         
            +
                  assert_called_on_instance_of(klass, method_name, message, times: 0, &block)
         
     | 
| 
      
 183 
     | 
    
         
            +
                end
         
     | 
| 
      
 184 
     | 
    
         
            +
              end
         
     | 
| 
      
 185 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,22 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            lib = File.expand_path("lib", __dir__)
         
     | 
| 
      
 2 
     | 
    
         
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         
     | 
| 
      
 3 
     | 
    
         
            +
            require "minitest/mock_expectations/version"
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            Gem::Specification.new do |spec|
         
     | 
| 
      
 6 
     | 
    
         
            +
              spec.name          = "minitest-mock_expectations"
         
     | 
| 
      
 7 
     | 
    
         
            +
              spec.version       = Minitest::MockExpectations::VERSION
         
     | 
| 
      
 8 
     | 
    
         
            +
              spec.authors       = ["bogdanvlviv"]
         
     | 
| 
      
 9 
     | 
    
         
            +
              spec.email         = ["bogdanvlviv@gmail.com"]
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              spec.summary       = "Provides method call assertions"
         
     | 
| 
      
 12 
     | 
    
         
            +
              spec.description   = ""
         
     | 
| 
      
 13 
     | 
    
         
            +
              spec.homepage      = "https://github.com/bogdanvlviv/minitest-mock_expectations"
         
     | 
| 
      
 14 
     | 
    
         
            +
              spec.license       = "MIT"
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              spec.files         = `git ls-files -z`.split("\x0")
         
     | 
| 
      
 17 
     | 
    
         
            +
              spec.require_paths = ["lib"]
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              spec.add_development_dependency "bundler", "~> 1.16"
         
     | 
| 
      
 20 
     | 
    
         
            +
              spec.add_development_dependency "rake", "~> 10.0"
         
     | 
| 
      
 21 
     | 
    
         
            +
              spec.add_development_dependency "minitest", "~> 5.0"
         
     | 
| 
      
 22 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,201 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "test_helper"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class Minitest::MockExpectations::AssertionsTest < Minitest::Test
         
     | 
| 
      
 4 
     | 
    
         
            +
              class Post
         
     | 
| 
      
 5 
     | 
    
         
            +
                attr_accessor :title, :body
         
     | 
| 
      
 6 
     | 
    
         
            +
                attr_reader :comments
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                def initialize(title: "", body: "", comments: [])
         
     | 
| 
      
 9 
     | 
    
         
            +
                  @title = title
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @body = body
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @comments = comments
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                def add_comment(comment)
         
     | 
| 
      
 15 
     | 
    
         
            +
                  @comments << comment
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                  "Thank you!"
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 22 
     | 
    
         
            +
                @post = Post.new(
         
     | 
| 
      
 23 
     | 
    
         
            +
                  title: "What is new in Rails 6.0",
         
     | 
| 
      
 24 
     | 
    
         
            +
                  body: "https://bogdanvlviv.com/posts/ruby/rails/what-is-new-in-rails-6_0.html",
         
     | 
| 
      
 25 
     | 
    
         
            +
                  comments: [
         
     | 
| 
      
 26 
     | 
    
         
            +
                    "Looking really good.",
         
     | 
| 
      
 27 
     | 
    
         
            +
                    "I'm really like this post."
         
     | 
| 
      
 28 
     | 
    
         
            +
                  ]
         
     | 
| 
      
 29 
     | 
    
         
            +
                )
         
     | 
| 
      
 30 
     | 
    
         
            +
              end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
              def test_assert_called_with_defaults_to_expect_once
         
     | 
| 
      
 33 
     | 
    
         
            +
                assert_called @post, :title do
         
     | 
| 
      
 34 
     | 
    
         
            +
                  @post.title
         
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
              end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
              def test_assert_called_more_than_once
         
     | 
| 
      
 39 
     | 
    
         
            +
                assert_called(@post, :title, times: 2) do
         
     | 
| 
      
 40 
     | 
    
         
            +
                  @post.title
         
     | 
| 
      
 41 
     | 
    
         
            +
                  @post.title
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
              def test_assert_called_method_with_arguments
         
     | 
| 
      
 46 
     | 
    
         
            +
                assert_called(@post, :add_comment) do
         
     | 
| 
      
 47 
     | 
    
         
            +
                  @post.add_comment("Thanks for sharing this.")
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
              def test_assert_called_returns
         
     | 
| 
      
 52 
     | 
    
         
            +
                assert_called(@post, :title, returns: "What is new in Rails 5.2") do
         
     | 
| 
      
 53 
     | 
    
         
            +
                  assert_equal "What is new in Rails 5.2", @post.title
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                assert_equal "What is new in Rails 6.0", @post.title
         
     | 
| 
      
 57 
     | 
    
         
            +
              end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
              def test_assert_called_failure
         
     | 
| 
      
 60 
     | 
    
         
            +
                error = assert_raises(Minitest::Assertion) do
         
     | 
| 
      
 61 
     | 
    
         
            +
                  assert_called(@post, :title) do
         
     | 
| 
      
 62 
     | 
    
         
            +
                  end
         
     | 
| 
      
 63 
     | 
    
         
            +
                end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                assert_equal "Expected title to be called 1 times, but was called 0 times.\nExpected: 1\n  Actual: 0", error.message
         
     | 
| 
      
 66 
     | 
    
         
            +
              end
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
              def test_assert_not_called
         
     | 
| 
      
 69 
     | 
    
         
            +
                assert_not_called(@post, :title) do
         
     | 
| 
      
 70 
     | 
    
         
            +
                  @post.body
         
     | 
| 
      
 71 
     | 
    
         
            +
                end
         
     | 
| 
      
 72 
     | 
    
         
            +
              end
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
              def test_assert_not_called_failure
         
     | 
| 
      
 75 
     | 
    
         
            +
                error = assert_raises(Minitest::Assertion) do
         
     | 
| 
      
 76 
     | 
    
         
            +
                  assert_not_called(@post, :title) do
         
     | 
| 
      
 77 
     | 
    
         
            +
                    @post.title
         
     | 
| 
      
 78 
     | 
    
         
            +
                  end
         
     | 
| 
      
 79 
     | 
    
         
            +
                end
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                assert_equal "Expected title to be called 0 times, but was called 1 times.\nExpected: 0\n  Actual: 1", error.message
         
     | 
| 
      
 82 
     | 
    
         
            +
              end
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
              def test_assert_called_with_message
         
     | 
| 
      
 85 
     | 
    
         
            +
                error = assert_raises(Minitest::Assertion) do
         
     | 
| 
      
 86 
     | 
    
         
            +
                  assert_called(@post, :title, "Message") do
         
     | 
| 
      
 87 
     | 
    
         
            +
                  end
         
     | 
| 
      
 88 
     | 
    
         
            +
                end
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
                assert_equal "Message.\nExpected title to be called 1 times, but was called 0 times.\nExpected: 1\n  Actual: 0", error.message
         
     | 
| 
      
 91 
     | 
    
         
            +
              end
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
              def test_assert_called_with_arguments
         
     | 
| 
      
 94 
     | 
    
         
            +
                assert_called_with(@post, :add_comment, ["Thanks for sharing this."]) do
         
     | 
| 
      
 95 
     | 
    
         
            +
                  @post.add_comment("Thanks for sharing this.")
         
     | 
| 
      
 96 
     | 
    
         
            +
                end
         
     | 
| 
      
 97 
     | 
    
         
            +
              end
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
              def test_assert_called_with_arguments_and_returns
         
     | 
| 
      
 100 
     | 
    
         
            +
                assert_called_with(@post, :add_comment, ["Thanks for sharing this."], returns: "Thanks!") do
         
     | 
| 
      
 101 
     | 
    
         
            +
                  assert_equal "Thanks!", @post.add_comment("Thanks for sharing this.")
         
     | 
| 
      
 102 
     | 
    
         
            +
                end
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                assert_equal "Thank you!", @post.add_comment("Thanks for sharing this.")
         
     | 
| 
      
 105 
     | 
    
         
            +
              end
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
              def test_assert_called_with_failure
         
     | 
| 
      
 108 
     | 
    
         
            +
                assert_raises(MockExpectationError) do
         
     | 
| 
      
 109 
     | 
    
         
            +
                  assert_called_with(@post, :add_comment, ["Thanks for sharing this."]) do
         
     | 
| 
      
 110 
     | 
    
         
            +
                    @post.add_comment("Thanks")
         
     | 
| 
      
 111 
     | 
    
         
            +
                  end
         
     | 
| 
      
 112 
     | 
    
         
            +
                end
         
     | 
| 
      
 113 
     | 
    
         
            +
              end
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
              def test_assert_called_with_multiple_expected_arguments
         
     | 
| 
      
 116 
     | 
    
         
            +
                assert_called_with(@post, :add_comment, [["Thanks for sharing this."], ["Thanks!"]]) do
         
     | 
| 
      
 117 
     | 
    
         
            +
                  @post.add_comment("Thanks for sharing this.")
         
     | 
| 
      
 118 
     | 
    
         
            +
                  @post.add_comment("Thanks!")
         
     | 
| 
      
 119 
     | 
    
         
            +
                end
         
     | 
| 
      
 120 
     | 
    
         
            +
              end
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
      
 122 
     | 
    
         
            +
              def test_assert_called_on_instance_of_with_defaults_to_expect_once
         
     | 
| 
      
 123 
     | 
    
         
            +
                assert_called_on_instance_of Post, :title do
         
     | 
| 
      
 124 
     | 
    
         
            +
                  @post.title
         
     | 
| 
      
 125 
     | 
    
         
            +
                end
         
     | 
| 
      
 126 
     | 
    
         
            +
              end
         
     | 
| 
      
 127 
     | 
    
         
            +
             
     | 
| 
      
 128 
     | 
    
         
            +
              def test_assert_called_on_instance_of_more_than_once
         
     | 
| 
      
 129 
     | 
    
         
            +
                assert_called_on_instance_of(Post, :title, times: 2) do
         
     | 
| 
      
 130 
     | 
    
         
            +
                  @post.title
         
     | 
| 
      
 131 
     | 
    
         
            +
                  @post.title
         
     | 
| 
      
 132 
     | 
    
         
            +
                end
         
     | 
| 
      
 133 
     | 
    
         
            +
              end
         
     | 
| 
      
 134 
     | 
    
         
            +
             
     | 
| 
      
 135 
     | 
    
         
            +
              def test_assert_called_on_instance_of_with_arguments
         
     | 
| 
      
 136 
     | 
    
         
            +
                assert_called_on_instance_of(Post, :add_comment) do
         
     | 
| 
      
 137 
     | 
    
         
            +
                  @post.add_comment("Thanks for sharing this.")
         
     | 
| 
      
 138 
     | 
    
         
            +
                end
         
     | 
| 
      
 139 
     | 
    
         
            +
              end
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
              def test_assert_called_on_instance_of_returns
         
     | 
| 
      
 142 
     | 
    
         
            +
                assert_called_on_instance_of(Post, :title, returns: "What is new in Rails 5.2") do
         
     | 
| 
      
 143 
     | 
    
         
            +
                  assert_equal "What is new in Rails 5.2", @post.title
         
     | 
| 
      
 144 
     | 
    
         
            +
                end
         
     | 
| 
      
 145 
     | 
    
         
            +
             
     | 
| 
      
 146 
     | 
    
         
            +
                assert_equal "What is new in Rails 6.0", @post.title
         
     | 
| 
      
 147 
     | 
    
         
            +
              end
         
     | 
| 
      
 148 
     | 
    
         
            +
             
     | 
| 
      
 149 
     | 
    
         
            +
              def test_assert_called_on_instance_of_failure
         
     | 
| 
      
 150 
     | 
    
         
            +
                error = assert_raises(Minitest::Assertion) do
         
     | 
| 
      
 151 
     | 
    
         
            +
                  assert_called_on_instance_of(Post, :title) do
         
     | 
| 
      
 152 
     | 
    
         
            +
                  end
         
     | 
| 
      
 153 
     | 
    
         
            +
                end
         
     | 
| 
      
 154 
     | 
    
         
            +
             
     | 
| 
      
 155 
     | 
    
         
            +
                assert_equal "Expected title to be called 1 times, but was called 0 times.\nExpected: 1\n  Actual: 0", error.message
         
     | 
| 
      
 156 
     | 
    
         
            +
              end
         
     | 
| 
      
 157 
     | 
    
         
            +
             
     | 
| 
      
 158 
     | 
    
         
            +
              def test_assert_called_on_instance_of_with_message
         
     | 
| 
      
 159 
     | 
    
         
            +
                error = assert_raises(Minitest::Assertion) do
         
     | 
| 
      
 160 
     | 
    
         
            +
                  assert_called_on_instance_of(Post, :title, "Message") do
         
     | 
| 
      
 161 
     | 
    
         
            +
                  end
         
     | 
| 
      
 162 
     | 
    
         
            +
                end
         
     | 
| 
      
 163 
     | 
    
         
            +
             
     | 
| 
      
 164 
     | 
    
         
            +
                assert_equal "Message.\nExpected title to be called 1 times, but was called 0 times.\nExpected: 1\n  Actual: 0", error.message
         
     | 
| 
      
 165 
     | 
    
         
            +
              end
         
     | 
| 
      
 166 
     | 
    
         
            +
             
     | 
| 
      
 167 
     | 
    
         
            +
              def test_assert_called_on_instance_of_nesting
         
     | 
| 
      
 168 
     | 
    
         
            +
                assert_called_on_instance_of(Post, :title, times: 3) do
         
     | 
| 
      
 169 
     | 
    
         
            +
                  assert_called_on_instance_of(Post, :body, times: 2) do
         
     | 
| 
      
 170 
     | 
    
         
            +
                    @post.title
         
     | 
| 
      
 171 
     | 
    
         
            +
                    @post.body
         
     | 
| 
      
 172 
     | 
    
         
            +
                    @post.title
         
     | 
| 
      
 173 
     | 
    
         
            +
                    @post.body
         
     | 
| 
      
 174 
     | 
    
         
            +
                    @post.title
         
     | 
| 
      
 175 
     | 
    
         
            +
                  end
         
     | 
| 
      
 176 
     | 
    
         
            +
                end
         
     | 
| 
      
 177 
     | 
    
         
            +
              end
         
     | 
| 
      
 178 
     | 
    
         
            +
             
     | 
| 
      
 179 
     | 
    
         
            +
              def test_assert_not_called_on_instance_of
         
     | 
| 
      
 180 
     | 
    
         
            +
                assert_not_called_on_instance_of(Post, :title) do
         
     | 
| 
      
 181 
     | 
    
         
            +
                  @post.body
         
     | 
| 
      
 182 
     | 
    
         
            +
                end
         
     | 
| 
      
 183 
     | 
    
         
            +
              end
         
     | 
| 
      
 184 
     | 
    
         
            +
             
     | 
| 
      
 185 
     | 
    
         
            +
              def test_assert_not_called_on_instance_of_failure
         
     | 
| 
      
 186 
     | 
    
         
            +
                error = assert_raises(Minitest::Assertion) do
         
     | 
| 
      
 187 
     | 
    
         
            +
                  assert_not_called_on_instance_of(Post, :title) do
         
     | 
| 
      
 188 
     | 
    
         
            +
                    @post.title
         
     | 
| 
      
 189 
     | 
    
         
            +
                  end
         
     | 
| 
      
 190 
     | 
    
         
            +
                end
         
     | 
| 
      
 191 
     | 
    
         
            +
             
     | 
| 
      
 192 
     | 
    
         
            +
                assert_equal "Expected title to be called 0 times, but was called 1 times.\nExpected: 0\n  Actual: 1", error.message
         
     | 
| 
      
 193 
     | 
    
         
            +
              end
         
     | 
| 
      
 194 
     | 
    
         
            +
             
     | 
| 
      
 195 
     | 
    
         
            +
              def test_assert_not_called_on_instance_of_nesting
         
     | 
| 
      
 196 
     | 
    
         
            +
                assert_not_called_on_instance_of(Post, :title) do
         
     | 
| 
      
 197 
     | 
    
         
            +
                  assert_not_called_on_instance_of(Post, :body) do
         
     | 
| 
      
 198 
     | 
    
         
            +
                  end
         
     | 
| 
      
 199 
     | 
    
         
            +
                end
         
     | 
| 
      
 200 
     | 
    
         
            +
              end
         
     | 
| 
      
 201 
     | 
    
         
            +
            end
         
     | 
    
        data/test/test_helper.rb
    ADDED
    
    
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,100 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: minitest-mock_expectations
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.9.0
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - bogdanvlviv
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2018-10-18 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies:
         
     | 
| 
      
 13 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 14 
     | 
    
         
            +
              name: bundler
         
     | 
| 
      
 15 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 16 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 17 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 18 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 19 
     | 
    
         
            +
                    version: '1.16'
         
     | 
| 
      
 20 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 21 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 22 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 23 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 24 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 25 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 26 
     | 
    
         
            +
                    version: '1.16'
         
     | 
| 
      
 27 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 28 
     | 
    
         
            +
              name: rake
         
     | 
| 
      
 29 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 30 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 31 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 32 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 33 
     | 
    
         
            +
                    version: '10.0'
         
     | 
| 
      
 34 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 35 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 36 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 37 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 38 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 39 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 40 
     | 
    
         
            +
                    version: '10.0'
         
     | 
| 
      
 41 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 42 
     | 
    
         
            +
              name: minitest
         
     | 
| 
      
 43 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 44 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 45 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 46 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 47 
     | 
    
         
            +
                    version: '5.0'
         
     | 
| 
      
 48 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 49 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 50 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 51 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 52 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 53 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 54 
     | 
    
         
            +
                    version: '5.0'
         
     | 
| 
      
 55 
     | 
    
         
            +
            description: ''
         
     | 
| 
      
 56 
     | 
    
         
            +
            email:
         
     | 
| 
      
 57 
     | 
    
         
            +
            - bogdanvlviv@gmail.com
         
     | 
| 
      
 58 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 59 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 60 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 61 
     | 
    
         
            +
            files:
         
     | 
| 
      
 62 
     | 
    
         
            +
            - ".gitignore"
         
     | 
| 
      
 63 
     | 
    
         
            +
            - ".travis.yml"
         
     | 
| 
      
 64 
     | 
    
         
            +
            - Gemfile
         
     | 
| 
      
 65 
     | 
    
         
            +
            - Gemfile.lock
         
     | 
| 
      
 66 
     | 
    
         
            +
            - LICENSE.txt
         
     | 
| 
      
 67 
     | 
    
         
            +
            - README.md
         
     | 
| 
      
 68 
     | 
    
         
            +
            - Rakefile
         
     | 
| 
      
 69 
     | 
    
         
            +
            - lib/minitest/mock_expectations.rb
         
     | 
| 
      
 70 
     | 
    
         
            +
            - lib/minitest/mock_expectations/assertions.rb
         
     | 
| 
      
 71 
     | 
    
         
            +
            - lib/minitest/mock_expectations/version.rb
         
     | 
| 
      
 72 
     | 
    
         
            +
            - minitest-mock_expectations.gemspec
         
     | 
| 
      
 73 
     | 
    
         
            +
            - test/minitest/mock_expectations/assertions_test.rb
         
     | 
| 
      
 74 
     | 
    
         
            +
            - test/minitest/mock_expectations_test.rb
         
     | 
| 
      
 75 
     | 
    
         
            +
            - test/test_helper.rb
         
     | 
| 
      
 76 
     | 
    
         
            +
            homepage: https://github.com/bogdanvlviv/minitest-mock_expectations
         
     | 
| 
      
 77 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 78 
     | 
    
         
            +
            - MIT
         
     | 
| 
      
 79 
     | 
    
         
            +
            metadata: {}
         
     | 
| 
      
 80 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 81 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 82 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 83 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 84 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 85 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 86 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 87 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 88 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 89 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 90 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 91 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 92 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 93 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 94 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 95 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 96 
     | 
    
         
            +
            rubygems_version: 2.7.6
         
     | 
| 
      
 97 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 98 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 99 
     | 
    
         
            +
            summary: Provides method call assertions
         
     | 
| 
      
 100 
     | 
    
         
            +
            test_files: []
         
     |