Sha256: 0e3a799feff8acae6861a69c9f9009b38a0ee8e2741afa288837eac1754314ae

Contents?: true

Size: 937 Bytes

Versions: 2

Compression:

Stored size: 937 Bytes

Contents

module RSpec::Rails
  module Controller     
    include RSpec::Rails::App
        
    def create_controller name, content=nil
      file = controller_file_name(name)
      unless File.exist?(file)    
        FileUtils.mkdir_p File.dirname(file)
        content ||= yield if block_given?          
        File.open(file, 'w') do |f|  
          f.puts controller_content(name, content)
        end
      end
    end  

    def controller_content name, content=nil
      %Q{class #{name.to_s.camelize}Controller < ActionController::Base
        #{content}
      end}        
    end

    def remove_controller name
      file = controller_file_name(name)
      FileUtils.rm_f(file) if File.exist?(file)
    end

    def remove_controllers *names
      names.each{|name| remove_controller name }
    end     
    
    def controller_file_name name
      File.join(controller_dir, "#{name}_controller.rb")
    end        
    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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