Skip to content

Commit

Permalink
Merge pull request #603 from calabash/release/0.11.4
Browse files Browse the repository at this point in the history
Release/0.11.4
  • Loading branch information
jmoody committed Nov 6, 2014
2 parents 3ca939c + daae3ae commit 8985278
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 350 deletions.
3 changes: 2 additions & 1 deletion calabash-cucumber/calabash-cucumber.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Gem::Specification.new do |s|
# Match the xamarin-test-cloud dependency.
s.add_dependency('bundler', '~> 1.3')
s.add_dependency('awesome_print', '~> 1.2.0')
s.add_dependency('run_loop', '~> 1.0.10.pre1')
s.add_dependency('run_loop', '~> 1.1.0')

s.add_development_dependency 'rake', '~> 10.3'
s.add_development_dependency 'rspec', '~> 3.0'
Expand All @@ -77,4 +77,5 @@ Gem::Specification.new do |s|
s.add_development_dependency 'guard-rspec', '~> 4.3'
s.add_development_dependency 'guard-bundler', '~> 2.0'
s.add_development_dependency 'growl', '~> 1.0'
s.add_development_dependency 'stub_env', '~> 0.2'
end
140 changes: 4 additions & 136 deletions calabash-cucumber/lib/calabash-cucumber/utils/plist_buddy.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
require 'calabash-cucumber/utils/logging'
require 'run_loop'

module Calabash
module Cucumber

include Calabash::Cucumber::Logging

# @!visibility private
# A module for reading and writing property list values.
module PlistBuddy
Expand All @@ -17,16 +14,7 @@ module PlistBuddy
# @return [String] the value of the key
# @raise [ArgumentError] if nil or empty key
def plist_read(key, file, opts={})
if key.nil? or key.length == 0
raise(ArgumentError, "key '#{key}' must not be nil or empty")
end
cmd = build_plist_cmd(:print, {:key => key}, file)
res = execute_plist_cmd(cmd, opts)
if res == "Print: Entry, \":#{key}\", Does Not Exist"
nil
else
res
end
RunLoop::PlistBuddy.new.plist_read(key, file, opts)
end

# Checks if the key exists in plist.
Expand All @@ -50,128 +38,8 @@ def plist_key_exists?(key, file, opts={})
# @return [Boolean] true if the operation was successful
# @raise [ArgumentError] if nil or empty key
def plist_set(key, type, value, file, opts={})
default_opts = {:verbose => false}
merged = default_opts.merge(opts)

if key.nil? or key.length == 0
raise(ArgumentError, "key '#{key}' must not be nil or empty")
end

cmd_args = {:key => key,
:type => type,
:value => value}

if plist_key_exists?(key, file, merged)
cmd = build_plist_cmd(:set, cmd_args, file)
else
cmd = build_plist_cmd(:add, cmd_args, file)
end

res = execute_plist_cmd(cmd, merged)
res == ''
end

private

# returns the path to the PlistBuddy executable
# @return [String] path to PlistBuddy
def plist_buddy
'/usr/libexec/PlistBuddy'
RunLoop::PlistBuddy.new.plist_set(key, type, value, file, opts)
end

# Executes cmd as a shell command and returns the result.
#
# @param [String] cmd shell command to execute
# @param [Hash] opts options for controlling execution
# @option opts [Boolean] :verbose (false) controls log level
# @return [Boolean] if command was successful
# @return [String] if :print'ing result, the value of the key - if there
# is an error, the output from stderr
def execute_plist_cmd(cmd, opts={})
default_opts = {:verbose => false}
merged = default_opts.merge(opts)

calabash_info(cmd) if merged[:verbose]

res = nil
# noinspection RubyUnusedLocalVariable
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
err = stderr.read
std = stdout.read
if not err.nil? and err != ''
res = err.chomp
else
res = std.chomp
end
end
res
end

# Composes a PlistBuddy command that can be executed as a shell command.
#
# @param [Symbol] type should be one of [:print, :set, :add]
#
# @param [Hash] args_hash arguments used to construct plist command
# @option args_hash [String] :key (required) the plist key
# @option args_hash [String] :value (required for :set and :add) the new value
# @option args_hash [String] :type (required for :add) the new type of the value
#
# @param [String] file the plist file to interact with (must exist)
#
# @raise [RuntimeError] if file does not exist
# @raise [ArgumentError] when invalid type is passed
# @raise [ArgumentError] when args_hash does not include required key/value pairs
#
# @return [String] a shell-ready PlistBuddy command
def build_plist_cmd(type, args_hash, file)

unless File.exist?(File.expand_path(file))
raise(RuntimeError, "plist '#{file}' does not exist - could not read")
end

case type
when :add
value_type = args_hash[:type]
unless value_type
raise(ArgumentError, ':value_type is a required key for :add command')
end
allowed_value_types = ['string', 'bool', 'real', 'integer']
unless allowed_value_types.include?(value_type)
raise(ArgumentError, "expected '#{value_type}' to be one of '#{allowed_value_types}'")
end
value = args_hash[:value]
unless value
raise(ArgumentError, ':value is a required key for :add command')
end
key = args_hash[:key]
unless key
raise(ArgumentError, ':key is a required key for :add command')
end
cmd_part = "\"Add :#{key} #{value_type} #{value}\""
when :print
key = args_hash[:key]
unless key
raise(ArgumentError, ':key is a required key for :print command')
end
cmd_part = "\"Print :#{key}\""
when :set
value = args_hash[:value]
unless value
raise(ArgumentError, ':value is a required key for :set command')
end
key = args_hash[:key]
unless key
raise(ArgumentError, ':key is a required key for :set command')
end
cmd_part = "\"Set :#{key} #{value}\""
else
cmds = [:add, :print, :set]
raise(ArgumentError, "expected '#{type}' to be one of '#{cmds}'")
end

"#{plist_buddy} -c #{cmd_part} \"#{file}\""
end

end
end
end
end
11 changes: 10 additions & 1 deletion calabash-cucumber/lib/calabash-cucumber/utils/xctools.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
require 'open3'
require 'run_loop'

module Calabash
module Cucumber

# @deprecated 0.11.4 Replaced with RunLoop::XCTools.
# @!visibility private
# Methods for interacting with the xcode tools.
module XcodeTools

# @deprecated 0.11.4 Replaced with RunLoop::XCTools.
# Returns the path to the current developer directory.
#
# From the man pages:
Expand All @@ -22,6 +23,7 @@ module XcodeTools
#
# @return [String] path to current developer directory
def xcode_developer_dir
_deprecated('0.11.4', 'Use RunLoop::XCTools', :warn)
RunLoop::XCTools.new.xcode_developer_dir
end

Expand All @@ -33,6 +35,7 @@ def xcode_bin_dir
File.expand_path("#{xcode_developer_dir}/usr/bin")
end

# @deprecated 0.11.4 Replaced with RunLoop::XCTools.
# Method for interacting with instruments.
#
# @example Getting the path to instruments.
Expand All @@ -54,15 +57,18 @@ def instruments(cmd=nil)
return instruments if cmd == nil
case cmd
when :version
_deprecated('0.11.4', 'Use RunLoop::XCTools', :warn)
RunLoop::XCTools.new.instruments(cmd).to_s
when :sims
_deprecated('0.11.4', 'Use RunLoop::XCTools', :warn)
RunLoop::XCTools.new.instruments(cmd)
else
candidates = [:version, :sims]
raise(ArgumentError, "expected '#{cmd}' to be one of '#{candidates}'")
end
end

# @deprecated 0.11.4 Replaced with RunLoop::XCTools.
# Does the instruments `version` accept the -s flag?
#
# @example
Expand All @@ -75,16 +81,19 @@ def instruments(cmd=nil)
#
# @return [Boolean] true if the version is >= 5.*
def instruments_supports_hyphen_s?(version)
_deprecated('0.11.4', 'Use RunLoop::XCTools', :warn)
RunLoop::XCTools.new.instruments_supports_hyphen_s?(version)
end

