我想在rails控制器规范中重用一些常见的代码。对于管理员用户和普通用户,我有不同的上下文。然而,许多行为是特定的行为一样,所以我尝试了拉那常见的行为变成一个辅助功能:在不同的rspec上下文中重复使用代码
describe SomeController do
def common_get_new
# common stuff
end
context "regular users" do
describe "GET new" do
common_get_new
end
end
context "admin users" do
describe "GET new" do
common_get_new
end
end
end
这给我的错误:
undefined local variable or method `common_get_new'
我在做什么错误?
什么是common_get_new - 安装的东西,调用应该,整个例子,别的东西? –
@FrederickCheung它不包含设置的东西。它有几个完整的例子。 – mushroom