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



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

def bundle
  if File.exists?('.env')
    shell_out "cp .env spec/huginn"
  end
  Dir.chdir('spec/huginn') do
    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



34
35
36
37
38
# File 'lib/huginn_agent/spec_runner.rb', line 34

def database
  Dir.chdir('spec/huginn') do
    shell_out('bundle exec rake db:create db:migrate', 'Creating database ...')
  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



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/huginn_agent/spec_runner.rb', line 46

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'
    HuginnAgent::Helper.open3(command, streaming_output)
  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



40
41
42
43
44
# File 'lib/huginn_agent/spec_runner.rb', line 40

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