module RSpec::RubyContentMatchers class HaveClass < RSpec::RubyContentMatcher attr_reader :klass, :type def initialize(klass, type=nil) @klass = klass.to_s.camelize @type = type.to_s.camelize if type end 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 def failure_message super "Expected there to be the class #{klass}" end def negative_failure_message super "Did no expected there to be the class #{klass}" end def end_expr "(end|# #{klass})" end end def have_class(klass, type = nil) HaveClass.new(klass, type) end alias_method :be_class, :have_class def have_helper_class(klass) HaveClass.new(klass, :helper) end alias_method :be_helper_class, :have_helper_class def have_controller_class(klass) HaveClass.new(klass, :controller) end alias_method :be_controller_class, :have_controller_class end