Class: XamarinTestCloud::CalabashVersionDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/xamarin-test-cloud/calabash_version_detector.rb

Overview

A class for determining the Calabash version.

Finding the calabash version is required because:

  1. The correct Android test server needs to be identified.

  2. If a Gemfile does exist, a default one needs to be created.

If a Gemfile and Gemfile.lock exists, use bundler to try to find the version.

Otherwise, shell out to the gem's version command.

Callers of `version` should rescue RuntimeError and re-raise.

ArgumentError should not be caught. This is an internal class; ArgumentError represent incorrect usage.

Instance Method Summary collapse

Constructor Details

#initialize(workspace, gem_keyword) ⇒ CalabashVersionDetector

Returns a new instance of CalabashVersionDetector.


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/xamarin-test-cloud/calabash_version_detector.rb', line 21

def initialize(workspace, gem_keyword)
  @workspace = workspace

  if !File.directory?(workspace)
    raise(ArgumentError, "Workspace must be a directory that exists")
  end

  case gem_keyword
    when :android
      @gem_name = "calabash-android"
      @version_path = "calabash-android/version"
      @version_constant = "Calabash::Android::VERSION"
    when :ios
      @gem_name = "calabash-cucumber"
      @version_path = "calabash-cucumber/version"
      @version_constant = "Calabash::Cucumber::VERSION"
    when :calabash
      @gem_name = "calabash"
      @version_path = "calabash/version"
      @version_constant = "Calabash::VERSION"
    else
      raise(ArgumentError,
            %Q[Invalid gem_keyword: '#{gem_keyword}'; expected :android, :ios, or :calabash])
  end
end

Instance Method Details

#inspectObject


51
52
53
# File 'lib/xamarin-test-cloud/calabash_version_detector.rb', line 51

def inspect
  to_s
end

#to_sObject


47
48
49
# File 'lib/xamarin-test-cloud/calabash_version_detector.rb', line 47

def to_s
  %Q[#<CalabashVersion: #{workspace} #{gem_name} #{version_path} #{version_constant}>]
end

#versionObject


55
56
57
58
59
60
61
62
# File 'lib/xamarin-test-cloud/calabash_version_detector.rb', line 55

def version
  if use_bundler?
    version = detect_version_with_bundler
  else
    version = detect_version_with_ruby
  end
  version
end