class HuginnAgent::SpecRunner

Attributes

gem_name[R]

Public Class Methods

new() click to toggle source
# File lib/huginn_agent/spec_runner.rb, line 7
def initialize
  @gem_name = File.basename(Dir['*.gemspec'].first, '.gemspec')
  $stdout.sync = true
end

Public Instance Methods

bundle() click to toggle source
# 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
clone() click to toggle source
# 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
database() click to toggle source
# 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
patch() click to toggle source
# 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
reset() click to toggle source
# 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) click to toggle source
# 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
spec() click to toggle source
# 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