<commit_before>
describe 'Controller', ->

  Given ->
    setGet = (n) ->
      (v) ->
        if typeof v != 'undefined'
          @data[n] = v
          return @
        else
          return @data[n]
    @Message = class Message
      constructor: ->
        @data =
          actor: 'me'
          action: 'say'
          content: 'hello'
          target: 'you'
          created: new Date
          reference: null
          id: 1
      actor: setGet 'actor' 
      action: setGet 'action'
      target: setGet 'target'
      content: setGet 'content'
      id: setGet 'id'
      created: setGet 'created'
      reference: setGet 'reference'
      published: setGet 'published'
      clone: ->
        return new Message

  Given -> @Controller = requireSubject 'lib/controller', {
    './message': @Message
  }

  Given -> @message = new @Message

  Given ->
    @controller = @Controller @message
    spyOn(@controller,'emit').andCallThrough()
  Then -> expect(@controller instanceof @Controller).toBe true
  And -> expect(@controller.message).toEqual @message

  describe '#consume', ->
    When -> @controller.consume()
    Then -> expect(@controller.emit).toHaveBeenCalledWith 'consume', @message
    And -> expect(@message.consumed instanceof Date).toBe true


  describe '#respond', ->
    When -> @controller.respond 'goodbye'
    Then -> expect(@controller.emit).toHaveBeenCalled()
    And -> expect(@controller.emit.mostRecentCall.args[0]).toBe 'respond'
    And -> expect(@controller.emit.mostRecentCall.args[1].data.actor).toBe 'you'
    And -> expect(@controller.emit.mostRecentCall.args[1].data.action).toBe 'say'
    And -> expect(@controller.emit.mostRecentCall.args[1].data.content).toBe 'goodbye'
    And -> expect(@controller.emit.mostRecentCall.args[1].data.target).toBe 'me'
    And -> expect(@controller.emit.mostRecentCall.args[1].data.reference).toBe 1
    And -> expect(@controller.emit.mostRecentCall.args[1].data.created instanceof Date).toBe true

  describe '#deliver', ->

    context 'no args', ->

      When -> @controller.deliver()
      Then -> expect(@controller.emit).toHaveBeenCalledWith 'deliver', @message

    context 'new target', ->
      Given ->
        @m = @message.clone()
        @m.data.target = 'people'
      When -> @controller.deliver 'people'
      Then -> expect(@controller.emit).toHaveBeenCalledWith 'deliver', @m

  describe '#actor', ->

    Given -> @v = 'a'
    Then -> expect(@controller.actor(@v).actor()).toEqual @v
  
  describe '#action', ->

    Given -> @v = 'a'
    Then -> expect(@controller.action(@v).action()).toEqual @v
<commit_msg>tweaked test hopefully resolved the issue we test occasionally failing<commit_after>
describe 'Controller', ->

  Given ->
    setGet = (n) ->
      (v) ->
        if typeof v != 'undefined'
          @data[n] = v
          return @
        else
          return @data[n]
    @Message = class Message
      constructor: ->
        @data =
          actor: 'me'
          action: 'say'
          content: 'hello'
          target: 'you'
          created: new Date
          reference: null
          id: 1
      actor: setGet 'actor' 
      action: setGet 'action'
      target: setGet 'target'
      content: setGet 'content'
      id: setGet 'id'
      created: setGet 'created'
      reference: setGet 'reference'
      published: setGet 'published'
      clone: ->
        return new Message

  Given -> @Controller = requireSubject 'lib/controller', {
    './message': @Message
  }

  Given -> @message = new @Message

  Given ->
    @controller = @Controller @message
    spyOn(@controller,'emit').andCallThrough()
  Then -> expect(@controller instanceof @Controller).toBe true
  And -> expect(@controller.message).toEqual @message

  describe '#consume', ->
    When -> @controller.consume()
    Then -> expect(@controller.emit).toHaveBeenCalledWith 'consume', @message
    And -> expect(@message.consumed instanceof Date).toBe true


  describe '#respond', ->
    When -> @controller.respond 'goodbye'
    Then -> expect(@controller.emit).toHaveBeenCalled()
    And -> expect(@controller.emit.mostRecentCall.args[0]).toBe 'respond'
    And -> expect(@controller.emit.mostRecentCall.args[1].data.actor).toBe 'you'
    And -> expect(@controller.emit.mostRecentCall.args[1].data.action).toBe 'say'
    And -> expect(@controller.emit.mostRecentCall.args[1].data.content).toBe 'goodbye'
    And -> expect(@controller.emit.mostRecentCall.args[1].data.target).toBe 'me'
    And -> expect(@controller.emit.mostRecentCall.args[1].data.reference).toBe 1
    And -> expect(@controller.emit.mostRecentCall.args[1].data.created instanceof Date).toBe true

  describe '#deliver', ->

    context 'no args', ->

      When -> @controller.deliver()
      Then -> expect(@controller.emit).toHaveBeenCalledWith 'deliver', @message

    context 'new target', ->
      Given ->
        @m = @message.clone()
        @m.data.target = 'people'
      When -> @controller.deliver 'people'
      Then -> expect(@controller.emit).toHaveBeenCalled()
      And -> expect(@controller.emit.mostRecentCall.args[0]).toBe 'deliver'
      And -> expect(@controller.emit.mostRecentCall.args[1]).toEqual @m

  describe '#actor', ->

    Given -> @v = 'a'
    Then -> expect(@controller.actor(@v).actor()).toEqual @v
  
  describe '#action', ->

    Given -> @v = 'a'
    Then -> expect(@controller.action(@v).action()).toEqual @v

{'fraction_non_alphanumeric': 0.15087719298245614, 'fraction_numerical': 0.003693444136657433, 'mean_word_length': 2.694406548431105, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 83, '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': '3928710', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1560, 'n_words': 359}