Module: RSpec::Rails::Helper

Defined in:
lib/rspec_for_generators/rails_helpers/rails_helper.rb

Instance Method Summary collapse

Instance Method Details

#create_helper(name, content = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/rspec_for_generators/rails_helpers/rails_helper.rb', line 3

def create_helper name, content=nil
  file =  helper_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 helper_content(name, content)
    end
  end
end

#helper_content(name, content = nil) ⇒ Object



14
15
16
17
18
# File 'lib/rspec_for_generators/rails_helpers/rails_helper.rb', line 14

def helper_content name, content=nil
  %Q{class #{name.to_s.camelize}Helper
  #{content}
end}        
end

#remove_helper(name) ⇒ Object



20
21
22
23
# File 'lib/rspec_for_generators/rails_helpers/rails_helper.rb', line 20

def remove_helper name
  file = helper_file_name(name)
  FileUtils.rm_f(file) if File.exist?(file)
end

#remove_helpers(*names) ⇒ Object



25
26
27
# File 'lib/rspec_for_generators/rails_helpers/rails_helper.rb', line 25

def remove_helpers *names
  names.each{|name| remove_helper name }
end