Class: RSpec::RubyContentMatchers::HaveModules
- Inherits:
-
RSpec::RubyContentMatcher
- Object
- RSpec::RubyContentMatcher
- RSpec::RubyContentMatchers::HaveModules
- Defined in:
- lib/code_spec/matchers/multi/have_classes_modules.rb
Direct Known Subclasses
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
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
-
#postfix ⇒ Object
readonly
Returns the value of attribute postfix.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from RSpec::RubyContentMatcher
#content, #content_matches, #end_option
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(*names) ⇒ HaveModules
constructor
A new instance of HaveModules.
- #is_match?(content) ⇒ Boolean
- #matches?(content, &block) ⇒ Boolean
- #negative_failure_message ⇒ Object
Methods inherited from RSpec::RubyContentMatcher
#any_args_expr, #args_expr, #args_msg, #comment_end, #debug, #debug?, #debug_content, #display, #display_content, #end_expr, #get_expr, #handle_result, #index, #indexes, #opt
Constructor Details
#initialize(*names) ⇒ HaveModules
Returns a new instance of HaveModules.
5 6 7 8 9 10 |
# File 'lib/code_spec/matchers/multi/have_classes_modules.rb', line 5 def initialize(*names) postfix = last_arg_value({:postfix => ''}, names) @names = names.to_strings @postfix = postfix ? postfix.to_s.camelize : nil @type = :module end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/code_spec/matchers/multi/have_classes_modules.rb', line 3 def name @name end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
3 4 5 |
# File 'lib/code_spec/matchers/multi/have_classes_modules.rb', line 3 def names @names end |
#postfix ⇒ Object (readonly)
Returns the value of attribute postfix.
3 4 5 |
# File 'lib/code_spec/matchers/multi/have_classes_modules.rb', line 3 def postfix @postfix end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/code_spec/matchers/multi/have_classes_modules.rb', line 3 def type @type end |
Instance Method Details
#failure_message ⇒ Object
39 40 41 42 |
# File 'lib/code_spec/matchers/multi/have_classes_modules.rb', line 39 def super display "Expected there to be the #{type} #{name}" end |
#is_match?(content) ⇒ Boolean
31 32 33 34 35 36 37 |
# File 'lib/code_spec/matchers/multi/have_classes_modules.rb', line 31 def is_match? content expr = get_expr(content) debug "match expression: #{expr}" match = (content =~ expr) @content_matches = [$1, $2, $3] match end |
#matches?(content, &block) ⇒ Boolean
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/code_spec/matchers/multi/have_classes_modules.rb', line 12 def matches? content, &block return false if names.empty? @content = content return false if names.empty? names.each do |name| @name = name.camelize @klass = name.camelize @full_class = "#{@klass}#{@postfix}" @end_option = name match = is_match? content return false if !match end true end |
#negative_failure_message ⇒ Object
44 45 46 47 |
# File 'lib/code_spec/matchers/multi/have_classes_modules.rb', line 44 def super display "Did not expected there to be the #{type} #{name}" end |