features/support/env.rb in mirage-1.1.0 vs features/support/env.rb in mirage-1.2.0
- old
+ new
@@ -1,18 +1,26 @@
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../../lib")
require 'rubygems'
-#require 'bundler/setup'
-#Bundler.setup(:test)
require 'mirage'
require 'cucumber'
require 'rspec'
require 'mechanize'
SCRATCH = './scratch'
RUBY_CMD = RUBY_PLATFORM == 'JAVA' ? 'jruby' : 'ruby'
+$log_file_marker = 0
+module CommandLine
+ def execute command
+ command_line_output_path = "#{SCRATCH}/commandline_output.txt"
+ system "cd #{SCRATCH} && #{command} > #{File.basename(command_line_output_path)}"
+ File.read(command_line_output_path)
+ end
+end
+
+
module Web
include Mirage::Web
def get(url)
browser = Mechanize.new
@@ -20,11 +28,11 @@
browser.get(url)
end
def hit_mirage(url, parameters={})
start_time = Time.now
- file = parameters.values.find{|value| value.is_a?(File)}
+ file = parameters.values.find { |value| value.is_a?(File) }
response = (file ? http_post(url, parameters) : http_get(url, parameters))
@response_time = Time.now - start_time
response
end
@@ -33,38 +41,40 @@
end
end
module Regression
+ include CommandLine
+
def stop_mirage
- system "export RUBYOPT='' && cd #{SCRATCH} && mirage stop"
+ system "cd #{SCRATCH} && mirage stop"
end
def start_mirage
- system "truncate mirage.log --size 0"
- system "export RUBYOPT='' && cd #{SCRATCH} && mirage start"
+ system "cd #{SCRATCH} && mirage start"
end
+
+ def run command
+ execute(command)
+ end
end
module IntelliJ
+ include CommandLine
include Mirage::Util
def stop_mirage
- system "cd #{SCRATCH} && ../bin/mirage stop"
- wait_until do
- !$mirage.running?
- end
+ system "cd #{SCRATCH} && #{RUBY_CMD} ../bin/mirage stop"
end
def start_mirage
puts "starting mirage"
- system "truncate mirage.log --size 0"
- system "cd #{SCRATCH} && ../bin/mirage start"
+ system "cd #{SCRATCH} && #{RUBY_CMD} ../bin/mirage start"
+ end
- wait_until do
- $mirage.running?
- end
+ def run command
+ execute "#{RUBY_CMD} #{command}"
end
end
'regression' == ENV['mode'] ? World(Regression) : World(IntelliJ)
'regression' == ENV['mode'] ? include(Regression) : include(IntelliJ)
@@ -72,19 +82,23 @@
World(Web)
Before do
FileUtils.mkdir_p(SCRATCH)
$mirage = Mirage::Client.new
-
if $mirage.running?
$mirage.clear
else
start_mirage
end
-
- system "cd #{SCRATCH}/ && ls | grep -v mirage.log | xargs rm -rf"
- system "truncate -s 0 #{SCRATCH}/mirage.log"
+
+ Dir["#{SCRATCH}/*"].each do |file|
+ FileUtils.rm_rf(file) unless file == "#{SCRATCH}/mirage.log"
+ end
+
+ @mirage_log_file = File.open("#{SCRATCH}/mirage.log")
+ @mirage_log_file.seek(0,IO::SEEK_END)
end
+
at_exit do
- stop_mirage
-end
+ stop_mirage if $mirage.running?
+end
\ No newline at end of file