flexmock 2.0.1 → 2.0.2
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/lib/flexmock/core.rb +2 -0
 - data/lib/flexmock/core_class_methods.rb +34 -1
 - data/lib/flexmock/expectation_director.rb +3 -2
 - data/lib/flexmock/partial_mock.rb +1 -0
 - data/lib/flexmock/spy_describers.rb +3 -10
 - data/lib/flexmock/version.rb +1 -1
 - metadata +3 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 98384ea13adbc6183d9341511891b3a9f8f03d45
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 3590aed927dd2b5639cd89bc5ef4a94721cc019a
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 81593e3d1ac8834dfa7a2984a5673979b9a609cd2269711be7ddaa989f31542066bbec7a26b927f9d268a0880a332d26b7db70e642abac4aa24579cadc09c933
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 157647079491431589151fd0a1297c7b78d8b179b73ff2e97fc2d7415cf3f8b25bf0985d5577b210490633291e83e2e4bdae57014ff2cc5140640ed28cb5f6bf
         
     | 
    
        data/lib/flexmock/core.rb
    CHANGED
    
    | 
         @@ -106,6 +106,8 @@ class FlexMock 
     | 
|
| 
       106 
106 
     | 
    
         | 
| 
       107 
107 
     | 
    
         
             
              # Handle missing methods by attempting to look up a handler.
         
     | 
| 
       108 
108 
     | 
    
         
             
              def method_missing(sym, *args, &block)
         
     | 
| 
      
 109 
     | 
    
         
            +
                FlexMock.verify_mocking_allowed!
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
       109 
111 
     | 
    
         
             
                enhanced_args = block_given? ? args + [block] : args
         
     | 
| 
       110 
112 
     | 
    
         
             
                call_record = CallRecord.new(sym, enhanced_args, block_given?)
         
     | 
| 
       111 
113 
     | 
    
         
             
                @calls << call_record
         
     | 
| 
         @@ -48,6 +48,34 @@ class FlexMock 
     | 
|
| 
       48 
48 
     | 
    
         
             
                  container.flexmock_teardown
         
     | 
| 
       49 
49 
     | 
    
         
             
                end
         
     | 
| 
       50 
50 
     | 
    
         | 
| 
      
 51 
     | 
    
         
            +
                FORBID_MOCKING = :__flexmock_forbid_mocking
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                # Forbid mock calls to happen while the block is being evaluated
         
     | 
| 
      
 54 
     | 
    
         
            +
                #
         
     | 
| 
      
 55 
     | 
    
         
            +
                # @param [Object] mocking_forbidden_return the return value that should be
         
     | 
| 
      
 56 
     | 
    
         
            +
                #   used if a mocking call has happened. If no mocking calls happened,
         
     | 
| 
      
 57 
     | 
    
         
            +
                #   returns the return value of the block
         
     | 
| 
      
 58 
     | 
    
         
            +
                def forbid_mocking(mocking_forbidden_return = nil)
         
     | 
| 
      
 59 
     | 
    
         
            +
                  current, Thread.current[FORBID_MOCKING] =
         
     | 
| 
      
 60 
     | 
    
         
            +
                      Thread.current[FORBID_MOCKING], true
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                  catch(FORBID_MOCKING) do
         
     | 
| 
      
 63 
     | 
    
         
            +
                    return yield
         
     | 
| 
      
 64 
     | 
    
         
            +
                  end
         
     | 
| 
      
 65 
     | 
    
         
            +
                  mocking_forbidden_return
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                ensure
         
     | 
| 
      
 68 
     | 
    
         
            +
                  Thread.current[FORBID_MOCKING] = current
         
     | 
| 
      
 69 
     | 
    
         
            +
                end
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                # Verify that mocking is allowed in the current context. Throws if it is
         
     | 
| 
      
 72 
     | 
    
         
            +
                # not.
         
     | 
| 
      
 73 
     | 
    
         
            +
                def verify_mocking_allowed!
         
     | 
| 
      
 74 
     | 
    
         
            +
                  if Thread.current[FORBID_MOCKING]
         
     | 
| 
      
 75 
     | 
    
         
            +
                    throw FORBID_MOCKING
         
     | 
| 
      
 76 
     | 
    
         
            +
                  end
         
     | 
| 
      
 77 
     | 
    
         
            +
                end
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
       51 
79 
     | 
    
         
             
                # Class method to format a method name and argument list as a nice
         
     | 
| 
       52 
80 
     | 
    
         
             
                # looking string.
         
     | 
| 
       53 
81 
     | 
    
         
             
                def format_call(sym, args)  # :nodoc:
         
     | 
| 
         @@ -58,7 +86,12 @@ class FlexMock 
     | 
|
| 
       58 
86 
     | 
    
         
             
                # parenthesis).
         
     | 
| 
       59 
87 
     | 
    
         
             
                def format_args(args)
         
     | 
| 
       60 
88 
     | 
    
         
             
                  if args
         
     | 
| 
       61 
     | 
    
         
            -
                    args. 
     | 
| 
      
 89 
     | 
    
         
            +
                    args = args.map do |a|
         
     | 
| 
      
 90 
     | 
    
         
            +
                      FlexMock.forbid_mocking("<recursive call to mocked method in #inspect>") do
         
     | 
| 
      
 91 
     | 
    
         
            +
                        a.inspect
         
     | 
| 
      
 92 
     | 
    
         
            +
                      end
         
     | 
| 
      
 93 
     | 
    
         
            +
                    end
         
     | 
