Method: CapsuleCD::Ruby::RubyEngine#test_step

Defined in:
lib/capsulecd/ruby/ruby_engine.rb

#test_stepObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/capsulecd/ruby/ruby_engine.rb', line 71

def test_step
  super

  gems = Dir.glob(@source_git_local_path + '/*.gem')
  if gems.empty?
    fail CapsuleCD::Error::TestDependenciesError, 'Ruby gem file could not be found'
  end
  gem_path = gems.first

  # lets install the gem, and any dependencies
  # http://guides.rubygems.org/make-your-own-gem/
  Bundler.with_clean_env do
    Open3.popen3('gem install ./' + File.basename(gem_path) + ' --ignore-dependencies', chdir: @source_git_local_path) do |_stdin, stdout, stderr, external|
      { stdout: stdout, stderr: stderr }. each do |name, stream_buffer|
        Thread.new do
          until (line = stream_buffer.gets).nil?
            puts "#{name} -> #{line}"
          end
        end
      end
      # wait for process
      external.join
      unless external.value.success?
        fail CapsuleCD::Error::TestDependenciesError, 'gem install failed. Check gemspec and gem dependencies'
      end
    end

    Open3.popen3('bundle install', chdir: @source_git_local_path) do |_stdin, stdout, stderr, external|
      { stdout: stdout, stderr: stderr }. each do |name, stream_buffer|
        Thread.new do
          until (line = stream_buffer.gets).nil?
            puts "#{name} -> #{line}"
          end
        end
      end
      # wait for process
      external.join
      unless external.value.success?
        fail CapsuleCD::Error::TestDependenciesError, 'bundle install failed. Check Gemfile'
      end
    end

    # run test command
    test_cmd = @config.engine_cmd_test || 'rake spec'
    Open3.popen3(test_cmd, chdir: @source_git_local_path) do |_stdin, stdout, stderr, external|
      { stdout: stdout, stderr: stderr }. each do |name, stream_buffer|
        Thread.new do
          until (line = stream_buffer.gets).nil?
            puts "#{name} -> #{line}"
          end
        end
      end
      # wait for process
      external.join
      unless external.value.success?
        fail CapsuleCD::Error::TestRunnerError, test_cmd + ' failed. Check log for exact error'
      end
    end unless @config.engine_disable_test
  end
end