Skip to content

Instantly share code, notes, and snippets.

@barneywilliams
Created May 24, 2012 13:10
Show Gist options
  • Save barneywilliams/2781482 to your computer and use it in GitHub Desktop.
Save barneywilliams/2781482 to your computer and use it in GitHub Desktop.
C++ step definitions and the corresponding test fixture
#include <gtest/gtest.h>
#include <cucumber-cpp/defs.hpp>
#include <Calculator.h>
struct CalcCtx {
Calculator calc;
double result;
};
GIVEN("^I have entered (\\d+) into the calculator$") {
REGEX_PARAM(double, n);
USING_CONTEXT(CalcCtx, context);
context->calc.push(n);
}
WHEN("^I press add") {
USING_CONTEXT(CalcCtx, context);
context->result = context->calc.add();
}
WHEN("^I press divide") {
USING_CONTEXT(CalcCtx, context);
context->result = context->calc.divide();
}
THEN("^the result should be (.*) on the screen$") {
REGEX_PARAM(double, expected);
USING_CONTEXT(CalcCtx, context);
EXPECT_EQ(expected, context->result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment