title: Unit testing session variable in controller with spock
body: <p>I am trying to test that a session variable is set up in a method in a controller using a unit test in a Grails controller but it is complaining about setting a readonly property:</p>
  
  <pre><code>Cannot set readonly property: session for class: MyController
  </code></pre>
  
  <p>I have something like this:</p>
  
  <pre><code>class MyController {
     def settingSession = {
         session.var1 = "hello world!"
     }
  }
  </code></pre>
  
  <p>and this would be my test:</p>
  
  <pre><code>class MyControllerUnitTest extends ControllerSpec {
      def "My test with sessions"() {
         when:
              controller.settingSession()
         then:
              controller.session.var1 == "hello world!"
      }
  }
  </code></pre>
  
  <p>I guest that probably I should write an integration test but I would like to know if there is any possibility of doing this in a unit test.</p>