Class: RSpec::RailsApp::File::Matchers::HaveRailsFile

Inherits:
Object
  • Object
show all
Includes:
Rails::Assist::App, Rails::Assist::BaseHelper::FileName, Rails::Assist::Migration::FileName, Rails::Migration::Assist::ClassMethods
Defined in:
lib/rails_app_spec/matchers/file/have_rails_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, artifact_type = nil) ⇒ HaveRailsFile

Returns a new instance of HaveRailsFile.



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

def initialize(name, artifact_type = nil)
  self.artifact_type = artifact_type
  
  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.



12
13
14
# File 'lib/rails_app_spec/matchers/file/have_rails_file.rb', line 12

def action
  @action
end

#artifact_nameObject

Returns the value of attribute artifact_name.



10
11
12
# File 'lib/rails_app_spec/matchers/file/have_rails_file.rb', line 10

def artifact_name
  @artifact_name
end

#artifact_typeObject

Returns the value of attribute artifact_type.



10
11
12
# File 'lib/rails_app_spec/matchers/file/have_rails_file.rb', line 10

def artifact_type
  @artifact_type
end

#folderObject

Returns the value of attribute folder.



12
13
14
# File 'lib/rails_app_spec/matchers/file/have_rails_file.rb', line 12

def folder
  @folder
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/rails_app_spec/matchers/file/have_rails_file.rb', line 10

def name
  @name
end

#view_extObject

Returns the value of attribute view_ext.



12
13
14
# File 'lib/rails_app_spec/matchers/file/have_rails_file.rb', line 12

def view_ext
  @view_ext
end

Instance Method Details

#failure_messageObject



46
47
48
# File 'lib/rails_app_spec/matchers/file/have_rails_file.rb', line 46

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

#matches?(generator, &block) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rails_app_spec/matchers/file/have_rails_file.rb', line 28

def matches?(generator, &block)
  self.artifact_name = case artifact_type
  when :view
    File.expand_path(send :"#{artifact_type}_file_name", folder, action, view_ext)          
  else            
    found_file = send :existing_file_name, artifact_name, artifact_type if respond_to? :existing_file_name
    # send :"#{artifact_type}_file_name", artifact_name
  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



50
51
52
# File 'lib/rails_app_spec/matchers/file/have_rails_file.rb', line 50

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