Sha256: 2f38fb74ee6122db0ff3581f8e00df8f6198a420a2c78c58c12b58269f6245d5

Contents?: true

Size: 1.25 KB

Versions: 18

Compression:

Stored size: 1.25 KB

Contents

module RSpec::RubyContentMatchers
  class HaveCalls < HaveCall
    attr_reader :calls, :method, :args

    def initialize(*calls)
      case calls.first
      when Array, Hash
        @calls = calls.first
      else    
        @calls = calls
      end
    end

    def matches?(content)
      super
      case calls
      when Array
        do_list
      when Hash
        do_hash
      end
    end                              
    
    protected

    def do_list
      calls.each do |method|
        @method = method.to_s   
        expr = 
        has_def = (content =~ /def(.*)#{method}/)
        expr = if has_def
          /#{not_def}\s*#{method}/m
        else
          /#{not_def}?\s*#{method}/m
        end
        return false if (content =~ expr) == nil
      end
      true
    end    

    def do_hash
      calls.each_pair do |method, args|
        @method = method.to_s
        @args = args
        has_def = (content =~ /def(.*)#{method}/)
        expr = if has_def
          /#{not_def}\s*#{method}\s*#{args_expr}/m
        else
          /#{not_def}?\s*#{method}\s*#{args_expr}/m
        end         
        return false if (content =~ expr) == nil
      end
      true
    end    
  end
  
  def have_calls(*calls)
    HaveCalls.new(*calls)
  end  
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
code-spec-0.4.0 lib/code_spec/matchers/have_calls.rb
code-spec-0.3.0 lib/code_spec/matchers/have_calls.rb
code-spec-0.2.11 lib/code_spec/matchers/have_calls.rb
code-spec-0.2.9 lib/code_spec/matchers/have_calls.rb
code-spec-0.2.8 lib/code_spec/matchers/have_calls.rb
code-spec-0.2.7 lib/code_spec/matchers/have_calls.rb
code-spec-0.2.6 lib/code_spec/matchers/have_calls.rb
code-spec-0.2.5 lib/code_spec/matchers/have_calls.rb
code-spec-0.2.4 lib/code_spec/matchers/have_calls.rb
code-spec-0.2.3 lib/code_spec/matchers/have_calls.rb
code-spec-0.2.2 lib/code_spec/matchers/have_calls.rb
code-spec-0.2.1 lib/code_spec/matchers/have_calls.rb
code-spec-0.2.0 lib/code_spec/matchers/have_calls.rb
code-spec-0.1.3 lib/code_spec/matchers/have_calls.rb
code-spec-0.1.2 lib/code_spec/matchers/have_calls.rb
code-spec-0.1.0 lib/code_spec/matchers/have_calls.rb
generator-spec-0.5.0 lib/generator_spec/matchers/content/have_calls.rb
generator-spec-0.4.8 lib/generator_spec/matchers/content/have_calls.rb