Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retina support #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ rescue LoadError
end
end

begin
require 'spec/rake/spectask'

desc "Run all examples"
Spec::Rake::SpecTask.new(:spec) do |t|
t.spec_files = FileList['spec/**/*.rb']
end
rescue
desc "Run all examples (not available)"
task :spec do
abort "Rspec is not available. In order to run specs, you must: sudo gem install rspec"
end
end

task :default => :features

require 'rake/rdoctask'
Expand Down
3 changes: 2 additions & 1 deletion lib/icuke/icuke_world.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def icuke_configuration
icuke_driver.quit
end

Given /^(?:"([^\"]*)" from )?"([^\"]*)"(?: with build configuration "([^\"]*)")? is loaded in the (?:(iphone|ipad) )?simulator(?: with SDK ([0-9.]+))?$/ do |target, project, configuration, platform, sdk_version|
Given /^(?:"([^\"]*)" from )?"([^\"]*)"(?: with build configuration "([^\"]*)")? is loaded in the (?:(retina|non-retina) )?(?:(iphone|ipad) )?simulator(?: with SDK ([0-9.]+))?$/ do |target, project, configuration, retina, platform, sdk_version|
if sdk_version
ICuke::SDK.use(sdk_version)
elsif platform
Expand All @@ -33,6 +33,7 @@ def icuke_configuration
'DYLD_INSERT_LIBRARIES' => ICuke::SDK.dylib_fullpath
}
}
attrs.merge!(:retina => !(retina =~ /non/)) if retina
attrs.merge!(:build_configuration => configuration) if configuration
icuke_driver.launch(File.expand_path(project), attrs)
end
Expand Down
30 changes: 30 additions & 0 deletions lib/icuke/waxsim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ def launch(process)
'CFFIXED_USER_HOME' => Dir.mktmpdir
}
})

process.setup_commands.each do |cmd|
fail "Unable to run setup command #{cmd}" if !system(cmd)
fail "Setup command #{cmd} failed with exit status #{$?}" if $? != 0
end

@simulator = BackgroundProcess.run(process.command)
self.current_process = process

Expand Down Expand Up @@ -54,12 +60,36 @@ def initialize(project_file, launch_options = {})
def with_options(options = {})
self.class.new(@project_file, options.merge(@launch_options))
end

def setup_commands
cmds = []
cmds << simulate_device_command if @launch_options.has_key?(:retina)
cmds
end

def command
ICuke::SDK.launch("#{directory}/#{target}.app", @launch_options[:platform], @launch_options[:env])
end

private

def simulate_device_command
"defaults write com.apple.iphonesimulator SimulateDevice '\"#{simulate_device}\"'"
end

def simulate_device
case @launch_options[:platform]
when :ipad
"iPad"
else
"iPhone"
end +
if @launch_options[:retina]
" (Retina)"
else
""
end
end

def target
@launch_options[:target] || File.basename(@project_file, '.xcodeproj')
Expand Down
8 changes: 5 additions & 3 deletions spec/cucumber_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
require 'icuke/cucumber'
require 'icuke/simulate'


describe ICukeWorld do

before(:each) do
@simulator = []
@simulator.stub(:view)
@simulator.stub(:fire_event)
ICuke::Simulator.should_receive(:new).and_return(@simulator)
@cuke_world = ICukeWorld.new
@cuke_world = ICuke::SimulatorDriver.new @simulator, ICuke::Configuration.new({
:build_configuration => 'Debug'
})
@cuke_world.stub!(:sleep)

xml = File.read('spec/fixtures/controls_page.xml')
@cuke_world.stub(:response).and_return(xml)

end

context "when performing a swipe" do
Expand Down
38 changes: 38 additions & 0 deletions spec/process_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'spec/spec_helper'
require 'icuke/waxsim'

describe ICuke::Simulator::Process do

it "should provide a list of commands necessary to set up the environment" do
p = ICuke::Simulator::Process.new('foo', {})
p.should respond_to(:setup_commands)
p.setup_commands.should be_kind_of(Array)
end

it "should not provide a defaults command when retina is not specified" do
found = ICuke::Simulator::Process.new('foo', {}).setup_commands.detect {|c| c =~ /^defaults/}
found.should be_nil
end

it "should set SimulateDevice to \"iPhone (Retina)\" if platform is iPhone and retina is required" do
attrs = {:platform => :iphone, :retina => true}
found = ICuke::Simulator::Process.new('foo', attrs).setup_commands.detect {|c| c =~ /^defaults/}
found.should_not be_nil
found.should == "defaults write com.apple.iphonesimulator SimulateDevice '\"iPhone (Retina)\"'"
end

it "should set SimulateDevice to \"iPhone\" if platform is iPhone and retina is rejected" do
attrs = {:platform => :iphone, :retina => false}
found = ICuke::Simulator::Process.new('foo', attrs).setup_commands.detect {|c| c =~ /^defaults/}
found.should_not be_nil
found.should == "defaults write com.apple.iphonesimulator SimulateDevice '\"iPhone\"'"
end

it "should set SimulateDevice to \"iPad\" if platform is iPad and retina is rejected" do
attrs = {:platform => :ipad, :retina => false}
found = ICuke::Simulator::Process.new('foo', attrs).setup_commands.detect {|c| c =~ /^defaults/}
found.should_not be_nil
found.should == "defaults write com.apple.iphonesimulator SimulateDevice '\"iPad\"'"
end

end
28 changes: 28 additions & 0 deletions spec/simulator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'spec/spec_helper'
require 'icuke/waxsim'

describe ICuke::Simulator do

describe :launch do
it "should run any setup commands" do
s = ICuke::Simulator.new
s.stub(:view).and_return(nil)

p = ICuke::Simulator::Process.new('foo', {:env => {}})
f = "/tmp/command_was_run.#{$$}"
p.stub(:setup_commands).and_return(["touch #{f}"])
p.stub(:with_options).and_return(p)

BackgroundProcess.stub(:run).and_return(nil)

File.delete(f) rescue nil

ICuke::SDK.use('4.0')
s.launch(p)

File.exist?(f).should be_true
File.delete(f) rescue nil
end
end

end