| 
      
 94 
     | 
    
         
            +
                    args.join(', ')
         
     | 
| 
       62 
95 
     | 
    
         
             
                  else
         
     | 
| 
       63 
96 
     | 
    
         
             
                    "*args"
         
     | 
| 
       64 
97 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -39,8 +39,9 @@ class FlexMock 
     | 
|
| 
       39 
39 
     | 
    
         
             
                  exp = find_expectation(*args)
         
     | 
| 
       40 
40 
     | 
    
         
             
                  call_record.expectation = exp if call_record
         
     | 
| 
       41 
41 
     | 
    
         
             
                  FlexMock.check(
         
     | 
| 
       42 
     | 
    
         
            -
                    "no matching handler found for " +
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
      
 42 
     | 
    
         
            +
                    proc { "no matching handler found for " +
         
     | 
| 
      
 43 
     | 
    
         
            +
                           FlexMock.format_call(@sym, args) }
         
     | 
| 
      
 44 
     | 
    
         
            +
                  ) { !exp.nil? }
         
     | 
| 
       44 
45 
     | 
    
         
             
                  returned_value = exp.verify_call(*args)
         
     | 
| 
       45 
46 
     | 
    
         
             
                  returned_value
         
     | 
| 
       46 
47 
     | 
    
         
             
                end
         
     | 
| 
         @@ -3,7 +3,7 @@ class FlexMock 
     | 
|
| 
       3 
3 
     | 
    
         
             
                module SpyDescribers
         
     | 
| 
       4 
4 
     | 
    
         
             
                  def spy_description(spy, sym, args, options)
         
     | 
| 
       5 
5 
     | 
    
         
             
                    result = "have received "
         
     | 
| 
       6 
     | 
    
         
            -
                    result <<  
     | 
| 
      
 6 
     | 
    
         
            +
                    result << FlexMock.format_call(sym, args)
         
     | 
| 
       7 
7 
     | 
    
         
             
                    result << times_description(options[:times])
         
     | 
| 
       8 
8 
     | 
    
         
             
                    result << block_description(options[:with_block])
         
     | 
| 
       9 
9 
     | 
    
         
             
                    result
         
     | 
| 
         @@ -19,7 +19,7 @@ class FlexMock 
     | 
|
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
                  def describe_spy(spy, sym, args, options, not_clause="")
         
     | 
| 
       21 
21 
     | 
    
         
             
                    result = "expected "
         
     | 
| 
       22 
     | 
    
         
            -
                    result <<  
     | 
| 
      
 22 
     | 
    
         
            +
                    result << FlexMock.format_call(sym, args)
         
     | 
| 
       23 
23 
     | 
    
         
             
                    result << " to#{not_clause} be received by " << spy.inspect
         
     | 
| 
       24 
24 
     | 
    
         
             
                    result << times_description(options[:times])
         
     | 
| 
       25 
25 
     | 
    
         
             
                    result << block_description(options[:with_block])
         
     | 
| 
         @@ -44,7 +44,7 @@ class FlexMock 
     | 
|
| 
       44 
44 
     | 
    
         
             
                  def append_call_record(result, call_record)
         
     | 
| 
       45 
45 
     | 
    
         
             
                    result <<
         
     | 
| 
       46 
46 
     | 
    
         
             
                      "    " <<
         
     | 
| 
       47 
     | 
    
         
            -
                       
     | 
| 
      
 47 
     | 
    
         
            +
                      FlexMock.format_call(call_record.method_name, call_record.args)
         
     | 
| 
       48 
48 
     | 
    
         
             
                    if call_record.expectation
         
     | 
| 
       49 
49 
     | 
    
         
             
                      result <<
         
     | 
| 
       50 
50 
     | 
    
         
             
                        " matched by " <<
         
     | 
| 
         @@ -79,13 +79,6 @@ class FlexMock 
     | 
|
| 
       79 
79 
     | 
    
         
             
                    end
         
     | 
| 
       80 
80 
     | 
    
         
             
                  end
         
     | 
| 
       81 
81 
     | 
    
         | 
| 
       82 
     | 
    
         
            -
                  def call_description(sym, args)
         
     | 
| 
       83 
     | 
    
         
            -
                    if args
         
     | 
| 
       84 
     | 
    
         
            -
                      "#{sym}(#{args.map { |o| o.inspect }.join(', ')})"
         
     | 
| 
       85 
     | 
    
         
            -
                    else
         
     | 
| 
       86 
     | 
    
         
            -
                      "#{sym}(...)"
         
     | 
| 
       87 
     | 
    
         
            -
                    end
         
     | 
| 
       88 
     | 
    
         
            -
                  end
         
     | 
| 
       89 
82 
     | 
    
         
             
                  extend SpyDescribers
         
     | 
| 
       90 
83 
     | 
    
         
             
                end
         
     | 
| 
       91 
84 
     | 
    
         | 
    
        data/lib/flexmock/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: flexmock
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 2.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 2.0.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Jim Weirich
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2015- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2015-11-16 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: minitest
         
     | 
| 
         @@ -176,3 +176,4 @@ signing_key: 
     | 
|
| 
       176 
176 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       177 
177 
     | 
    
         
             
            summary: Simple and Flexible Mock Objects for Testing
         
     | 
| 
       178 
178 
     | 
    
         
             
            test_files: []
         
     | 
| 
      
 179 
     | 
    
         
            +
            has_rdoc: 
         
     |