public CalculatorFeature() { var calculator = new Calculator(); comment = @" as a math idiot I want to use a calculator so I don't make mistakes with simple arithmetic "; Scenario["Addition"] = () => { Given["I have pressed clear"] = () => calculator.Clear(); When["I key in two"] = () => calculator.Key(2); When["I add three"] = () => calculator.Add(3); Then["the total is five"] = () => calculator.Total.ShouldEqual(5); Then["the equation history is:"] = () => log(calculator.Equation.ShouldEqual("2 + 3")); }; Scenario["Division"] = () => { Given["I have pressed clear"] = () => calculator.Clear(); When["I key in twelve"] = () => calculator.Key(12); When["I divide by four"] = () => calculator.Divide(4); Then["the total is three"] = () => calculator.Total.ShouldEqual(3); Then["the equation history is:"] = () => log(calculator.Equation.ShouldEqual("12 / 4")); }; }
public CalculatorSpecification() { var calculator = new Calculator(); before_each = () => calculator.Clear(); describe["Addition"] = () => { context["adding two and three"] = () => { before = () => calculator.Key(2).Add(3); it["sets the total to five"] = () => { calculator.Total.ShouldEqual(5); }; it["sets the equation history to:"] = () => { log(calculator.Equation.ShouldEqual("2 + 3")); }; }; context["adding two, three and four"] = () => { before = () => calculator.Key(2).Add(3).Add(4); it["sets the total to nine"] = () => { calculator.Total.ShouldEqual(9); }; it["sets the equation history to:"] = () => { log(calculator.Equation.ShouldEqual("2 + 3 + 4")); }; }; }; describe["Division"] = () => { context["dividing four from twelve"] = () => { before = () => calculator.Key(12).Divide(4); it["sets the total three"] = () => { calculator.Total.ShouldEqual(3); }; it["sets the equation history to:"] = () => { log(calculator.Equation.ShouldEqual("12 / 4")); }; }; context["dividing by zero"] = () => { it["explodes 💣💥☠️"] = () => { Catch(() => calculator.Key(2).Divide(0)).ShouldBeOfExactType<DivideByZeroException>(); }; }; }; }