Class: RSpec::RubyContentMatchers::HaveComment

Inherits:
RSpec::RubyContentMatcher show all
Defined in:
lib/code_spec/matchers/have_comment.rb

Constant Summary

Constants inherited from RSpec::RubyContentMatcher

RSpec::RubyContentMatcher::ANY_GROUP, RSpec::RubyContentMatcher::LPAR, RSpec::RubyContentMatcher::OPT_ARGS, RSpec::RubyContentMatcher::OPT_SPACES, RSpec::RubyContentMatcher::Q_ANY_GROUP, RSpec::RubyContentMatcher::RPAR, RSpec::RubyContentMatcher::SPACES

Instance Attribute Summary collapse

Attributes inherited from RSpec::RubyContentMatcher

#alt_end, #content, #content_matches, #end_option

Instance Method Summary collapse

Methods inherited from RSpec::RubyContentMatcher

#any_args_expr, #args_expr, #args_msg, #comment_end, #debug, #debug?, #debug_content, #end_expr, #get_expr, #handle_result, #index, #indexes, #is_match?, #opt

Constructor Details

#initialize(comment) ⇒ HaveComment

Returns a new instance of HaveComment.



5
6
7
# File 'lib/code_spec/matchers/have_comment.rb', line 5

def initialize comment
  @comment = comment
end

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



3
4
5
# File 'lib/code_spec/matchers/have_comment.rb', line 3

def comment
  @comment
end

Instance Method Details

#failure_messageObject



14
15
16
17
# File 'lib/code_spec/matchers/have_comment.rb', line 14

def failure_message
  super
  "Expected there to be the comment '# #{comment}'" 
end

#matches?(content) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
# File 'lib/code_spec/matchers/have_comment.rb', line 9

def matches?(content)
  @content = content                        
  (content =~ /#{main_expr}/)
end

#negative_failure_messageObject



19
20
21
22
# File 'lib/code_spec/matchers/have_comment.rb', line 19

def negative_failure_message
  super
  "Did not expect there to be the comment '# #{comment}'" 
end