Ruby on rails 如何组织集成规范

Ruby on rails 如何组织集成规范,ruby-on-rails,rspec,capybara,Ruby On Rails,Rspec,Capybara,有了rspec,你应该如何组织你的单位规格就很清楚了。spec中的目录结构与app目录中的目录结构非常相似,因此模型规格位于model目录中,控制器规格位于controller目录中,依此类推 但是对于集成测试来说还不是很清楚。我只有一个关于集成测试的文件:spec/features/integration.rb 创建一个详细的规范来测试应用程序的每一个功能,这是一个好主意吗?大概是这样的: require 'spec_helper' describe "Everything", js: tr

有了rspec,你应该如何组织你的单位规格就很清楚了。
spec
中的目录结构与
app
目录中的目录结构非常相似,因此模型规格位于
model
目录中,控制器规格位于
controller
目录中,依此类推

但是对于集成测试来说还不是很清楚。我只有一个关于集成测试的文件:
spec/features/integration.rb

创建一个详细的规范来测试应用程序的每一个功能,这是一个好主意吗?大概是这样的:

require 'spec_helper'

describe "Everything", js: true do
    before do
            @user_0 = FactoryGirl.build(:user_0)
            @user_1 = FactoryGirl.build(:user_1)
            @user_2 = FactoryGirl.build(:user_2)
            @user_3 = FactoryGirl.build(:user_3)
    end


    it "can create a user" do


            visit root_path
            click_link 'Sign In'

            ap @user_0

            fill_in('Email', with: @user_0.email)
            fill_in('Password', with: @user_0.password)
            click_button 'Sign in'
            visit('/user_friendships')       
        end

        it "can create a user" do
        end

        it "can create a user" do
        end

        it "can create a user" do
        end    

        it "GET /root_path" do
            visit root_path
            page.should have_content("All of our statuses")
            click_link "Post a New Status"
            page.should have_content("New status")
            fill_in "status_content", with: "Oh my god I am going insaaaaaaaaane!!!"
            click_button "Create Status"
            page.should have_content("Status was successfully created.")
            click_link "Statuses"
            page.should have_content("All of our statuses")                       
            page.should have_content("Jimmy balooney")
            page.should have_content("Oh my god I am going insaaaaaaaaane!!! ")
        end
end
但时间要长得多


我应该使用多个文件吗?我应该如何使用描述块?我现在只使用了一个,这感觉不太对。

简短的回答是:不,它不是要放在一个文件中

较大的项目根据功能集将验收测试套件拆分为文件。如果你有很多测试,它们通常被分成不同的目录。组织这些测试的方式取决于您。我在这里看到了很多不同的方法。我倾向于将规范与数据库设置(也称为测试数据)的类似要求分组


如果你想为你的rspec测试提供一个很好的指南,那么去看看这个网站:

通常需要在你的应用程序中按页面或流程划分集成测试

例如,您可以尝试:

#spec/users/sign_in_spec.rb
RSpec.description“用户登录”,js:true do
让我来!(:user){FactoryGirl.build(:user_0)}
它“可以登录”吗
访问根路径
单击链接“登录”
填写('Email',使用:user.Email)
填写('Password',使用:user.Password)
单击按钮“登录”
第页应包含内容(“已登录”)
结束
结束
#spec/status/manage_status.rb
RSpec.description'status',js:true do
它“应该能够发布状态”吗
访问根路径
第页应包含内容(“我们的所有状态”)
单击链接“发布新状态”
在“状态内容”中填写:“一切正常”
单击按钮“创建状态”
page.com应具有_内容(“状态已成功创建”)
单击链接“状态”
第页应包含内容(“我们的所有状态”)
page.应该有_内容(“一切正常”)
结束
结束
如果您正在寻找一种组织规范的方法,那么可以使用来封装代码并使测试更具可读性。例如:

#spec/users/sign_in_spec.rb
RSpec.description'Users Sign-In',js:true,test_helpers:[:login]do
让我来!(:user){FactoryGirl.build(:user_0)}
它“可以登录”吗
访问根路径
登录。输入_凭据(电子邮件:user.email,密码:user.password)
当前页面应具有内容(“已登录”)
结束
结束
#spec/status/manage_status.rb
RSpec.description'Statuses',js:true,test_helpers:[:Statuses]do
它“应该能够发布状态”吗
访问根路径
当前页面应包含内容(“我们的所有状态”)
statuses.post('一切正常')
状态。现在应该。有状态('一切正常')
结束
结束

好的,很酷,描述块是否像单元规范中使用上下文一样使用?命名和组织的常用方法是使用模式,如
actor\u does\u what\u spec.rb
。例如,
user\u在规范rb中签名或
user\u评论文章规范rb