From 271200bc843f6bf9fcdcdb5c1b5921c9bc0af5a6 Mon Sep 17 00:00:00 2001 From: Marc Schwieterman Date: Wed, 11 Jul 2012 17:59:59 -0400 Subject: [PATCH 1/2] tag specs that fail with accessibility inspector Three of the specs in "Bacon::Functional::API, concerning continuous gestures" fail if the identity inspector is on. I'm not sure if that's fixable, but I tagged them with TODO, so it will at least be obvious why they have failed if they do. --- test/bacon-ui/spec/continuous_gestures_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/bacon-ui/spec/continuous_gestures_spec.rb b/test/bacon-ui/spec/continuous_gestures_spec.rb index 2496fabe..72ea0b84 100644 --- a/test/bacon-ui/spec/continuous_gestures_spec.rb +++ b/test/bacon-ui/spec/continuous_gestures_spec.rb @@ -38,6 +38,7 @@ end describe "Bacon::Functional::API, concerning continuous gestures" do tests ScrollViewController + # TODO this spec fails if the Accessibility Inspector is on it "creates 'pinch open' and 'pinch close' gesture events" do before = controller.scrollView.zoomScale pinch_open 'Scroll view' @@ -67,6 +68,7 @@ describe "Bacon::Functional::API, concerning continuous gestures" do pinch_open 'Scroll view' end + # TODO this spec fails if the Accessibility Inspector is on it "drags from point A to point B" do before = controller.scrollView.contentOffset drag 'Scroll view', :from => CGPointMake(310, 100), :to => CGPointMake(5, 150) @@ -74,6 +76,7 @@ describe "Bacon::Functional::API, concerning continuous gestures" do controller.scrollView.contentOffset.y.should < before.y end + # TODO this spec fails if the Accessibility Inspector is on it "drags along the specified list of points" do view = controller.scrollView before = view.contentOffset From 9045772f7678249b0f6470b8f29d00eb4ca82d29 Mon Sep 17 00:00:00 2001 From: Marc Schwieterman Date: Wed, 11 Jul 2012 23:54:53 -0400 Subject: [PATCH 2/2] storyboard support * load from MainStoryboard by default * options * :storyboard_name - name of storyboard file (without extension) * :id - identifier value of controler as set in Xcode * tests --- lib/motion/spec/helpers/ui.rb | 16 ++++++- .../resources/AlternateStoryboard.storyboard | 39 +++++++++++++++ .../resources/MainStoryboard.storyboard | 39 +++++++++++++++ test/bacon-ui/spec/storyboard_spec.rb | 47 +++++++++++++++++++ 4 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 test/bacon-ui/resources/AlternateStoryboard.storyboard create mode 100644 test/bacon-ui/resources/MainStoryboard.storyboard create mode 100644 test/bacon-ui/spec/storyboard_spec.rb diff --git a/lib/motion/spec/helpers/ui.rb b/lib/motion/spec/helpers/ui.rb index 6d447e60..e1ce1be0 100644 --- a/lib/motion/spec/helpers/ui.rb +++ b/lib/motion/spec/helpers/ui.rb @@ -169,6 +169,12 @@ module Bacon # * :tab => true def tests(controller_class, options = {}) @controller_class = controller_class + @options = { + # name of storyboard file in resources directory + :storyboard_name => 'MainStoryboard', + # id of controller as assigned in Xcode + :id => nil + }.merge(options) extend Bacon::Functional::API extend Bacon::Functional::ContextExt end @@ -213,7 +219,15 @@ module Bacon attr_accessor :controller def controller - @controller ||= @controller_class.alloc.init + @controller ||= if @options[:id] + storyboard.instantiateViewControllerWithIdentifier(@options[:id]) + else + @controller_class.alloc.init + end + end + + def storyboard + @storyboard ||= UIStoryboard.storyboardWithName(@options[:storyboard_name], bundle:nil) end end diff --git a/test/bacon-ui/resources/AlternateStoryboard.storyboard b/test/bacon-ui/resources/AlternateStoryboard.storyboard new file mode 100644 index 00000000..4da3367c --- /dev/null +++ b/test/bacon-ui/resources/AlternateStoryboard.storyboard @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/bacon-ui/resources/MainStoryboard.storyboard b/test/bacon-ui/resources/MainStoryboard.storyboard new file mode 100644 index 00000000..5b23414c --- /dev/null +++ b/test/bacon-ui/resources/MainStoryboard.storyboard @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/bacon-ui/spec/storyboard_spec.rb b/test/bacon-ui/spec/storyboard_spec.rb new file mode 100644 index 00000000..5f75c966 --- /dev/null +++ b/test/bacon-ui/spec/storyboard_spec.rb @@ -0,0 +1,47 @@ +class StoryboardViewController < UIViewController + + # The view associated with this controller in the storyboard has a single + # UILabel with an accessibility label of 'Storyboard' and a text value of + # 'Hello, Rubymotion' + + def viewDidLoad + label = UILabel.alloc.init + label.text = 'Code' + view.addSubview(label) + end + +end + +describe "Storyboard support when not used" do + tests StoryboardViewController + + it "does not load from storyboard without an id" do + labels = views(UILabel) + labels.count.should == 1 + labels.first.text.should == 'Code' + end +end + +shared "a controller from a storyboard" do + it "has the label defined in the storyboard" do + labels = views(UILabel) + labels.count.should == 2 + view('Storyboard').text.should == 'Hello, RubyMotion' + end +end + +describe "Storyboard support defaults" do + tests StoryboardViewController, :id => 'main' + + it "uses MainStoryboard if no name is provided" do + @options[:storyboard_name].should == 'MainStoryboard' + end + + behaves_like "a controller from a storyboard" +end + +describe "Storyboard support with named storyboard" do + tests StoryboardViewController, :storyboard_name => 'AlternateStoryboard', :id => 'alternate' + + behaves_like "a controller from a storyboard" +end