Class: HuginnAgent::SpecRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/huginn_agent/spec_runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSpecRunner

Returns a new instance of SpecRunner.



7
8
9
10
# File 'lib/huginn_agent/spec_runner.rb', line 7

def initialize
  @gem_name = File.basename(Dir['*.gemspec'].first, '.gemspec')
  $stdout.sync = true
end

Instance Attribute Details

#gem_nameObject (readonly)

Returns the value of attribute gem_name.



5
6
7
# File 'lib/huginn_agent/spec_runner.rb', line 5

def gem_name
  @gem_name
end

Instance Method Details

#bundleObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/huginn_agent/spec_runner.rb', line 32

def bundle
  if File.exists?('.env')
    shell_out "cp .env spec/huginn"
  end
  Dir.chdir('spec/huginn') do
    if !File.exists?('.env')
      shell_out "cp .env.example .env"
    end
    shell_out "bundle install --without development production -j 4", 'Installing ruby gems ...'
  end

end

#cloneObject



12
13
14
15
16
# File 'lib/huginn_agent/spec_runner.rb', line 12

def clone
  unless File.exists?('spec/huginn/.git')
    shell_out "git clone #{HuginnAgent.remote} -b #{HuginnAgent.branch} spec/huginn", 'Cloning huginn source ...'
  end
end

#databaseObject



45
46
47
48
49
# File 'lib/huginn_agent/spec_runner.rb', line 45

def database
  Dir.chdir('spec/huginn') do
    shell_out('bundle exec rake db:create db:migrate', 'Creating database ...')
  end
end

#patchObject



24
25
26
27
28
29
30
# File 'lib/huginn_agent/spec_runner.rb', line 24

def patch
  Dir.chdir('spec/huginn') do
    open('Gemfile', 'a') do |f|
      f.puts File.read(File.join(__dir__, 'patches/gemfile_helper.rb'))
    end
  end
end

#resetObject



18
19
20
21
22
# File 'lib/huginn_agent/spec_runner.rb', line 18

def reset
  Dir.chdir('spec/huginn') do
    shell_out "git fetch && git reset --hard origin/#{HuginnAgent.branch}", 'Resetting Huginn source ...'
  end
end

#shell_out(command, message = nil, streaming_output = false) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/huginn_agent/spec_runner.rb', line 57

def shell_out(command, message = nil, streaming_output = false)
  print message if message

  (status, output) = Bundler.with_clean_env do
    ENV['ADDITIONAL_GEMS'] = "#{gem_name}(path: ../../)"
    ENV['RAILS_ENV'] = 'test'
    if streaming_output
      HuginnAgent::Helper.exec(command)
    else
      HuginnAgent::Helper.open3(command)
    end
  end

  if status == 0
    puts "\e[32m [OK]\e[0m" if message
  else
    puts "\e[31m [FAIL]\e[0m" if message
    puts "Tried executing '#{command}'"
    puts output
    fail
  end
end

#specObject



51
52
53
54
55
# File 'lib/huginn_agent/spec_runner.rb', line 51

def spec
  Dir.chdir('spec/huginn') do
    shell_out "bundle exec rspec -r #{File.join(__dir__, 'patches/coverage.rb')} --pattern '../**/*_spec.rb' --exclude-pattern './spec/**/*_spec.rb'", 'Running specs ...', true
  end
end