Sha256: 0b7ff5f83015fe938129d57012bdf04f57e707af4ef21d94d064ed0b231d88ff

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

module RSpec::RubyContentMatchers
  class HaveCalls
    attr_reader :calls
    attr_accessor :method, :args    

    def initialize(calls)
      @calls = calls
    end

    def matches?(content)
      calls.each_pair do |method, args|
        @method = method
        @args = args
        return false if (content =~ /#{method}\s+#{args_expr}/m) == nil
      end
      true
    end          
  
    def failure_message
      return "Expected there to be a call to #{method} with args #{args}, but there wasn't" if args
      "Expected there to be a call to #{method}, but there wasn't"
    end 
    
    def negative_failure_message                                      
      return "Did not expect there to be a call to #{method} with args #{args}, but there was" if args
      "Did not expect there to be a call to #{method}, but there was"
    end
             
    protected
    
    def args_expr
      args ? "(\()?\s*#{args}\s*(\))?" : ''
    end      
               
  end
  
  def have_calls(calls)
    HaveCalls.new(calls)
  end  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
generator-spec-0.4.0 lib/rspec_for_generators/matchers/content/have_calls.rb
generator-spec-0.3.5 lib/rspec_for_generators/matchers/content/have_calls.rb
generator-spec-0.3.4 lib/rspec_for_generators/matchers/content/have_calls.rb