Class: Qor::Test::CLI
- Inherits:
-
Object
- Object
- Qor::Test::CLI
- Defined in:
- lib/qor_test/cli.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#scripts ⇒ Object
Returns the value of attribute scripts.
Class Method Summary collapse
Instance Method Summary collapse
- #gemfile ⇒ Object
- #gemfiles ⇒ Object
-
#initialize(options = {}) ⇒ CLI
constructor
A new instance of CLI.
- #rubies ⇒ Object
- #run ⇒ Object
- #run_with_gemfile(file) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ CLI
Returns a new instance of CLI.
9 10 11 12 |
# File 'lib/qor_test/cli.rb', line 9 def initialize(={}) self. = self.scripts = [] end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/qor_test/cli.rb', line 7 def @options end |
#scripts ⇒ Object
Returns the value of attribute scripts.
7 8 9 |
# File 'lib/qor_test/cli.rb', line 7 def scripts @scripts end |
Class Method Details
.copy_sample_configuration ⇒ Object
73 74 75 76 77 |
# File 'lib/qor_test/cli.rb', line 73 def self.copy_sample_configuration FileUtils.mkdir_p(File.dirname(Qor::Test::Configuration.config_path)) FileUtils.cp(Qor::Test::Configuration.sample_file, Qor::Test::Configuration.config_path) puts("Copied sample configuration to #{Qor::Test::Configuration.config_path}!") end |
.temp_directory ⇒ Object
68 69 70 71 |
# File 'lib/qor_test/cli.rb', line 68 def self.temp_directory tempfile = Tempfile.new('fake') File.dirname(tempfile.path) end |
Instance Method Details
#gemfile ⇒ Object
14 15 16 |
# File 'lib/qor_test/cli.rb', line 14 def gemfile @gemfile ||= Qor::Test::Gemfile.new() end |
#gemfiles ⇒ Object
18 19 20 |
# File 'lib/qor_test/cli.rb', line 18 def gemfiles @gemfiles ||= gemfile.generate_gemfiles.reverse end |
#rubies ⇒ Object
22 23 24 |
# File 'lib/qor_test/cli.rb', line 22 def rubies gemfile.ruby_versions end |
#run ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/qor_test/cli.rb', line 26 def run rubies.map do |version| scripts << Qor::Test::Rubies.switch_ruby_version(version) gemfiles.map { |file| run_with_gemfile(file) } end rescue Qor::Dsl::ConfigurationNotFound puts "ConfigurationNotFound, please run `qor_test --init` in project's root to get a sample configuration" end |
#run_with_gemfile(file) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/qor_test/cli.rb', line 35 def run_with_gemfile(file) $case_num += 1 scripts << "echo -n '\n\e[01;31m[ENV #{gemfile.group_name}] \e[0m'" unless gemfile.group_name.nil? scripts << "echo -n '\e[31mRunning case #{$case_num} with '$(ruby -v)', '$[$total_cases_num-#{$case_num}]' cases left\e[0m\n'" lock_file = "#{file}.lock" temp_file = "QorTest_" + File.basename(file) temp_lock = "#{temp_file}.lock" # Copy Gemfile and Gemfile.lock if exist scripts << "cp '#{file}' '#{temp_file}'" scripts << "[ -f '#{lock_file}' ] && cp '#{lock_file}' '#{temp_lock}'" # Export Gemfile scripts << "echo '>> BUNDLE_GEMFILE=#{file}'" scripts << "export BUNDLE_GEMFILE=#{temp_file}" # Test commands [ "bundle install --quiet", "#{[:command].sub(/^(bundle\s+exec\s+)?/, 'bundle exec ')} && pass_cases_num=$(($pass_cases_num+1)) || failed_cases=(\"${failed_cases[@]}\" \"RUBY_VERSION:$(ruby -v | sed 's/ /-/g') #{file}\")" ].map do |command| scripts << "echo '>> #{command.sub(/ && .*$/,'')}'" scripts << command unless [:pretend] end # Backup & Cleanup scripts << "[ -f '#{temp_lock}' ] && cp '#{temp_lock}' '#{lock_file}'" [temp_file, temp_lock].map do |file| scripts << "[ -f '#{file}' ] && rm '#{file}'" end end |