How to use examples method of for class

Best Quick code snippet using for.examples

World.swift

Source:World.swift Github

copy

Full Screen

1import Foundation2/**3    A closure that, when evaluated, returns a dictionary of key-value4    pairs that can be accessed from within a group of shared examples.5*/6public typealias SharedExampleContext = () -> (NSDictionary)7/**8    A closure that is used to define a group of shared examples. This9    closure may contain any number of example and example groups.10*/11public typealias SharedExampleClosure = (SharedExampleContext) -> ()12/**13    A collection of state Quick builds up in order to work its magic.14    World is primarily responsible for maintaining a mapping of QuickSpec15    classes to root example groups for those classes.16    It also maintains a mapping of shared example names to shared17    example closures.18    You may configure how Quick behaves by calling the -[World configure:]19    method from within an overridden +[QuickConfiguration configure:] method.20*/21@objc final public class World {22    /**23        The example group that is currently being run.24        The DSL requires that this group is correctly set in order to build a25        correct hierarchy of example groups and their examples.26    */27    public var currentExampleGroup: ExampleGroup?28    /**29        The example metadata of the test that is currently being run.30        This is useful for using the Quick test metadata (like its name) at31        runtime.32    */33    public var currentExampleMetadata: ExampleMetadata?34    /**35        A flag that indicates whether additional test suites are being run36        within this test suite. This is only true within the context of Quick37        functional tests.38    */39    public var isRunningAdditionalSuites = false40    private var specs: Dictionary<String, ExampleGroup> = [:]41    private var sharedExamples: [String: SharedExampleClosure] = [:]42    private let configuration = Configuration()43    private var isConfigurationFinalized = false44    internal var exampleHooks: ExampleHooks {return configuration.exampleHooks }45    internal var suiteHooks: SuiteHooks { return configuration.suiteHooks }46    // MARK: Singleton Constructor47    private init() {}48    private struct Shared {49        static let instance = World()50    }51    public class func sharedWorld() -> World {52        return Shared.instance53    }54    // MARK: Public Interface55    /**56        Exposes the World's Configuration object within the scope of the closure57        so that it may be configured. This method must not be called outside of58        an overridden +[QuickConfiguration configure:] method.59        :param: closure  A closure that takes a Configuration object that can60                         be mutated to change Quick's behavior.61    */62    public func configure(closure: QuickConfigurer) {63        assert(!isConfigurationFinalized,64               "Quick cannot be configured outside of a +[QuickConfiguration configure:] method. You should not call -[World configure:] directly. Instead, subclass QuickConfiguration and override the +[QuickConfiguration configure:] method.")65        closure(configuration: configuration)66    }67    /**68        Finalizes the World's configuration.69        Any subsequent calls to World.configure() will raise.70    */71    public func finalizeConfiguration() {72        isConfigurationFinalized = true73    }74    /**75        Returns an internally constructed root example group for the given76        QuickSpec class.77        A root example group with the description "root example group" is lazily78        initialized for each QuickSpec class. This root example group wraps the79        top level of a -[QuickSpec spec] method--it's thanks to this group that80        users can define beforeEach and it closures at the top level, like so:81            override func spec() {82                // These belong to the root example group83                beforeEach {}84                it("is at the top level") {}85            }86        :param: cls The QuickSpec class for which to retrieve the root example group.87        :returns: The root example group for the class.88    */89    public func rootExampleGroupForSpecClass(cls: AnyClass) -> ExampleGroup {90        let name = NSStringFromClass(cls)91        if let group = specs[name] {92            return group93        } else {94            let group = ExampleGroup(95                description: "root example group",96                flags: [:],97                isInternalRootExampleGroup: true98            )99            specs[name] = group100            return group101        }102    }103    /**104        Returns all examples that should be run for a given spec class.105        There are two filtering passes that occur when determining which examples should be run.106        That is, these examples are the ones that are included by inclusion filters, and are107        not excluded by exclusion filters.108        :param: specClass The QuickSpec subclass for which examples are to be returned.109        :returns: A list of examples to be run as test invocations.110    */111    @objc(examplesForSpecClass:)112    public func examples(specClass: AnyClass) -> [Example] {113        // 1. Grab all included examples.114        let included = includedExamples115        // 2. Grab the intersection of (a) examples for this spec, and (b) included examples.116        let spec = rootExampleGroupForSpecClass(specClass).examples.filter { contains(included, $0) }117        // 3. Remove all excluded examples.118        return spec.filter { example in119            !self.configuration.exclusionFilters.reduce(false) { $0 || $1(example: example) }120        }121    }122    // MARK: Internal123    internal func registerSharedExample(name: String, closure: SharedExampleClosure) {124        raiseIfSharedExampleAlreadyRegistered(name)125        sharedExamples[name] = closure126    }127    internal func sharedExample(name: String) -> SharedExampleClosure {128        raiseIfSharedExampleNotRegistered(name)129        return sharedExamples[name]!130    }131    internal var exampleCount: Int {132        return allExamples.count133    }134    private var allExamples: [Example] {135        var all: [Example] = []136        for (_, group) in specs {137            group.walkDownExamples { all.append($0) }138        }139        return all140    }141    private var includedExamples: [Example] {142        let all = allExamples143        let included = all.filter { example in144            return self.configuration.inclusionFilters.reduce(false) { $0 || $1(example: example) }145        }146        if included.isEmpty && configuration.runAllWhenEverythingFiltered {147            return all148        } else {149            return included150        }151    }152    private func raiseIfSharedExampleAlreadyRegistered(name: String) {153        if sharedExamples[name] != nil {154            NSException(name: NSInternalInconsistencyException,155                reason: "A shared example named '\(name)' has already been registered.",156                userInfo: nil).raise()157        }158    }159    private func raiseIfSharedExampleNotRegistered(name: String) {160        if sharedExamples[name] == nil {161            NSException(name: NSInternalInconsistencyException,162                reason: "No shared example named '\(name)' has been registered. Registered shared examples: '\(Array(sharedExamples.keys))'",163                userInfo: nil).raise()164        }165    }166}...

Full Screen

Full Screen

ExampleTableViewController.swift

Source:ExampleTableViewController.swift Github

copy

Full Screen

...28}29extension ExampleTableViewController {30    override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {31        if section == 0 {32            searchBar.placeholder = "Search examples"33            return searchBar34        }35        return nil36    }37    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {38        if section == 0 {39            return 60.040        }41        return 3042    }43    override func numberOfSections(in tableView: UITableView) -> Int {44        if isFiltering {45            return 146        }47        return allExamples.count + 148    }49    override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {50        if section == 0 {51            return nil52        } else {53            return allExamples[section - 1]["title"] as? String54        }55    }56    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {57        if isFiltering {58          return filteredExamples.count59        }60        if section == 0 {61            return 062        }63        let examples = allExamples[section - 1]["examples"] as! [Example]64        return examples.count65    }66    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {67        var example: Example68        if isFiltering {69          example = filteredExamples[indexPath.row]70        } else {71            let examples = allExamples[indexPath.section - 1]["examples"] as! [Example]72          example = examples[indexPath.row]73        }74        let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "reuseIdentifier")75        cell.textLabel?.text = example.title76        cell.textLabel?.numberOfLines = 277        cell.detailTextLabel?.text = example.description.trimmingCharacters(in: .whitespacesAndNewlines)78        cell.detailTextLabel?.numberOfLines = 279        if #available(iOS 13.0, *) {80            cell.detailTextLabel?.textColor = .secondaryLabel81        } else {82            cell.detailTextLabel?.textColor = .lightGray83        }84        return cell85    }86    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {87        var example: Example88        if isFiltering {89          example = filteredExamples[indexPath.row]90        } else {91            let examples = allExamples[indexPath.section - 1]["examples"] as! [Example]92          example = examples[indexPath.row]93        }94        let exampleViewController = example.makeViewController()95        navigationController?.pushViewController(exampleViewController, animated: true)96    }97    func filterContentForSearchText(_ searchText: String) {98        var examples = [Example]()99        for array in allExamples {100            examples.append(contentsOf: array["examples"] as! [Example])101        }102        filteredExamples = examples.filter {103            return $0.title.lowercased().contains(searchText.lowercased())104        }105      tableView.reloadData()106    }107}...

Full Screen

Full Screen

examples

Using AI Code Generation

copy

Full Screen

1import UIKit2class Vehicle {3    var description: String {4        return "Vehicle with \(numberOfWheels) wheels"5    }6}7let vehicle = Vehicle()8print("Vehicle: \(vehicle.description)")9import UIKit10class Bicycle: Vehicle {11    override init() {12        super.init()13    }14}15let bicycle = Bicycle()16print("Bicycle: \(bicycle.description)")17import UIKit18class Hoverboard: Vehicle {19    init(color: String) {20        super.init()21    }22    override var description: String {23        return "\(super.description) in a beautiful \(color)"24    }25}26let hoverboard = Hoverboard(color: "silver")27print("Hoverboard: \(hoverboard.description)")28import UIKit29class Food {30    init(name: String) {31    }32    convenience init() {33        self.init(name: "[Unnamed]")34    }35}36let namedMeat = Food(name: "Bacon")37let mysteryMeat = Food()38import UIKit39class RecipeIngredient: Food {40    init(name: String, quantity: Int) {41        super.init(name: name)42    }43    override convenience init(name: String) {44        self.init(name: name, quantity: 1)45    }46}47let oneMysteryItem = RecipeIngredient()48let oneBacon = RecipeIngredient(name: "Bacon")49let sixEggs = RecipeIngredient(name: "Eggs", quantity: 6)50import UIKit51class ShoppingListItem: RecipeIngredient {52    var description: String {53        var output = "\(quantity) x \(name.lowercaseString)"54    }55}

Full Screen

Full Screen

examples

Using AI Code Generation

copy

Full Screen

1import Foundation2class example{3    func display(){4        print("Name is \(name)")5    }6}7let obj = example()8obj.display()9import Foundation10class example{11    func display(){12        print("Name is \(name)")13    }14}15let obj = example()16obj.display()17import Foundation18class example{19    func display(){20        print("Name is \(name)")21    }22}23let obj = example()24obj.display()25import Foundation26class example{27    func display(){28        print("Name is \(name)")29    }30}31let obj = example()32obj.display()33import Foundation34class example{35    func display(){36        print("Name is \(name)")37    }38}39let obj = example()40obj.display()41import Foundation42class example{43    func display(){44        print("Name is \(name)")45    }46}47let obj = example()48obj.display()

Full Screen

Full Screen

examples

Using AI Code Generation

copy

Full Screen

1import Foundation2class ExampleClass {3    func exampleClassMethod() -> Int {4    }5}6struct ExampleStruct {7    func exampleClassMethod() -> Int {8    }9}10enum ExampleEnum {11    func exampleClassMethod() -> Int {12    }13}14protocol ExampleProtocol {15    var exampleClassProperties: Int { get }16    func exampleClassMethod() -> Int17}18struct ExampleStruct2 {19    func exampleClassMethod() -> Int {20    }21}22class ExampleClass2 {23    func exampleClassMethod() -> Int {24    }25}26enum ExampleEnum2 {27    func exampleClassMethod() -> Int {28    }29}30protocol ExampleProtocol2 {31    var exampleClassProperties: Int { get }32    func exampleClassMethod() -> Int33}34struct ExampleStruct3 {35    func exampleClassMethod() -> Int {36    }37}38class ExampleClass3 {39    func exampleClassMethod() -> Int {40    }41}42enum ExampleEnum3 {43    func exampleClassMethod() -> Int {44    }45}46protocol ExampleProtocol3 {47    var exampleClassProperties: Int { get }48    func exampleClassMethod() -> Int49}50struct ExampleStruct4 {51    func exampleClassMethod() -> Int {52    }53}54class ExampleClass4 {55    func exampleClassMethod() -> Int

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful