<commit_before>﻿# reference "../witness/dsl/describe.coffee"
# reference "../witness/Scenario.coffee"
# reference "../witness/Action.coffee"

describe "Scenario",
{
	given: ->
		@scenario = new Witness.Scenario
			given:   { description: "given", actions: [ (new Witness.Action (=> @givenCalled = true), []) ] }
			when:    { description: "when", actions: [ (new Witness.Action (=> @whenCalled = true), []) ] }
			then:    { description: "then", actions: [ new Witness.Assertion (new Witness.Action (=> @thenCalled = true), []) ] }
			dispose: { description: "dispose", actions: [ (new Witness.Action (=> @disposeCalled = true), []) ] }

	when: ->
		@scenario.run {}, (->), (->)

	then:
		givenCalled: should.be true
		whenCalled: should.be true
		thenCalled: should.be true
		disposeCalled: should.be true
},
{
	given: ->
		@scenario = new Witness.Scenario 
			given:   { description: "given", actions: [ (new Witness.Action (-> throw new Error "given failed"), []) ] }
			when:    { description: "when", actions: [ (new Witness.Action (=> @whenCalled = true), []) ] }
			then:    { description: "then", actions: [ new Witness.Assertion (new Witness.Action (=> @thenCalled = true), []) ] }
			dispose: { description: "dispose", actions: [ (new Witness.Action (=> @disposeCalled = true), []) ] }


	when: ->
		@scenario.run {}, (->), ((errors) => @errors = errors)

	then:
		whenCalled: should.be undefined
		thenCalled: should.be undefined
		disposeCalled: should.be true
		errors: [ message: should.be "given failed" ]
}<commit_msg>Add descriptions to Scenario spec<commit_after>﻿# reference "../witness/dsl/describe.coffee"
# reference "../witness/Scenario.coffee"
# reference "../witness/Action.coffee"

describe "Scenario",
{
	"given a scenario with given, when, then and dispose": ->
		@scenario = new Witness.Scenario
			given:   { description: "given", actions: [ (new Witness.Action (=> @givenCalled = true), []) ] }
			when:    { description: "when", actions: [ (new Witness.Action (=> @whenCalled = true), []) ] }
			then:    { description: "then", actions: [ new Witness.Assertion (new Witness.Action (=> @thenCalled = true), []) ] }
			dispose: { description: "dispose", actions: [ (new Witness.Action (=> @disposeCalled = true), []) ] }

	"when scenario is run": ->
		@scenario.run {}, (->), (->)

	then:
		givenCalled: should.be true
		whenCalled: should.be true
		thenCalled: should.be true
		disposeCalled: should.be true
},
{
	"given a scenario where the `given` action throws an error": ->
		@scenario = new Witness.Scenario 
			given:   { description: "given", actions: [ (new Witness.Action (-> throw new Error "given failed"), []) ] }
			when:    { description: "when", actions: [ (new Witness.Action (=> @whenCalled = true), []) ] }
			then:    { description: "then", actions: [ new Witness.Assertion (new Witness.Action (=> @thenCalled = true), []) ] }
			dispose: { description: "dispose", actions: [ (new Witness.Action (=> @disposeCalled = true), []) ] }


	"when scenarion is run": ->
		@scenario.run {}, (->), ((errors) => @errors = errors)

	then:
		whenCalled: should.be undefined
		thenCalled: should.be undefined
		disposeCalled: should.be true
		errors: [ message: should.be "given failed" ]
}
{'fraction_non_alphanumeric': 0.1822125813449024, 'fraction_numerical': 0.0, 'mean_word_length': 3.817910447761194, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 35, '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': '2260806', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1041, 'n_words': 273}