<commit_before>//
//  ActionSpec.swift
//  ReactiveCocoa
//
//  Created by <NAME> on 2014-12-11.
//  Copyright (c) 2014 GitHub. All rights reserved.
//

import LlamaKit
import Nimble
import Quick
import ReactiveCocoa

class ActionSpec: QuickSpec {
	override func spec() {
		var action: Action<Int, String>!

		var scheduler: TestScheduler!
		var enabledSink: SinkOf<Bool>!

		let testError = RACError.Empty.error

		beforeEach {
			let (signal, sink) = HotSignal<Bool>.pipe()
			enabledSink = sink

			scheduler = TestScheduler()
			action = Action(enabledIf: signal, serializedOnScheduler: scheduler) { number in
				return ColdSignal { (sink, disposable) in
					if number % 2 == 0 {
						sink.put(.Next(Box("\(number)")))
						sink.put(.Next(Box("\(number)\(number)")))
						sink.put(.Completed)
					} else {
						sink.put(.Error(testError))
					}
				}
			}
		}

		it("should be disabled and not executing after initialization") {
			expect(action.enabled.first().value()).to(equal(false))
			expect(action.executing.first().value()).to(equal(false))
		}

		it("should error if executed while disabled") {
			var receivedError: NSError?
			action.execute(0).start(error: {
				receivedError = $0
			})

			expect(receivedError).to(beNil())

			scheduler.advance()
			expect(receivedError).to(equal(RACError.ActionNotEnabled.error))
		}
	}
}<commit_msg>WIP more enabled/disabled tests for Action<commit_after>//
//  ActionSpec.swift
//  ReactiveCocoa
//
//  Created by <NAME> on 2014-12-11.
//  Copyright (c) 2014 GitHub. All rights reserved.
//

import LlamaKit
import Nimble
import Quick
import ReactiveCocoa

class ActionSpec: QuickSpec {
	override func spec() {
		var action: Action<Int, String>!

		var scheduler: TestScheduler!
		var enabledSink: SinkOf<Bool>!

		let testError = RACError.Empty.error

		beforeEach {
			let (signal, sink) = HotSignal<Bool>.pipe()
			enabledSink = sink

			scheduler = TestScheduler()
			action = Action(enabledIf: signal, serializedOnScheduler: scheduler) { number in
				return ColdSignal { (sink, disposable) in
					if number % 2 == 0 {
						sink.put(.Next(Box("\(number)")))
						sink.put(.Next(Box("\(number)\(number)")))
						sink.put(.Completed)
					} else {
						sink.put(.Error(testError))
					}
				}
			}
		}

		it("should be disabled and not executing after initialization") {
			expect(action.enabled.first().value()).to(beFalsy())
			expect(action.executing.first().value()).to(beFalsy())
		}

		it("should error if executed while disabled") {
			var receivedError: NSError?
			action.execute(0).start(error: {
				receivedError = $0
			})

			expect(receivedError).to(beNil())

			scheduler.advance()
			expect(receivedError).to(equal(RACError.ActionNotEnabled.error))
		}

		it("should enable and disable based on the given signal") {
			enabledSink.put(true)
			expect(action.enabled.first().value()).to(beFalsy())

			scheduler.advance()
			expect(action.enabled.first().value()).to(beTruthy())
			expect(action.executing.first().value()).to(beFalsy())

			enabledSink.put(false)
			expect(action.enabled.first().value()).to(beTruthy())

			scheduler.advance()
			expect(action.enabled.first().value()).to(beFalsy())
			expect(action.executing.first().value()).to(beFalsy())
		}
	}
}
{'fraction_non_alphanumeric': 0.1507985257985258, 'fraction_numerical': 0.009828009828009828, 'mean_word_length': 3.6264204545454546, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '5513644', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1063, 'n_words': 218}