Class: AppiumRspecSetup::Gemfile

Inherits:
Object
  • Object
show all
Defined in:
lib/appium_rspec_setup/gemfile.rb

Class Method Summary collapse

Class Method Details

.configure_gemfile_and_bundle!Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/appium_rspec_setup/gemfile.rb', line 3

def self.configure_gemfile_and_bundle!
  file_array = File.readlines('GemFile')

  insert_hash = {
      'appium_lib' => "gem 'appium_lib'",
      'rspec' => "gem 'rspec', require: 'spec'",
      'pry' => "gem 'pry'"
  }

  offset = -1

  insert_hash.each do |substring_key, line_for_file_value|
    file_array.insert(offset, line_for_file_value) unless file_array.any? do |line|
      line.include? substring_key
    end
  end

  File.open('GemFile', 'w') do |file|
    file.puts file_array
  end

  %x{bundle}
end