 
 
   describe "square expression", ->
-    beforeEach ->
-      @square = @manip.build_square()
-
-    it_plays_manipulation_role (test)->
-      @square
+    it_plays_manipulation_role
+      subject: ->
+        @manip.build_square()
 
     it "returns a squared expression", ->
       exp = @exp_builder(10)
-      squared = @square.invoke(exp)
+      squared = @manip.build_square().perform(exp)
       @expect_value(squared, '100')
 
   describe "AppendRoot", ->
-    it_plays_manipulation_role ->
-      @manip.build_append_root()
+    it_plays_manipulation_role
+      subject: ->
+        @manip.build_append_root()
 
     it "adds a mulitplication and root to the expression", ->
       exp = @exp_builder([1])
 
-      new_exp = @manip.build_append_root(degree: 2).invoke(exp)
+      new_exp = @manip.build_append_root(degree: 2).perform(exp)
 
       expect(new_exp.last() instanceof @components.classes.root).toBeTruthy()
       expect(new_exp.last(1) instanceof @components.classes.multiplication).toBeTruthy()



  describe "appending addition", ->
    it_plays_manipulation_role (test)->
      @manip.build_append_addition()

    it "adds addition to the end of the expression", ->
      exp = @exp_builder(1)
      new_exp = @manip.build_append_addition().invoke(exp)
      expect(new_exp.last() instanceof @components.classes.addition).toEqual true

    it_inserts_component_into_the_last_nested_open_expression(

    it "adds a root with a radicand that is an open expression", ->
      exp = @exp_builder([1])

      new_exp = @manip.build_append_root(degree: 2).perform(exp)

      expect(new_exp.last() instanceof @components.classes.root).toBeTruthy()
      expect(new_exp.last().radicand().isOpen()).toBeTruthy()

  describe "AppendVariable", ->
    it_plays_manipulation_role
      subject: ->
        @manip.build_append_variable()

    it "adds itself to an empty expression", ->
      exp = @exp_builder()
      append_var = @manip.build_append_variable(variable: "doot")
      new_exp = append_var.perform(exp)
      expected = @exp_builder(variable: "doot")
      expect(new_exp).toBeAnEqualExpressionTo expected


  describe "Reset", ->
    it_plays_manipulation_role
      subject: ->
        @manip.build_reset()

      expression_for_performance: ->
        false # not important at all

    beforeEach ->
      @reset = @manip.build_reset()
      @result = @reset.perform()

    it "returns an empty resulting expression", ->
      expect(@result.expression()).toBeAnEqualExpressionTo @exp_builder()

    it "returns an pointer which points to that expression", ->
      expect(@result.position()).toEqual @result.expression().id()

  describe "update position", ->
    it_plays_manipulation_role
      subject: ->
        @manip.build_update_position()

      expression_for_performance: ->
        false


  describe "(moved over from other test file)", ->

    describe "NegationManipulation", ->
      it_plays_manipulation_role
        subject: ->
          @manip.build_negate_last()

      it "will negate the last element", ->
        exp = @exp_builder(1)
        new_exp = @manip.build_negate_last().perform(exp)
        expect(new_exp.last().value()).toEqual -1


    describe "AppendPi", ->
      it_plays_manipulation_role
        subject: ->
          @manip.build_append_pi()

      it "adds a mulitplication and pi to the expression", ->
        exp = @exp_builder(1)
        new_exp = @manip.build_append_pi().perform(exp)
        expect(new_exp.last() instanceof @components.classes.pi).toBeTruthy()
        expect(new_exp.last(1) instanceof @components.classes.multiplication).toBeTruthy()


    describe "SquareRootManipulation", ->
      it_plays_manipulation_role
        subject: ->
          @manip.build_square_root()

      it "finds the square root of an expression", ->
        exp = @exp_builder([4])
        new_exp = @manip.build_square_root().perform(exp)
        expect(new_exp.last().value()).toEqual '2'


