Sha256: 63a242044293390fc7863a1915706b839e95d4b0c36d115dacb3645a8679428c

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

module RSpec::RubyContentMatchers
  class HaveClass
    attr_reader :klass, :type, :content

    def initialize(klass, type=nil)
      @klass = klass.to_s.camelize
      @type  = type.to_s.camelize if type
    end

    def matches?(content) 
      @content = content     
      match_res = (content =~ /class\s+#{klass}#{type}\s+(.*)end/m)
      if block_given? && $1
        ruby_content = $1.strip.extend(RSpec::RubyContent::Helpers)
        yield ruby_content        
      end
      match_res
    end          
  
    def failure_message 
      puts "Content: #{content}" if RSpec::Generator.debug?
      "Expected there to be the class #{klass}"
    end 
    
    def negative_failure_message    
      puts "Content: #{content}" if RSpec::Generator.debug?      
      "Did no expected there to be the class #{klass}"
    end
               
  end
  
  def have_class(klass, type = nil)
    HaveClass.new(klass, type)
  end    

  def have_helper_class(klass)
    HaveClass.new(klass, :helper)
  end    

  def have_controller_class(klass)
    HaveClass.new(klass, :controller)
  end
end
      

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
generator-spec-0.4.3 lib/rspec_for_generators/matchers/content/have_class.rb
generator-spec-0.4.2 lib/rspec_for_generators/matchers/content/have_class.rb