我正在使用带有 Capybara 的 Rspec Rails 进行测试,我想使用新的 feature spec在 RSpec Rails 3 中,因为它们 read more as customer tests and acceptance tests
.但是,我发现旧的(Describe/It)样式中缺少的一件事是 嵌套 .尝试嵌套时 scenarios
或使用 background
内任意 scenario
阻止,我得到一个 undefined method
错误。无论如何,我是否可以通过功能规范实现嵌套以获得这样的东西(来自 Michael Hartl 的 Ruby On Rails Tutorial :
describe "Authentication" do
subject { page }
describe "authorization" do
let(:user) { FactoryGirl.create(:user) }
describe "for non-signed in users" do
describe "when attempting to visit a protected page" do
before { visit edit_user_path(user) }
it "should redirect_to to the signin page" do
expect(page).to have_title('Sign in')
end
describe "after signing in" do
before do
valid_signin user, no_visit: true
end
it "should render the desired protected page" do
expect(page).to have_title('Edit user')
end
或者我应该以不同的方式思考集成测试?
最佳答案
如 https://www.relishapp.com/rspec/rspec-rails/docs/feature-specs/feature-spec 中所述, feature
对应于 describe
和 scenario
对应于 it
.因此,您可以嵌套 feature
的实例。 ,但您不能嵌套 scenario
内scenario
,就像您不能嵌套 it
内it
.
关于ruby-on-rails - 在 Rspec Rails 3 中使用特性规范嵌套场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22466596/