Class: RSpec::RailsApp::ArtifactFile::Matchers::HaveRailsArtifactFile

Inherits:
Object
  • Object
show all
Includes:
Rails3::Assist::Artifact::FileName
Defined in:
lib/rails_app_spec/matchers/artifact/have_rails_artifact_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, artifact_type = nil) ⇒ HaveRailsArtifactFile

Returns a new instance of HaveRailsArtifactFile.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rails_app_spec/matchers/artifact/have_rails_artifact_file.rb', line 13

def initialize(name, artifact_type = nil)
  self.artifact_type = artifact_type

  extend "Rails3::Assist::Artifact::#{artifact_type.to_s.camelize}".constantize
  
  if name.kind_of? Hash                  
    view_options  = name
    self.folder   = view_options[:folder]
    self.action   = view_options[:action] 
    self.view_ext = view_options[:view_ext] 
    self.artifact_type = :view
    return nil
  end        
  self.artifact_name = name.to_s
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



11
12
13
# File 'lib/rails_app_spec/matchers/artifact/have_rails_artifact_file.rb', line 11

def action
  @action
end

#artifact_nameObject

include ::Rails::Assist::Migration::FileName



9
10
11
# File 'lib/rails_app_spec/matchers/artifact/have_rails_artifact_file.rb', line 9

def artifact_name
  @artifact_name
end

#artifact_typeObject

include ::Rails::Assist::Migration::FileName



9
10
11
# File 'lib/rails_app_spec/matchers/artifact/have_rails_artifact_file.rb', line 9

def artifact_type
  @artifact_type
end

#folderObject

Returns the value of attribute folder.



11
12
13
# File 'lib/rails_app_spec/matchers/artifact/have_rails_artifact_file.rb', line 11

def folder
  @folder
end

#nameObject

include ::Rails::Assist::Migration::FileName



9
10
11
# File 'lib/rails_app_spec/matchers/artifact/have_rails_artifact_file.rb', line 9

def name
  @name
end

#view_extObject

Returns the value of attribute view_ext.



11
12
13
# File 'lib/rails_app_spec/matchers/artifact/have_rails_artifact_file.rb', line 11

def view_ext
  @view_ext
end

Instance Method Details

#failure_messageObject



52
53
54
# File 'lib/rails_app_spec/matchers/artifact/have_rails_artifact_file.rb', line 52

def failure_message
  "Expected the #{artifact_type} #{artifact_name} to exist, but it didn't"
end

#matches?(root_path, &block) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rails_app_spec/matchers/artifact/have_rails_artifact_file.rb', line 29

def matches?(root_path, &block)
  self.artifact_name = case artifact_type
  when :view                                           
    find_view_method = "#{artifact_type}_file_name"
    File.expand_path(send find_view_method, folder, action, view_ext, :root_path => root_path)          
  else                                                     
    find_existing_artifact_method = "existing_#{artifact_type}_file"
    if respond_to? find_existing_artifact_method
      send find_existing_artifact_method, artifact_name, artifact_type, :root_path => root_path 
    else
      raise "The method ##{find_existing_artifact_method} to find the artifact was not available"
    end
  end                    
    
  # puts "artifact_name: #{artifact_name}"

  match = File.file? artifact_name      
  if block && match
    yield File.read(artifact_name)
  end
  match        
end

#negative_failure_messageObject



56
57
58
# File 'lib/rails_app_spec/matchers/artifact/have_rails_artifact_file.rb', line 56

def negative_failure_message
  "Did not expect the #{artifact_type} #{artifact_name} to exist, but it did"
end