Sha256: 713610e08c758a620ee28c9e108a24dbaa84a054d27b96535570b7f85fb648ac

Contents?: true

Size: 1.61 KB

Versions: 2

Compression:

Stored size: 1.61 KB

Contents

# Combines artifact file exist check with class check!

module RSpec::RailsApp::Artifact
  module Matchers
    class HaveArtifact < RSpec::RubyContentMatcher      
      extend Rails3::Assist::UseMacro
      use_helpers :file

      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
        begin
          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     
        rescue
          false
        end
      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.13 lib/rails_app_spec/matchers/artifact/have_artifact.rb
rails-app-spec-0.2.12 lib/rails_app_spec/matchers/artifact/have_artifact.rb