package specs;

import static com.greghaskins.spectrum.Spectrum.beforeEach;
import static com.greghaskins.spectrum.Spectrum.describe;
import static com.greghaskins.spectrum.Spectrum.it;
import static junit.framework.TestCase.assertNull;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

import com.greghaskins.spectrum.Spectrum;
import com.greghaskins.spectrum.Variable;

import org.junit.runner.RunWith;

@RunWith(Spectrum.class)
public class VariableSpecs {
  {

    describe("The Variable convenience wrapper", () -> {

      final Variable<Integer> counter = new Variable<>();

      beforeEach(() -> {
        counter.set(0);
      });

      beforeEach(() -> {
        counter.set(counter.get() + 1);
      });

      it("lets you work around Java's requirement that closures only use `final` variables", () -> {
        counter.set(counter.get() + 1);
        assertThat(counter.get(), is(2));
      });

      it("can optionally have an initial value set", () -> {
        final Variable<String> name = new Variable<>("Alice");
        assertThat(name.get(), is("Alice"));
      });

      it("has a null value if not specified", () -> {
        final Variable<String> name = new Variable<>();
        assertNull(name.get());
      });

    });

  }
}

@@ -5,24 +5,83 @@
 age specs;%0A%0A
+import static com.greghaskins.spectrum.Spectrum.beforeAll;%0A
 import stati
@@ -682,36 +682,35 @@
 );%0A%0A      before
-Each
+All
 (() -%3E %7B%0A       
@@ -761,32 +761,58 @@
 (() -%3E %7B%0A       
+ final int previousValue =
  counter.set(cou
@@ -800,36 +800,47 @@
 e = counter.
-s
+g
 et(
+);%0A        
 counter.
 get() + 1);%0A
@@ -819,37 +819,49 @@
         counter.
-get()
+set(previousValue
  + 1);%0A      %7D);
@@ -975,39 +975,124 @@
     
-counter.set(counter.get() + 1);
+assertThat(counter.get(), is(1));%0A      %7D);%0A%0A      it(%22can share values across scopes, so use it carefully%22, () -%3E %7B
 %0A   

Clarify specs for Variable helper