Sha256: 6bdf72b647f95d110ca14821a446fb20e6dd0832c91c722221eafb12659c054b

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

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

    def initialize(calls)
      @calls = calls
    end

    def matches?(content)
      @content = content
      calls.each_pair do |method, args|
        @method = method.to_s
        @args = args
        return false if (content =~ /#{method}\s+#{args_expr}/m) == nil
      end
      true
    end          
  
    def failure_message
      puts "Content: #{content}" if RSpec::Generator.debug?            
      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 
      puts "Content: #{content}" if RSpec::Generator.debug?                                           
      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

2 entries across 2 versions & 1 rubygems

Version Path
generator-spec-0.4.3 lib/rspec_for_generators/matchers/content/have_calls.rb
generator-spec-0.4.2 lib/rspec_for_generators/matchers/content/have_calls.rb