目前我的代码如下所示:
it "Doesn't Access the Admin Panel"
it "Doesn't see New Project button"
it "Doesn't create new news"
it "Doesn't access New Project page"
it "Sees Projects"
it "Sees news"
it "Doesn't edit projects"
it "Doesn't edit news"
正如您所看到的,几乎所有测试都成对出现。我是否可以通过某种方式参与这些测试,例如创建一种接受争论的方法,无论它是否是一个新闻'或者'项目'?
OR 这不是做事的方法吗?我想遵循最佳实践,而不是尝试创建一些新的编码风格。
答案 0 :(得分:1)
您可以使用反映上下文的标题在describe块中嵌套示例:
describe "When logged in as an admin" do
let(:user) { admin_user }
it "can view the project" do
# ...
end
end
describe "When logged in as a guest" do
let(:user) { guest_user }
it "cannot view the project" do
# ...
end
end
有关更多示例,请参阅RSpec documentation。