<commit_before>//
//  SignalSpec.swift
//  ReactiveCocoa
//
//  Created by <NAME> on 2015-01-23.
//  Copyright (c) 2015 GitHub. All rights reserved.
//

import LlamaKit
import Nimble
import Quick
import ReactiveCocoa

class SignalSpec: QuickSpec {
	override func spec() {
		describe("init") {
			let testError = NSError(domain: "SignalSpec", code: 1, userInfo: nil)
			
			it("should run the generator immediately") {
				var didRunGenerator = false
				Signal<Int, NoError> { observer in
					didRunGenerator = true
					return nil
				}
				
				expect(didRunGenerator).to(beTrue())
			}

			it("should keep signal alive if not terminated") {
				let signal: Signal<Int, NoError> = Signal { observer in
					return nil
				}
				
				expect(signal).toNot(beNil())
			}

			it("should deallocate after erroring") {
				let scheduler = TestScheduler()
				var dealloced = false
				
				let signal: Signal<Int, NSError> = Signal { observer in
					scheduler.schedule {
						sendError(observer, testError)
					}
					return ActionDisposable {
						dealloced = true
					}
				}
				
				var errored = false
				
				signal.observe(
					next: { _ in},
					error: { _ in errored = true },
					completed: {}
				)
				
				expect(errored).to(beFalse())
				expect(dealloced).to(beFalse())
				
				scheduler.run()
				
				expect(errored).to(beTrue())
				expect(dealloced).to(beTrue())
			}

			it("should deallocate after completing") {
				let scheduler = TestScheduler()
				var dealloced = false
				
				let signal: Signal<Int, NSError> = Signal { observer in
					scheduler.schedule {
						sendCompleted(observer)
					}
					return ActionDisposable {
						dealloced = true
					}
				}
				
				var completed = false
				
				signal.observe(
					next: { _ in},
					error: { _ in },
					completed: { completed = true }
				)
				
				expect(completed).to(beFalse())
				expect(dealloced).to(beFalse())
				
				scheduler.run()
				
				expect(completed).to(beTrue())
				expect(dealloced).to(beTrue())
			}

			pending("should forward events to observers") {
			}

			pending("should dispose of returned disposable upon error") {
			}

			pending("should dispose of returned disposable upon completion") {
			}
		}

		describe("Signal.pipe") {
			pending("should keep signal alive if not terminated") {
			}

			pending("should deallocate after erroring") {<commit_msg>add spec wide testScheduler var and init it beforeEach<commit_after>//
//  SignalSpec.swift
//  ReactiveCocoa
//
//  Created by <NAME> on 2015-01-23.
//  Copyright (c) 2015 GitHub. All rights reserved.
//

import LlamaKit
import Nimble
import Quick
import ReactiveCocoa

class SignalSpec: QuickSpec {
	override func spec() {
		describe("init") {
			let testError = NSError(domain: "SignalSpec", code: 1, userInfo: nil)
			var testScheduler: TestScheduler!
			
			beforeEach {
				testScheduler = TestScheduler()
			}
			
			it("should run the generator immediately") {
				var didRunGenerator = false
				Signal<Int, NoError> { observer in
					didRunGenerator = true
					return nil
				}
				
				expect(didRunGenerator).to(beTrue())
			}

			it("should keep signal alive if not terminated") {
				let signal: Signal<Int, NoError> = Signal { observer in
					return nil
				}
				
				expect(signal).toNot(beNil())
			}

			it("should deallocate after erroring") {
				var dealloced = false
				
				let signal: Signal<Int, NSError> = Signal { observer in
					testScheduler.schedule {
						sendError(observer, testError)
					}
					return ActionDisposable {
						dealloced = true
					}
				}
				
				var errored = false
				
				signal.observe(
					next: { _ in},
					error: { _ in errored = true },
					completed: {}
				)
				
				expect(errored).to(beFalse())
				expect(dealloced).to(beFalse())
				
				testScheduler.run()
				
				expect(errored).to(beTrue())
				expect(dealloced).to(beTrue())
			}

			it("should deallocate after completing") {
				var dealloced = false
				
				let signal: Signal<Int, NSError> = Signal { observer in
					testScheduler.schedule {
						sendCompleted(observer)
					}
					return ActionDisposable {
						dealloced = true
					}
				}
				
				var completed = false
				
				signal.observe(
					next: { _ in},
					error: { _ in },
					completed: { completed = true }
				)
				
				expect(completed).to(beFalse())
				expect(dealloced).to(beFalse())
				
				testScheduler.run()
				
				expect(completed).to(beTrue())
				expect(dealloced).to(beTrue())
			}

			pending("should forward events to observers") {
			}

			pending("should dispose of returned disposable upon error") {
			}

			pending("should dispose of returned disposable upon completion") {
			}
		}

		describe("Signal.pipe") {
			pending("should keep signal alive if not terminated") {
			}

			pending("should deallocate after erroring") {
{'fraction_non_alphanumeric': 0.11074448339863889, 'fraction_numerical': 0.005361930294906166, 'mean_word_length': 2.5427319211102994, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1070931', 'n_tokens_mistral': 2130, 'n_tokens_neox': 1449, 'n_words': 372}