Max Kolesin
2018-08-14 20:39:03 UTC
Hello everyone, I raised this question Cucumber-CPP gitter originally, but
so far have no responses and don't really know if people check it
regularly. So will duplicate here, apologies to everyone who might feel
being a victim of spam attack :)
How difficult would it be to allow runtime steps registration?
The desire is to be able to register steps like this:
#include <gtest/gtest.h>#include <cucumber-cpp/autodetect.hpp>
#include <unordered_map>#include <vector>
using cucumber::ScenarioScope;
struct SomeCtx
{
std::unordered_map<std::string, std::string> m_configuration;
};
GIVEN("^I create some context$")
{
ScenarioScope<SomeCtx> context;
}
std::unordered_map<std::string, std::string> all_possible_params(
{{"int param", "(\\d+)"},
{"double param", "(.*)"},
{"string param", "\"([^\"]*)\""}});
void somehow_called_registration_func(){
for (const auto &k : all_possible_params)
{
const auto ¶m_name = k.first;
const auto ¶m_reqexp = k.second;
WHEN("^I set " + param_name + " to " + param_regexp + "$", [¶m_name](const auto &value))
{
ScenarioScope<SomeCtx> context;
context.m_conf[param_name] = std::to_string(value);
}
}
}
what would allow to then use generated steps in scenarios like this:
Given I create some contextWhen I set int param to 1And I set double param to 0.37And I set string param to "something"
What major problems with that approach do you foresee? I'm willing to
contribute, but don't really have a sense of how doable it is.
so far have no responses and don't really know if people check it
regularly. So will duplicate here, apologies to everyone who might feel
being a victim of spam attack :)
How difficult would it be to allow runtime steps registration?
The desire is to be able to register steps like this:
#include <gtest/gtest.h>#include <cucumber-cpp/autodetect.hpp>
#include <unordered_map>#include <vector>
using cucumber::ScenarioScope;
struct SomeCtx
{
std::unordered_map<std::string, std::string> m_configuration;
};
GIVEN("^I create some context$")
{
ScenarioScope<SomeCtx> context;
}
std::unordered_map<std::string, std::string> all_possible_params(
{{"int param", "(\\d+)"},
{"double param", "(.*)"},
{"string param", "\"([^\"]*)\""}});
void somehow_called_registration_func(){
for (const auto &k : all_possible_params)
{
const auto ¶m_name = k.first;
const auto ¶m_reqexp = k.second;
WHEN("^I set " + param_name + " to " + param_regexp + "$", [¶m_name](const auto &value))
{
ScenarioScope<SomeCtx> context;
context.m_conf[param_name] = std::to_string(value);
}
}
}
what would allow to then use generated steps in scenarios like this:
Given I create some contextWhen I set int param to 1And I set double param to 0.37And I set string param to "something"
What major problems with that approach do you foresee? I'm willing to
contribute, but don't really have a sense of how doable it is.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.