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