lib/cucumber/chef/test_runner.rb in cucumber-chef-1.0.3 vs lib/cucumber/chef/test_runner.rb in cucumber-chef-2.0.0.pre
- old
+ new
@@ -1,32 +1,103 @@
+################################################################################
+#
+# Author: Stephen Nelson-Smith <stephen@atalanta-systems.com>
+# Author: Zachary Patten <zachary@jovelabs.com>
+# Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
+# License: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+################################################################################
+
module Cucumber
module Chef
- class TestRunnerError < Error ; end
+ class TestRunnerError < Error; end
+
class TestRunner
- require 'cucumber/chef/test_lab'
+################################################################################
- def initialize(project_dir, config)
- @project_dir = project_dir
- @config = config
+ def initialize(features_path, stdout=STDOUT, stderr=STDERR, stdin=STDIN)
+ @features_path = features_path
+ @stdout, @stderr, @stdin = stdout, stderr, stdin
+ @stdout.sync = true if @stdout.respond_to?(:sync=)
+
+ @test_lab = Cucumber::Chef::TestLab.new(@stdout, @stderr, @stdin)
+
+ @ssh = Cucumber::Chef::SSH.new(@stdout, @stderr, @stdin)
+ @ssh.config[:host] = @test_lab.labs_running.first.public_ip_address
+ @ssh.config[:ssh_user] = "ubuntu"
+ @ssh.config[:identity_file] = Cucumber::Chef.locate(:file, ".cucumber-chef", "id_rsa-#{@ssh.config[:ssh_user]}")
+
+ @stdout.puts("Cucumber-Chef Test Runner Initalized!")
end
- def run
+################################################################################
+
+ def run(destroy, *args)
+ reset_project
upload_project
- @project_path = File.join('/home/ubuntu', File.basename(@project_dir), 'features')
- connection = Net::SSH.start(@hostname, 'ubuntu', :keys => @key) do |ssh|
- @output = ssh.exec!("sudo cucumber #{@project_path}")
+
+ @stdout.puts("Executing Cucumber-Chef Test Runner")
+ remote_path = File.join("/", "home", "ubuntu", "features")
+ cucumber_options = args.flatten.compact.uniq.join(" ")
+ env = ( destroy ? "DESTROY=1" : nil )
+ command = [ "cd #{remote_path}", "&&", "sudo", env, "cucumber", cucumber_options, "--exclude support/roles", "--exclude support/data_bags", "--exclude support/keys", "." ].flatten.compact.join(" ")
+
+ @ssh.exec(command)
+ end
+
+
+################################################################################
+ private
+################################################################################
+
+ def reset_project
+ @stdout.print("Cleaning up any previous test runs...")
+ Cucumber::Chef.spinner do
+ remote_path = File.join("/", "home", "ubuntu", "features")
+
+ command = "rm -rf #{remote_path}"
+ @ssh.exec(command, :silence => true)
end
- puts @output
+ @stdout.print("done.\n")
end
+################################################################################
+
def upload_project
- lab = Cucumber::Chef::TestLab.new(@config)
- @hostname = lab.public_hostname
- @key = File.expand_path(@config[:knife][:identity_file])
- %x[scp -r -i #{@key} #{@project_dir} ubuntu@#{@hostname}: 2>/dev/null]
- puts "Cucumber-chef project: #{File.basename(@project_dir)} sucessfully uploaded to the test lab."
+ @stdout.print("Uploading files required for this test run...")
+ Cucumber::Chef.spinner do
+ local_path = File.join(@features_path)
+ remote_path = File.join("/", "home", "ubuntu", "features")
+ @ssh.upload(local_path, remote_path)
+
+ root_path = Cucumber::Chef.locate_parent(".chef")
+ cucumber_config_file = File.expand_path(File.join(root_path, "cucumber.yml"))
+ if File.exists?(cucumber_config_file)
+ remote_file = File.join(remote_path, File.basename(cucumber_config_file))
+ @ssh.upload(cucumber_config_file, remote_file)
+ end
+ end
+ @stdout.print("done.\n")
end
+
+################################################################################
+
end
+
end
end
+
+################################################################################