From 16ffa2d29f04905fdd4f022e271afc90aab67560 Mon Sep 17 00:00:00 2001 From: Karthik Chokkaram Date: Mon, 31 Jan 2011 11:32:35 -0500 Subject: [PATCH 1/3] Task to run specs --- Rakefile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Rakefile b/Rakefile index 744deac..4b4b516 100644 --- a/Rakefile +++ b/Rakefile @@ -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' From c74352ff47ca6d17e505493a09576c8658c81c64 Mon Sep 17 00:00:00 2001 From: Karthik Chokkaram Date: Mon, 31 Jan 2011 11:36:05 -0500 Subject: [PATCH 2/3] Fix specs --- spec/cucumber_spec.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/cucumber_spec.rb b/spec/cucumber_spec.rb index eb9b9cd..a800e3a 100644 --- a/spec/cucumber_spec.rb +++ b/spec/cucumber_spec.rb @@ -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 From d9bd600e226eb0bf9a7481384fad66b4b4644de7 Mon Sep 17 00:00:00 2001 From: Karthik Chokkaram Date: Mon, 31 Jan 2011 15:09:58 -0500 Subject: [PATCH 3/3] Support for starting simulator in retina mode --- lib/icuke/icuke_world.rb | 3 ++- lib/icuke/waxsim.rb | 30 ++++++++++++++++++++++++++++++ spec/process_spec.rb | 38 ++++++++++++++++++++++++++++++++++++++ spec/simulator_spec.rb | 28 ++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 spec/process_spec.rb create mode 100644 spec/simulator_spec.rb diff --git a/lib/icuke/icuke_world.rb b/lib/icuke/icuke_world.rb index 470dad4..ffc3bcd 100644 --- a/lib/icuke/icuke_world.rb +++ b/lib/icuke/icuke_world.rb @@ -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 @@ -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 diff --git a/lib/icuke/waxsim.rb b/lib/icuke/waxsim.rb index 9c7c011..70c2e1a 100644 --- a/lib/icuke/waxsim.rb +++ b/lib/icuke/waxsim.rb @@ -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 @@ -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') diff --git a/spec/process_spec.rb b/spec/process_spec.rb new file mode 100644 index 0000000..65fbd3e --- /dev/null +++ b/spec/process_spec.rb @@ -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 diff --git a/spec/simulator_spec.rb b/spec/simulator_spec.rb new file mode 100644 index 0000000..9d40540 --- /dev/null +++ b/spec/simulator_spec.rb @@ -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