Sha256: 189a9251d1d1626e675ab6eb625f071a3d9bf1de0e6e57c271ee8ee5e4e1643d

Contents?: true

Size: 1.5 KB

Versions: 8

Compression:

Stored size: 1.5 KB

Contents

# This method tries to see if a specific method is contained in the generated file.
# It can operate (should) on either a file name or the raw content 
#
#   generated_file_name.should have_method "hello" # 'my/path/say_hello.rb'.should have_method "hello"
#
#   say_hello_file_content.should have_method "hello"
#
module RSpec::RubyContentMatchers
  class HaveMethod < RSpec::RubyContentMatcher
    attr_reader :method, :type, :args

    def initialize(method, type=nil, options = {})
      @method = method.to_s
      super method
      @type = type      
      @args = options[:args]
    end

    def index
      1
    end          
  
    def failure_message
      super
      "Expected there to be the #{class_msg} method #{method}, but there wasn't"
    end 
    
    def negative_failure_message                                      
      super
      "Did not expect there to be the #{class_msg} method #{method}, but there was"
    end

    protected

    def class_msg
      (type == :class) ? 'class' : ''
    end

    def main_expr
      'def' + SPACES + "#{self_expr}#{method}#{args_expr}" + ANY_GROUP
    end

    def args_expr
      return super if args
      any_args_expr
    end
       
    def self_expr 
      type == :class ? 'self.' : ''
    end
            
    def alt_end
      'def'
    end               
    
  end
  
  def have_method(method, type = nil)
    HaveMethod.new(method, type)
  end  

  def have_args_method(method, options = {})
    HaveMethod.new(method, options[:type], options)
  end  

end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
code-spec-0.2.1 lib/code_spec/matchers/have_method.rb
code-spec-0.2.0 lib/code_spec/matchers/have_method.rb
code-spec-0.1.3 lib/code_spec/matchers/have_method.rb
code-spec-0.1.2 lib/code_spec/matchers/have_method.rb
code-spec-0.1.0 lib/code_spec/matchers/have_method.rb
generator-spec-0.5.0 lib/generator_spec/matchers/content/have_method.rb
generator-spec-0.4.8 lib/generator_spec/matchers/content/have_method.rb
generator-spec-0.4.7 lib/generator_spec/matchers/content/have_method.rb