Class: RSpec::RubyContentMatcher
- Inherits:
-
Object
- Object
- RSpec::RubyContentMatcher
show all
- Defined in:
- lib/code_spec/matchers/content_matcher.rb
Direct Known Subclasses
RSpec::RubyContentMatchers::HaveBlock, RSpec::RubyContentMatchers::HaveCall, RSpec::RubyContentMatchers::HaveClassSelf, RSpec::RubyContentMatchers::HaveComment, RSpec::RubyContentMatchers::HaveMethod, RSpec::RubyContentMatchers::HaveMethods, RSpec::RubyContentMatchers::HaveModule, RSpec::RubyContentMatchers::HaveModules, RSpec::RubyContentMatchers::HaveRegion, RSpec::RubyContentMatchers::HaveSubclass, RSpec::RubyContentMatchers::IncludeModule, RSpec::RubyContentMatchers::InheritFrom
Constant Summary
collapse
- Q_ANY_GROUP =
'(.*?)'
- ANY_GROUP =
'(.*)'
- SPACES =
'\s+'
- OPT_SPACES =
'\s*'
- LPAR =
'(\()'
- RPAR =
'(\))'
- OPT_ARGS =
'(\(.+\))?'
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of RubyContentMatcher.
5
6
7
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 5
def initialize name
@end_option = name
end
|
Instance Attribute Details
#alt_end ⇒ Object
Returns the value of attribute alt_end.
3
4
5
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 3
def alt_end
@alt_end
end
|
#content ⇒ Object
Returns the value of attribute content.
3
4
5
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 3
def content
@content
end
|
#content_matches ⇒ Object
Returns the value of attribute content_matches.
3
4
5
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 3
def content_matches
@content_matches
end
|
#end_option ⇒ Object
Returns the value of attribute end_option.
3
4
5
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 3
def end_option
@end_option
end
|
Instance Method Details
#any_args_expr ⇒ Object
74
75
76
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 74
def any_args_expr
OPT_SPACES + OPT_ARGS
end
|
#args_msg ⇒ Object
70
71
72
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 70
def args_msg
args ? " with arguments #{args}" : ''
end
|
90
91
92
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 90
def
alt_end != nil ? '#' + SPACES + "(#{end_option}|#{alt_end})" : '#' + SPACES + "#{end_option}"
end
|
#debug(msg) ⇒ Object
106
107
108
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 106
def debug msg
puts msg if debug?
end
|
#debug? ⇒ Boolean
17
18
19
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 17
def debug?
false
end
|
#debug_content ⇒ Object
102
103
104
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 102
def debug_content
debug "Content: #{content}"
end
|
#end_expr ⇒ Object
86
87
88
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 86
def end_expr
"$"
end
|
#failure_message ⇒ Object
94
95
96
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 94
def failure_message
debug_content
end
|
#get_expr(content) ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 48
def get_expr content
expr = /#{main_expr}#{}/m
if (content =~ expr).nil?
/#{main_expr}#{end_expr}/m
else
expr
end
end
|
#handle_result(content, match, &block) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 40
def handle_result content, match, &block
if block && match && content
ruby_content = content.strip yield ruby_content
end
match
end
|
#index ⇒ Object
9
10
11
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 9
def index
0
end
|
#indexes ⇒ Object
13
14
15
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 13
def indexes
nil
end
|
#is_match?(content) ⇒ Boolean
32
33
34
35
36
37
38
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 32
def is_match? content
expr = get_expr(content)
debug "match expression: #{expr}"
match = (content =~ expr)
@content_matches = [$1, $2, $3]
match
end
|
#main_expr ⇒ Object
82
83
84
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 82
def main_expr
raise "Must override main_expr"
end
|
#matches?(content, &block) ⇒ Boolean
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 21
def matches? content, &block
@content = content
match = is_match? content
content_to_yield = if indexes
content_matches[indexes.last] || content_matches[indexes.first]
else
content_matches[index]
end
handle_result(content_to_yield, match, &block)
end
|
#negative_failure_message ⇒ Object
98
99
100
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 98
def negative_failure_message
debug_content
end
|
#opt(expr) ⇒ Object
66
67
68
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 66
def opt expr
"#{expr}?"
end
|