Module: ArtifactFile::Matcher::Helper

Includes:
RailsAssist::Artifact::View::FileName
Included in:
RSpec::RailsApp::Artifact::Matchers::HaveArtifacts, RSpec::RailsApp::ArtifactFile::Matchers::HaveRailsArtifactFile, RSpec::RailsApp::ArtifactFile::Matchers::HaveRailsArtifactFiles
Defined in:
lib/rails_app_spec/matchers/artifact/shared/artifact_file_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



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

def action
  @action
end

#artifact_nameObject (readonly)

Returns the value of attribute artifact_name.



10
11
12
# File 'lib/rails_app_spec/matchers/artifact/shared/artifact_file_helper.rb', line 10

def artifact_name
  @artifact_name
end

#artifact_typeObject (readonly)

Returns the value of attribute artifact_type.



10
11
12
# File 'lib/rails_app_spec/matchers/artifact/shared/artifact_file_helper.rb', line 10

def artifact_type
  @artifact_type
end

#folderObject (readonly)

Returns the value of attribute folder.



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

def folder
  @folder
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/rails_app_spec/matchers/artifact/shared/artifact_file_helper.rb', line 10

def name
  @name
end

#namesObject (readonly)

Returns the value of attribute names.



12
13
14
# File 'lib/rails_app_spec/matchers/artifact/shared/artifact_file_helper.rb', line 12

def names
  @names
end

#root_pathObject (readonly)

Returns the value of attribute root_path.



12
13
14
# File 'lib/rails_app_spec/matchers/artifact/shared/artifact_file_helper.rb', line 12

def root_path
  @root_path
end

#view_extObject (readonly)

Returns the value of attribute view_ext.



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

def view_ext
  @view_ext
end

Instance Method Details

#failure_messageObject



60
61
62
# File 'lib/rails_app_spec/matchers/artifact/shared/artifact_file_helper.rb', line 60

def failure_message
  "Expected #{msg}"
end

#get_artifact_nameObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rails_app_spec/matchers/artifact/shared/artifact_file_helper.rb', line 42

def get_artifact_name
  case artifact_type
  when :view
    path = send(:view_file_name, folder, artifact_name) #, 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
end

#get_view_ext(ext) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/rails_app_spec/matchers/artifact/shared/artifact_file_helper.rb', line 31

def get_view_ext(ext)
  case ext.to_sym
  when :erb
    'erb.html'
  when :haml
    'haml.html'
  else
    ext.to_s
  end
end

#handle_view(artifact_type, names) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/rails_app_spec/matchers/artifact/shared/artifact_file_helper.rb', line 22

def handle_view artifact_type, names
  if artifact_type == :view
    lang_option = last_arg({:lang => 'erb.html'}, names)
    raise ArgumentException, ':folder option must be specified in the last hash argument for #have_views' if !lang_option[:folder]          
    @folder = lang_option[:folder]
    @view_ext = get_view_ext(lang_option[:lang] || :erb)        
  end
end

#msgObject



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

def msg
  "the #{artifact_type} #{artifact_name} to exist"
end

#negative_failure_messageObject



64
65
66
# File 'lib/rails_app_spec/matchers/artifact/shared/artifact_file_helper.rb', line 64

def negative_failure_message
  "Did not expect #{msg}"
end

#set_view(name) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/rails_app_spec/matchers/artifact/shared/artifact_file_helper.rb', line 14

def set_view name
  view_options  = name
  @folder   = view_options[:folder]
  @action   = view_options[:action] 
  @view_ext = view_options[:view_ext] 
  @artifact_type = :view
end