class Cuesmash::Setup

Public Class Methods

setup() click to toggle source

Run the command line programs to setup appium. Based on steps from appium.io/slate/en/tutorial/ios.html?ruby#install-ruby

# File lib/cuesmash/setup.rb, line 16
def setup
  install_cucumber
  create_features_dir
  create_env_rb
  install_appium_console
  install_brew
  install_node
  create_travis_yml
  create_scripts_dir
  create_build_sh
  create_gemfile
  create_cuesmash_yml
end

Private Class Methods

command_runner(command:) click to toggle source

Run the command line

@param command [String] The command line statement to run

# File lib/cuesmash/setup.rb, line 98
def command_runner(command:)
  status = nil
  Logger.info "Starting: #{command}"
  Open3.popen3 command do |_stdin, out, err, wait_thr|
    [out, err].each do |stream|
      Thread.new do
        until (line = stream.gets).nil?
          Logger.info line
        end # until
      end # Thread.new
    end # each
    wait_thr.join
    status = wait_thr.value.exitstatus
  end # Open3

  if status != 0
    Logger.info "Command failed: #{command}"
    exit status
  else
    Logger.info "Finished: #{command}"
  end
end
create_build_sh() click to toggle source
# File lib/cuesmash/setup.rb, line 81
def create_build_sh
  download_gist(gist_id: '8df9762a103c694f5773', final_file: 'scripts/build.sh')
end
create_cuesmash_yml() click to toggle source
# File lib/cuesmash/setup.rb, line 89
def create_cuesmash_yml
  download_gist(gist_id: '788fd566f970703e772b', final_file: '.cuesmash.yml')
end
create_env_rb() click to toggle source

TODO: check if this file exists already. If so ask if you want to overwrite it.

# File lib/cuesmash/setup.rb, line 50
def create_env_rb
  download_gist(gist_id: '9fa5e495758463ee5340', final_file: 'features/support/env.rb')
end
create_features_dir() click to toggle source

TODO: check if these exist already

# File lib/cuesmash/setup.rb, line 45
def create_features_dir
  command_runner(command: 'mkdir -p features/{support,step_definitions}')
end
create_gemfile() click to toggle source
# File lib/cuesmash/setup.rb, line 85
def create_gemfile
  download_gist(gist_id: 'a5a689b072f0b69ec231', final_file: 'Gemfile')
end
create_scripts_dir() click to toggle source
# File lib/cuesmash/setup.rb, line 76
def create_scripts_dir
  puts 'creating scripts dir'
  command_runner(command: 'mkdir -p scripts')
end
create_travis_yml() click to toggle source
# File lib/cuesmash/setup.rb, line 72
def create_travis_yml
  download_gist(gist_id: '74cc418331bd81651746', final_file: '.travis.yml')
end
download_gist(gist_id:, final_file:) click to toggle source

Download gists files without git. @param gist_id: [String] the gist id @param final_file: [String] where the final file gets saved in relationship to the directory where the script is run.

# File lib/cuesmash/setup.rb, line 126
def download_gist(gist_id:, final_file:)
  base_url = URI('https://api.github.com/gists/')
  json = JSON.parse(RestClient.get(URI.join(base_url, gist_id).to_s))
  file_name = json['files'].keys[0]
  raw_url = json['files'][file_name]['raw_url']

  open(final_file, 'wb') do |file|
    file << open(raw_url).read
  end
end
install_appium_console() click to toggle source

TODO: this is failing.

# File lib/cuesmash/setup.rb, line 55
def install_appium_console
  command_runner(command: 'gem install --no-rdoc --no-ri appium_console')
end
install_brew() click to toggle source
# File lib/cuesmash/setup.rb, line 59
def install_brew
  brew_path = `which brew`
  if brew_path == 0
    command_runner(command: "ruby -e \"$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)\"")
  else
    Logger.info 'Brew already installed.'
  end
end
install_cucumber() click to toggle source

Honestly all of these should be self evident as to what they do. If you still can't figure it ou come find me and I'll beat you with a ruby hammer.

# File lib/cuesmash/setup.rb, line 40
def install_cucumber
  command_runner(command: 'gem install --no-rdoc --no-ri cucumber')
end
install_node() click to toggle source
# File lib/cuesmash/setup.rb, line 68
def install_node
  command_runner(command: 'brew update; brew upgrade node; brew install node')
end