Class: Cpspec::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/cpspec/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Middleware

Returns a new instance of Middleware.



3
4
5
6
# File 'lib/cpspec/middleware.rb', line 3

def initialize(app, env)
  @app = app
  @env = env
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cpspec/middleware.rb', line 8

def call(env)
  files = Dir.glob("test/*.rb")
  if env["vm"].created? && env["vm"].vm.running?
    files.each do |file|
      command = "ruby /vagrant/#{file}".strip

      env["vm"].ssh.execute do |ssh|
        env.ui.info "Running Test: #{file}"

        ssh.exec!("#{command}") do |channel, type, data|
          $stdout.print(data) if type != :exit_status
        end
        $stdout.puts
      end
    end
  end
  @app.call(env)
end