-
Notifications
You must be signed in to change notification settings - Fork 178
Closed
Labels
Milestone
Description
The following minimal example demonstrates the issue:
#include <vector>
#include <string>
#include "catch.hpp"
#include "fakeit.hpp"
using namespace std;
using namespace fakeit;
struct IExample {
virtual vector<string> getList() const = 0;
};
TEST_CASE("Mock capture by reference") {
Mock<IExample> mock;
vector<string> values;
When(Method(mock, getList)).AlwaysReturn(ref(values));
IExample& x = mock.get();
CHECK(x.getList().size() == 0);
values.push_back("Hello");
values.push_back("World");
REQUIRE(x.getList().size() == 2); // This assertion fails
CHECK(x.getList()[0] == "Hello");
CHECK(x.getList()[1] == "World");
}I can see that (Always)Return has reference and non-reference overloads, maybe adding a reference_wrapper overload would help?
For now I've worked around it by directly using (Always)Do instead.