problem with extract method from gtest test case

I'm working on the GildedRose refactoring kata (https://github.com/emilybache/GildedRose-Refactoring-Kata) and I've so far got this test code:

TEST(GildedRoseTest, Foo) {
auto *name = "Foo";
int sellIn = 0;
int quality = 0;

vector<Item> items;
items.push_back(Item(name, sellIn, quality));
GildedRose app(items);
app.updateQuality();
auto &result = app.items[0];

EXPECT_EQ("Foo", result.name);
}

I would like to perform an'extract method' refactoring on the middle block of code here, which should create a function
that I can reuse in several test cases. When I select "extract method" from the refactoring menu it works out
the signature of the new function should be this:

Item GildedRoseTest_Foo_Test::getItem(const char *name,
int sellIn,
int quality) const

When I push the "extract" button to ask it to do the refactoring, it completely mangles the code and nothing compiles
any more:

TEST(GildedRoseTest, Foo)

Item getItem(const char *name, int sellIn, int quality) const
{
return Item(__1::basic_string(), 0, 0);
}

{
auto *name = "Foo";
int sellIn = 0;
int quality = 0;

vector<Item> items;
items.push_back(Item(name, sellIn, quality));
GildedRose app(items);
app.updateQuality();
auto &result = app.items[0];

EXPECT_EQ("Foo", result.name);
}

Item GildedRoseTest_Foo_Test::getItem(const char *name, int sellIn, int quality) const
{
vector<Item> items;
items.push_back(Item(name, sellIn, quality));
GildedRose app(items);
app.updateQuality();
auto &result = app.items[0];
return result;
}
I can of course fix this up with a little work, but I might have well have not used the automated refactoring tool in
the first place.

Am I doing something wrong or how should I get extract method to work?


 

0

请先登录再写评论。