Sha256: c98c8ac14a2ce6d40b79f9f3605059ad89e02281f00bd5d5e11384885754c442

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

module RSpec::Rails
  module View
    include RSpec::Rails::App    
    
    def create_view name, action='show', *args, &block
      type, content = parse_args(*args)
      file = view_file_name(name, action, type)

      # make dir
      unless File.exist?(file)    
        FileUtils.mkdir_p File.dirname(file)
      end       

      # set content to block
      content = yield if block

      # abort if no content given
      return if !content    
      
      # write file content of view
      File.open(file, 'w') do |f|  
        f.puts content 
      end
    end  

    def parse_args *args
      type='html.erb'
      content=nil       
      if args && args[0]
        case args[0]
        when String
          content = args[0]
        when Symbol
          type = args[0]
          content = args[1] if args.size > 1
        end
      end
      [type, content]
    end

    def remove_view name, action='show', type='html.erb'
      file = view_file_name(name, action, type)
      FileUtils.rm_f(file) if File.exist?(file)
    end
    
    def view_file_name name, action='show', type='html.erb'
      File.join(view_dir, name.to_s, "#{action}.#{type}")
    end        
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
generator-spec-0.4.8 lib/generator_spec/rails_helpers/rails_view.rb