Module: Integra::Commands

Extended by:
Commands
Included in:
Commands
Defined in:
lib/integra/commands.rb

Instance Method Summary collapse

Instance Method Details

#init(options) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/integra/commands.rb', line 17

def init(options)
  require 'fileutils'

  if (app_host = options[:args].first)
    Integra.config.app_host = self.build_url(app_host)
  end

  # Create '.integra' file.
  ['integra', 'rspec'].each do |file|
    File.open(File.expand_path("./.#{file}"), 'w+') do |f|
      data = open("#{Integra.gem_libdir}/template/#{file}").read
      #
      # replace config variables
      #
      data.gsub!('{lang}', Integra.config.lang.to_s)
      data.gsub!('{app_host}', Integra.config.app_host.to_s)
      f.write(data)
    end
    Integra.logger.action('create', ".#{file}")
  end

  # Create 'features' and 'support' directories
  FileUtils.mkdir_p(File.expand_path('./features/support/'))
  FileUtils.mkdir_p(File.expand_path('./features/reports/'))
  Integra.logger.action('create', 'features/reports/')

  # Sample feature
  FileUtils.cp(Integra.gem_libdir + "/template/i18n/sample.#{Integra.config.lang}.feature", File.expand_path('./features/sample.feature'))
  Integra.logger.action('create', 'features/sample.feature')

  support_dest = 'features/support/'
  Dir.glob(Integra.gem_libdir + "/template/features/support/*.rb").each do |source|
    unless File.exists?(File.expand_path("#{support_dest}#{File.basename(source)}"))
      FileUtils.cp(source, File.expand_path(support_dest))
      Integra.logger.action('create', "#{support_dest}#{File.basename(source)}")
    end
  end
end

#run(options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/integra/commands.rb', line 5

def run(options)
  Integra.logger.log("Running: #{Integra.config.app_host}", :green)

  #
  # simulate rspec command call for rspec autorun
  #
  $0 = "rspec"
  ARGV.concat options[:args]

  require 'integra/autorun'
end