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
83
84
85
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 83
def any_args_expr
OPT_SPACES + OPT_ARGS
end
|
#args_msg ⇒ Object
79
80
81
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 79
def args_msg
args ? " with arguments #{args}" : ''
end
|
99
100
101
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 99
def
alt_end != nil ? '#' + SPACES + "(#{end_option}|#{alt_end})" : '#' + SPACES + "#{end_option}"
end
|
#debug(msg) ⇒ Object
115
116
117
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 115
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
111
112
113
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 111
def debug_content
debug "Content: #{content}"
end
|
#display(msg) ⇒ Object
25
26
27
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 25
def display msg
"#{msg}#{display_content}\nRegexp: #{@expr}\n#{@special_error}"
end
|
#display_content ⇒ Object
21
22
23
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 21
def display_content
"\ncontent:#{content}"
end
|
#end_expr ⇒ Object
95
96
97
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 95
def end_expr
"$"
end
|
#failure_message ⇒ Object
103
104
105
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 103
def failure_message
debug_content
end
|
#get_expr(content) ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 57
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
49
50
51
52
53
54
55
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 49
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
40
41
42
43
44
45
46
47
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 40
def is_match? content
expr = get_expr(content)
@expr = expr
debug "match expression: #{expr}"
match = (content =~ expr)
@content_matches = [$1, $2, $3]
match
end
|
#main_expr ⇒ Object
91
92
93
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 91
def main_expr
raise "Must override main_expr"
end
|
#matches?(content, &block) ⇒ Boolean
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 29
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
107
108
109
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 107
def negative_failure_message
debug_content
end
|
#opt(expr) ⇒ Object
75
76
77
|
# File 'lib/code_spec/matchers/content_matcher.rb', line 75
def opt expr
"#{expr}?"
end
|