Sha256: fe7fd051dc7ae32867293e383a6ff20997e51d35ad4c81e01ed4fa4a9eac3463

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

# Combines artifact file exist check with class check!

module RSpec::RailsApp::Artifact
  module Matchers
    class HaveArtifact < RSpec::RubyContentMatcher      
      include Rails3::Assist::Artifact::FileName
      include Artifact::Matcher::Helper

      def initialize(name, artifact_type)
        extend "Rails3::Assist::Artifact::#{artifact_type.to_s.camelize}".constantize
        
        parse_name name
        parse_type artifact_type
        super name if artifact_type != :view
      end

      def matches?(root_path, &block)
        @root_path = root_path
        artifact_found = find_artifact        
        return nil if !artifact_found

        # check file content for class or subclass
        self.content = File.read(artifact_found) 
        
        if artifact_type == :view
          yield content if block
          return true
        end
        super content, &block     
      end   
    end

    def have_artifact(relative, type = nil)
      HaveArtifact.new(relative, type)
    end
    alias_method :contain_artifact, :have_artifact
    
    (::Rails3::Assist.artifacts - [:view]).each do |name|
      class_eval %{
        def have_#{name} relative
          have_artifact relative, :#{name}
        end
        alias_method :contain_#{name}, :have_#{name}
      }
    end  
    
    def have_view folder, action=nil, view_ext=nil      
      arg = {:folder => folder, :action => action, :view_ext => view_ext}
      have_artifact arg, :view
    end
    alias_method :contain_view, :have_view
  end
end       

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails-app-spec-0.2.8 lib/rails_app_spec/matchers/artifact/have_artifact.rb
rails-app-spec-0.2.7 lib/rails_app_spec/matchers/artifact/have_artifact.rb