Sha256: ffb4bc0654329ca744e184055190e7a4e8803006b225aced730ba7818d5d12cb

Contents?: true

Size: 981 Bytes

Versions: 2

Compression:

Stored size: 981 Bytes

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 HaveComment < RSpec::RubyContentMatcher
    attr_accessor :comment

    def initialize comment
      @comment = comment
    end

    def matches?(content)
      @content = content                        
      (content =~ /#{main_expr}/)
    end
  
    def failure_message
      super
      "Expected there to be the comment '# #{comment}'" 
    end 
    
    def negative_failure_message
      super
      "Did not expect there to be the comment '# #{comment}'" 
    end

    protected
    
    def main_expr
      '\s*#\s*' + "#{comment}"
    end
  end

  def have_comment comment
    HaveComment.new comment
  end
  
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
code-spec-0.1.0 lib/code_spec/matchers/have_comment.rb
generator-spec-0.5.0 lib/generator_spec/matchers/content/have_comment.rb