Repository: ReactiveX/RxSwift
File: Tests/RxCocoaTests/UITabBarController+RxTests.swift (Swift)

Code before:
import RxSwift
import RxCocoa
import UIKit
import XCTest

class UITabBarControllerTests: RxTest {
    let createSubject: () -> UITabBarController = { UITabBarController() }
}

/**
 iOS only
 */
#if os(iOS)
extension UITabBarControllerTests {
    func testWillBeginCustomizing() {
        let subject = createSubject()
        
        let viewControllers = [UIViewController()]
        var returnedViewControllers: [UIViewController]!
        
        _ = subject.rx.willBeginCustomizing
            .subscribe(onNext: { vc in
                returnedViewControllers = vc
            })
        
        subject.delegate!.tabBarController!(subject, willBeginCustomizing: viewControllers)
        
        XCTAssertEqual(returnedViewControllers, viewControllers)
    }
    
    func testWillEndCustomizing() {
        let subject = createSubject()
        
        let viewControllers = [UIViewController()]
        var returnedViewControllers: [UIViewController]!
        var changed: Bool!
        
        _ = subject.rx.willEndCustomizing
            .subscribe(onNext: { (vc, c) in
                returnedViewControllers = vc
                changed = c
            })
        
        subject.delegate!.tabBarController!(subject, willEndCustomizing: viewControllers, changed: true)
        
        XCTAssertEqual(returnedViewControllers, viewControllers)
        XCTAssertEqual(changed, true)
    }
    
    func testDidEndCustomizing() {
        let subject = createSubject()

Review comment (bug):
It would be great to add before `subject.delegate!.tabBarController!(subject, willBeginCustomizing: viewControllers)` `XCTAssertNotEqual(returnedViewControllers, viewControllers)`.

I'll need to add those checks everywhere where they aren't present. We actually had a bug because those checks weren't there :)

Code after:
import RxSwift
import RxCocoa
import UIKit
import XCTest

class UITabBarControllerTests: RxTest {
    let createSubject: () -> UITabBarController = { UITabBarController() }
}

/**
 iOS only
 */
#if os(iOS)
extension UITabBarControllerTests {
    func testWillBeginCustomizing() {
        let subject = createSubject()
        
        let viewControllers = [UIViewController()]
        var returnedViewControllers = [UIViewController]()
        
        XCTAssertNotEqual(returnedViewControllers, viewControllers)
        
        _ = subject.rx.willBeginCustomizing
            .subscribe(onNext: { vc in
                returnedViewControllers = vc
            })
        
        subject.delegate!.tabBarController!(subject, willBeginCustomizing: viewControllers)
        
        XCTAssertEqual(returnedViewControllers, viewControllers)
    }
    
    func testWillEndCustomizing() {
        let subject = createSubject()
        
        let viewControllers = [UIViewController()]
        var returnedViewControllers = [UIViewController]()
        var changed: Bool!
        
        XCTAssertNotEqual(returnedViewControllers, viewControllers)
        XCTAssertNotEqual(changed, true)
        
        _ = subject.rx.willEndCustomizing
            .subscribe(onNext: { (vc, c) in
                returnedViewControllers = vc
                changed = c
            })
        
        subject.delegate!.tabBarController!(subject, willEndCustomizing: viewControllers, changed: true)
        
        XCTAssertEqual(returnedViewControllers, viewControllers)