ruby-on-rails - 在 Rspec Rails 3 中使用特性规范嵌套场景

标签 ruby-on-rails rspec ruby-on-rails-4 capybara integration-testing

我正在使用带有 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对应于 describescenario对应于 it .因此,您可以嵌套 feature 的实例。 ,但您不能嵌套 scenarioscenario ,就像您不能嵌套 itit .

关于ruby-on-rails - 在 Rspec Rails 3 中使用特性规范嵌套场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22466596/

相关文章:

ruby-on-rails - 从模型内部获取未保存的关联

ruby-on-rails - Rails Cells 似乎没有缓存

ruby-on-rails - 无法模拟数据库和 stub :save

ruby-on-rails - 如何在 Capybara finder 中使用正则表达式?

ruby-on-rails - ruby : Execute method in context of base class

ruby-on-rails - 使用 Bootstrap 3 进行 Sass/Rails 表单验证

ruby-on-rails - 无方法错误 : undefined method `call'

ruby-on-rails - 插入记录时主键上的Postgresql唯一违规

ruby-on-rails - Rails 3.1 和 Heroku - 即使使用 'therubyracer-heroku' 仍然无法工作

ruby-on-rails - 如何在不使用 eval 方法的情况下使用带有参数化代码的 RSpec 创建共享示例以进行测试?