Spec++ BDD framework for C++
Spec++ is a framework for practicing Behavior Driven Development (BDD) in C++. context “An empty stack” specify “should not be empty after push” stack.push( 1 ); stack.empty should_be false specify “should complain when poping empty stack” stack.pop should_throw
When designing Spec++ I tried to follow the specification layout mention above as closely as the C++ language allows.The above specification in Spec++ syntax would look like this:
#include "stack.hpp" struct stack_helper { stack stack; // Setup stack_helper() { // the stack is empty so we don't need to do anything } // Teardown ~stack_helper() {} }; context("An empty stack", stack_helper) { specify("should not be empty after push") { stack.push( 1 ); value( stack.empty() ).should.be( false ); } specify("should complain when poping empty stack") { method stack.pop(); should_throw; } } SPECPP_MAIN
This is all you have to code, joust compile and run. You can then at runtime choose between different output like xml, text, compiler error
(to be used in the IDE).In the 0.1.0 release these expectation bellow can be used. For the 0.2.0 release I’m working on a container keyword so it should be possible to write things likecontainer( x ).should.include( ); orcontainer( x ).should.have_at_least( ).of( ); and so on. I’m also doing some experimentation with Boost.Lambda library to see if I can make Spec++ even more flexible. And I’m adding more expectations to the value() API.
Equal and Not equal
.should.be( ); .should.equal( ); .should.not_be( ); .should.not_equal( ); .should == ; .should != ;
More than, less than or equal
.should.be_more_than( ); .should.be_less_than( ); .should.be_more_than_or_equal_to( ); .should.be_less_than_or_equal_to( ); .should < ; .should > ; .should <= ; .should >= ;
Between or equal to
.should.be_between( ).And( ); .should.not_be_between( ).And( ); .should.be_between( ) && ; .should.not_be_between( ) && ; .should.be_between_or_equal_to( ).And( ); .should.not_be_between_or_equal_to( ).And( ); .should.be_between_or_equal_to( ) && ; .should.not_be_between_or_equal_to( ) && ;
Floating point comparison
.should.be_close( , ); .should.not_be_close( , ); .should.be_within( ).of( ); .should.not_be_within( ).of( );
Regular Expression pattern matching
.should.match( ); .should.not_match( );
Throwing:
function f() should_throw; function f() should_not_throw; function f() should_throw_a( ); method f() should_throw; method f() should_not_throw; method f() should_throw_a( );
