Sha256: 75c5897bc98aefc286e4dcb4e5583ed933e5a2655aa8114e864f968065f9b971

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

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
      

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
generator-spec-0.4.5 lib/generator_spec/matchers/content/have_class.rb
generator-spec-0.4.4 lib/generator_spec/matchers/content/have_class.rb