Is Rspec ruby/rails specific? Is it possible to use it as a test framework for C/C++ program?
5 Answers
I know I am resurrecting an ANCIENT question... but I get this link from google when searching rspec and c++.
Google itself built a (pretty simple to use) test suite called GoogleTest, that is based on xUnit and designed to be cross-platform.
They also have a mocking framework called GoogleMock.

- 1,349
- 13
- 20
-
A couple helpful discussions: http://stackoverflow.com/questions/87794/c-unit-testing-framework http://stackoverflow.com/questions/20606793/state-of-the-art-c-unit-testing – Joe Schrag May 27 '14 at 18:13
Description of Rspec says:
RSpec is the original Behaviour Driven Development framework for Ruby.
I think that means this tool is Ruby specific. For c++ you could use Boost Test Library or other tools.

- 97,037
- 24
- 136
- 212
-
Depends what you want to do with rspec. Project im working on has some guys who write cucumber features and turning them to actual test suites for applications written with c++ & qt .. There's some additional software in the mix thou but afaik, its still doable. – rasjani Jun 30 '10 at 10:02
-
Check out my answer, http://stackoverflow.com/a/41783609/2009612, I happened to find a blog about testing C/C++ using Ruby. – FilBot3 Jan 21 '17 at 19:34
I don't think that RSpec works for C++, but you should check out this comprehension: http://gamesfromwithin.com/exploring-the-c-unit-testing-framework-jungle
From my experience: You can use CppUnit, but it's somehow painful. There's a lot of overhead per test (overhead means lines of code), so adding tests becomes annoying. CppTest looks a bit better, and cxxtest seems really nice, though I haven't used the last two myself.

- 418
- 2
- 9
I just saw ccspec, and it looks very promising.
https://github.com/zhangsu/ccspec
Basically uses C++11 constructs to make something that reads just like rspec. It looks like it would fit the bill if your looking for a rspec like BDD tool. Take a look at the following example from the site:
class Student {
public:
bool hasPapers() const {
return true;
}
string status() const {
return "alumni";
}
};
auto student_spec = describe("Student", [] {
Student subject;
it("has published papers", [subject] {
expect(subject.hasPapers()).to(be_truthy);
});
it("is alumni", [subject] {
expect(subject.status()).to(eq("alumni"));
});
});
Has anyone here given it a try? I'm not sure if it has rspec like mocking functionality, but it looks like you could leverage gmock to do some mocking. Not quite there feature for feature with rspec, but might be as close as you can get in C++11

- 1,438
- 16
- 25
I was thinking the same thing when I started going back into C/C++ development and started looking for something similar to RSpec, or MiniTest for Ruby, and JUnit for Java.
http://sodabrew.com/2012/04/writing-c-unit-tests-in-ruby.html
What this link shows is how to use the FFI gem to load your C/C++ object file into Ruby, and call it almost as though it were a native Ruby function. You might find it nifty.

- 3,460
- 6
- 33
- 55