# @deprecated 0.11.4 Replaced with RunLoop::XCTools.
# Returns a list of installed simulators by calling `$ instruments -s devices`.
# and parsing the output
# @return [Array<String>] an array of simulator names suitable for passing
# to instruments or xcodebuild
# @raise [RuntimeError] if the currently active instruments version does
# not support the -s flag
def installed_simulators
_deprecated('0.11.4', 'Use RunLoop::XCTools', :warn)
instruments(:sims)
end
end
Expand Down
4 changes: 2 additions & 2 deletions calabash-cucumber/lib/calabash-cucumber/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module Cucumber

# @!visibility public
# The Calabash iOS gem version.
VERSION = '0.11.4.pre2'
VERSION = '0.11.4'

# @!visibility public
# The minimum required version of the calabash.framework or, for Xamarin
# users, the Calabash component.
MIN_SERVER_VERSION = '0.11.4.pre2'
MIN_SERVER_VERSION = '0.11.4'
end
end
10 changes: 1 addition & 9 deletions calabash-cucumber/spec/integration/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,25 @@ class CoreIncluded
ENV.delete('DEVELOPER_DIR')
ENV.delete('DEBUG')
ENV.delete('DEVICE_ENDPOINT')
ENV.delete('DEVICE_TARGET')
RunLoop::SimControl.terminate_all_sims
}

after(:example) {
ENV.delete('DEVELOPER_DIR')
ENV.delete('DEBUG')
ENV.delete('DEVICE_ENDPOINT')
ENV.delete('DEVICE_TARGET')
}

describe '#calabash_exit' do
describe 'targeting simulators' do
let(:launcher) { Calabash::Cucumber::Launcher.new }
let(:core_instance) { CoreIncluded.new }
it "Xcode #{Resources.shared.current_xcode_version}" do
device_target = 'simulator'
if Resources.shared.travis_ci?
if Resources.shared.current_xcode_version >= RunLoop::Version.new('6.0')
device_target = 'iPad Air (8.0 Simulator)'
end
end
sim_control = RunLoop::SimControl.new
options =
{
:app => Resources.shared.app_bundle_path(:lp_simple_example),
:device_target => device_target,
:device_target => 'simulator',
:sim_control => sim_control,
:launch_retries => Resources.shared.travis_ci? ? 5 : 2
}
Expand Down
4 changes: 2 additions & 2 deletions calabash-cucumber/spec/integration/launcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
let(:fake_udid) { 'FAKE-UDID' }
describe 'reset_simulator' do
context 'when running on a device' do
before { ENV['DEVICE_TARGET'] = fake_udid }
it 'raises an error' do
stub_env('DEVICE_TARGET', fake_udid)
expect { launcher.reset_simulator }.to raise_error(RuntimeError)
end
end

context 'when running on the simulator' do
before { ENV.delete('DEVICE_TARGET') }
it 'successfully resets the simulator' do
stub_env('DEVICE_TARGET', nil)
launcher.reset_simulator
end
end
Expand Down
4 changes: 1 addition & 3 deletions calabash-cucumber/spec/integration/reset_app_sandbox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,13 @@ def path_to_containers(udid, simulator)
before(:example) {
ENV.delete('DEVELOPER_DIR')
ENV.delete('DEBUG')
ENV.delete('DEVICE_TARGET')
RunLoop::SimControl.terminate_all_sims
}

after(:example) {
ENV.delete('DEVELOPER_DIR')
ENV.delete('DEBUG')
ENV.delete('DEVICE_ENDPOINT')
ENV.delete('DEVICE_TARGET')
}

let(:launcher) { Calabash::Cucumber::Launcher.new }
Expand Down Expand Up @@ -283,7 +281,7 @@ def path_to_containers(udid, simulator)
udid = target_simulator.udid
it "#{instruments_launch_name} [#{udid}]" do
ENV['DEVELOPER_DIR'] = xcode6[:path]
ENV['DEVICE_TARGET'] = instruments_launch_name
stub_env('DEVICE_TARGET', instruments_launch_name)
sim_control = RunLoop::SimControl.new
helper.launch_and_stop_simulator(launcher, sim_control, instruments_launch_name)

Expand Down
53 changes: 0 additions & 53 deletions calabash-cucumber/spec/integration/xctools_spec.rb

This file was deleted.

Loading

0 comments on commit 8985278

Please sign in to comment.