This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// You implememt a Mock which conforms to the same protocol the ViewController is connected to | |
class UserServiceMock: UserServiceInterface { | |
var resultToReturn: Bool = false | |
var errorToReturn: Error? | |
func login(email: String, password: String, completion: (Bool, Error?)) { | |
completion(resultToReturn, errorToReturn) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewController: UIViewController { | |
var userService: UserServiceInterface = UserService.shared | |
func login(email: String, password: String, completion: ((Bool) -> Void)) { | |
// .... | |
userService.login(email, password, completion: { (success, error) in | |
if success { | |
completion(true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LoginTests: XCTestCase { | |
let viewControllerToTest = ViewController() | |
func testLogin() { | |
// Since this is an async call we need to wait for the callback in the test - otherwise we will not run long enought to get the response | |
let loginExpectation = expectation(description: "should call login") | |
viewController.login("testEmail", "testPassword", completion: { success in | |
loginExpectation.fulfill() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserService { | |
static var loginURL = "https://my.app.com/login" | |
static var shared = UserService() | |
func login(email: String, password: String, completion: (Bool, Error?)) { | |
let params = ["email": email, "password": password] | |
Alamofire.shared.request(loginURL, method: .POST, parameters: params, encoding: .URLEncoding).responseJSON { (response) in | |
switch respose.status { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewController: UIViewController { | |
// .... | |
@IBAction func loginButtonPressed() { | |
login(emailTextField.text ?? "", passwordTextField.text ?? "", completion: { success in | |
if !success { | |
showLoginError() | |
return | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private weak var webView: WKWebView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// This is needed when using an iOS target < iOS 11.0 - there was a storyboard bug which does not allow instantiating WKWebView from the Storyboard or Xib file | |
let webView = WKWebView() | |
self.webView.translatesAutoresizingMaskIntoConstraints = false | |
self.view.addSubview(webView) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from youtrack.connection import Connection as YouTrack | |
#// authentication request with permanent token | |
#yt = YouTrack('https://instance_name.myjetbrains.com/youtrack/', token='perm:abcdefghijklmn') | |
#// versus authentication with username and password | |
yt = YouTrack('https://everskill.myjetbrains.com/youtrack/', login='add_yours_here', password='add_yours_here') | |
def print_issues(project, issues, type): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from youtrack.connection import Connection as YouTrack | |
#// authentication request with permanent token | |
#yt = YouTrack('https://instance_name.myjetbrains.com/youtrack/', token='perm:abcdefghijklmn') | |
#// versus authentication with username and password | |
yt = YouTrack('https://everskill.myjetbrains.com/youtrack/', login='username', password='password') | |
def print_issues(project, issues, type): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyTest: NSObject { | |
private var identifier = "myIdentifier" | |
var defaultContent: [String] | |
init(withItem item: String) { | |
defaultContent = [item] | |
} | |
class func fetchInfo(success: (info: [AnyObject: AnyObject]?) -> (), failure: ((error: NSError?) -> ())? ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyTest: NSObject { | |
private var identifier: String = "myIdentifier" | |
var defaultContent: [String] | |
init(withItem item: String) { | |
self.defaultContent = [item] | |
} | |
class func fetchInfo(success: (info: [AnyObject: AnyObject]) -> (), failure: ((error: NSError?) -> ())? ) { |
NewerOlder