require "spec_helper" require "ib/generator" describe IB::Generator do describe "generates stubs header with ios platform" do files = IB::Parser.new(:ios).find_all("spec/fixtures/common") stubs = IB::Generator.new(:ios).render_stub_file('generator/templates/Stubs.h.erb', files) it 'should output valid values from IB::Generator::RenderingHelpers and template file' do stubs.should == <<-OBJC // Generated by IB v#{IB::VERSION} gem. Do not edit it manually // Run `rake ib:open` to refresh #import #import #import @interface AppDelegate: UIResponder @property IBOutlet UIWindow * window; @property IBOutlet UINavigationController * navigationController; @end @interface HasComplexSuperClass: Complex::SuperClass @end @interface HasLessComplexSuperClass: UIViewController @end @interface CustomView: UIView @property IBOutlet UIGreenLabel * greenLabel; @property IBOutlet UILabel * redLabel; @property IBOutlet id untyped_label; @property IBOutlet id yellowLabel; @property IBOutletCollection(UIGreenLabel) NSArray * greenLabelCollection; @property IBOutletCollection(UILabel) NSArray * redLabelCollection; @property IBOutletCollection(id) NSArray * untyped_label_collection; @property IBOutletCollection(id) NSArray * yellowLabelCollection; -(IBAction) someAction:(id) sender; -(IBAction) segueAction:(UIStoryboardSegue*) sender; -(IBAction) anotherAction:(id) button; -(IBAction) actionWithComment:(id) sender; -(IBAction) actionWithBrackets:(id) sender; -(IBAction) actionWithoutArgs; -(IBAction) exitAction:(UIStoryBoard *) story_board; -(IBAction) actionWithDefaultedArgs:(id) sender; @end @interface EmptyView: UIView @end @interface AnotherView: EmptyView @end @interface SimpleClass: NSObject @end OBJC end end describe "generates stubs header with osx platform" do files = IB::Parser.new(:osx).find_all("spec/fixtures/common") stubs = IB::Generator.new(:osx).render_stub_file('generator/templates/Stubs.h.erb', files) it 'should output valid values from IB::Generator::RenderingHelpers and template file' do stubs.should == <<-OBJC // Generated by IB v#{IB::VERSION} gem. Do not edit it manually // Run `rake ib:open` to refresh #import #import #import @interface AppDelegate: NSObject @property IBOutlet UIWindow * window; @property IBOutlet UINavigationController * navigationController; @end @interface HasComplexSuperClass: Complex::SuperClass @end @interface HasLessComplexSuperClass: UIViewController @end @interface CustomView: UIView @property IBOutlet UIGreenLabel * greenLabel; @property IBOutlet UILabel * redLabel; @property IBOutlet id untyped_label; @property IBOutlet id yellowLabel; @property IBOutletCollection(UIGreenLabel) NSArray * greenLabelCollection; @property IBOutletCollection(UILabel) NSArray * redLabelCollection; @property IBOutletCollection(id) NSArray * untyped_label_collection; @property IBOutletCollection(id) NSArray * yellowLabelCollection; -(IBAction) someAction:(id) sender; -(IBAction) segueAction:(UIStoryboardSegue*) sender; -(IBAction) anotherAction:(id) button; -(IBAction) actionWithComment:(id) sender; -(IBAction) actionWithBrackets:(id) sender; -(IBAction) actionWithoutArgs; -(IBAction) exitAction:(UIStoryBoard *) story_board; -(IBAction) actionWithDefaultedArgs:(id) sender; @end @interface EmptyView: UIView @end @interface AnotherView: EmptyView @end @interface SimpleClass: NSObject @end OBJC end end describe "generates stubs implement" do files = IB::Parser.new(:ios).find_all("spec/fixtures/common") stubs = IB::Generator.new(:ios).render_stub_file('generator/templates/Stubs.m.erb', files) it 'should output valid values from IB::Generator::RenderingHelpers and template file' do stubs.should == <<-OBJC // Generated by IB v#{IB::VERSION} gem. Do not edit it manually // Run `rake ib:open` to refresh #import "Stubs.h" @implementation AppDelegate @end @implementation HasComplexSuperClass @end @implementation HasLessComplexSuperClass @end @implementation CustomView @end @implementation EmptyView @end @implementation AnotherView @end @implementation SimpleClass @end OBJC end end describe "generates stubs header with ios platform of dependency_test fixtures" do it 'should output definitions which sorterd by its own dependencies' do files = IB::Parser.new(:ios).find_all("spec/fixtures/dependency_test") stubs = IB::Generator.new(:ios).render_stub_file('generator/templates/Stubs.h.erb', files) stubs.should == <<-OBJC // Generated by IB v#{IB::VERSION} gem. Do not edit it manually // Run `rake ib:open` to refresh #import #import #import @interface BaseView: NSObject @end @interface AddButton: BaseView @end @interface AppDelegate: UIResponder @end @interface SuperClass: UIViewController @end @interface SubView1: UIView @property IBOutlet AddButton * button; -(IBAction) action_test:(id) sender; @end @interface SubClass2: SuperClass @property IBOutlet SubView1 * banner; @end @interface SubClass1: SubClass2 @end @interface UIMyWebView: UIWebView @end OBJC end end describe "generates stubs header with ios platform of ProMotion's fixtures" do it 'should replace super_class from PM::* or ProMotion::* to UIViewController' do files = IB::Parser.new(:ios).find_all("spec/fixtures/for_promotion") stubs = IB::Generator.new(:ios).render_stub_file('generator/templates/Stubs.h.erb', files) stubs.should == <<-OBJC // Generated by IB v#{IB::VERSION} gem. Do not edit it manually // Run `rake ib:open` to refresh #import #import #import @interface PromotionScreen: UIViewController @end @interface PromotionMapScreen: UIViewController @end OBJC end end end