Class: RSpec::RubyContentMatchers::HaveSubclass
- Inherits:
-
RSpec::RubyContentMatcher
- Object
- RSpec::RubyContentMatcher
- RSpec::RubyContentMatchers::HaveSubclass
- Defined in:
- lib/generator_spec/matchers/content/have_subclass.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#superclass ⇒ Object
readonly
Returns the value of attribute superclass.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from RSpec::RubyContentMatcher
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(klass, superclass, type = nil) ⇒ HaveSubclass
constructor
A new instance of HaveSubclass.
- #matches?(content) ⇒ Boolean
- #negative_failure_message ⇒ Object
Methods inherited from RSpec::RubyContentMatcher
Constructor Details
#initialize(klass, superclass, type = nil) ⇒ HaveSubclass
Returns a new instance of HaveSubclass.
5 6 7 8 9 |
# File 'lib/generator_spec/matchers/content/have_subclass.rb', line 5 def initialize(klass, superclass, type=nil) @klass = klass.to_s.camelize @superclass = superclass.to_s.camelize @type = type.to_s.camelize if type end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
3 4 5 |
# File 'lib/generator_spec/matchers/content/have_subclass.rb', line 3 def klass @klass end |
#superclass ⇒ Object (readonly)
Returns the value of attribute superclass.
3 4 5 |
# File 'lib/generator_spec/matchers/content/have_subclass.rb', line 3 def superclass @superclass end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/generator_spec/matchers/content/have_subclass.rb', line 3 def type @type end |
Instance Method Details
#failure_message ⇒ Object
22 23 24 25 |
# File 'lib/generator_spec/matchers/content/have_subclass.rb', line 22 def super "Expected there to be the subclass #{klass} of #{superclass}" end |
#matches?(content) ⇒ Boolean
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/generator_spec/matchers/content/have_subclass.rb', line 11 def matches?(content) super match_res = (content =~ /class\s+#{klass}#{type}\s+<\s+#{superclass}(.*)#{end_expr}/m) if block_given? && $1 ruby_content = $1.strip.extend(RSpec::RubyContent::Helpers) yield ruby_content else match_res end end |
#negative_failure_message ⇒ Object
27 28 29 30 |
# File 'lib/generator_spec/matchers/content/have_subclass.rb', line 27 def super "Did no expected there to be the subclass #{klass} of #{superclass}" end |