zoukankan      html  css  js  c++  java
  • rspec-rails中的一些匹配器只有在特定的类型才能使用。

    请求测试

    render_template:

    expect(response).to render_template("new")

     redirect_to

    expect(response).to redirect_to(widgets_path)

    请求测试,功能测试: 

     have_http_status (:error/:missing/:redirect/:success)

    在功能测试:

    expect(page).to have_http_status(:success)

    在请求测试:

    expect(response).to have_http_status(201)
    expect(response).not_to have_http_status(:created)




     Model Specs描述模型的行为,一般基于数据库。

     

     Request Spec

    主要是:给了一个request,HTTP的响应response。 也可以叫integration。

    请求测试一般在spec/requests, spec/api, spec/integration目录,标志:type => :require 

    请求测试混入了Rails集成测试的模块Runner中的行为。

    很多开发者喜欢FactoryBot/Capybara一起用在请求测试。 

    require 'rails_helper'
    
    RSpec.describe "home page", :type => :request do
      it "displays the user's username after successful login" do
        user = FactoryBot.create(:user, :username => "jdoe", :password => "secret")
        visit "/login"
        fill_in "Username", :with => "jdoe"
        fill_in "Password", :with => "secret"
        click_button "Log in"
    
        expect(page).to have_selector(".header .username", :text => "jdoe")
      end
    end

    因此没有使用get "/login"这种HTTP verb加路径url的定位.

    Feature Specs从外部模仿浏览器。如果使用Capybara,请求测试和功能测试,集成测试都差不多。 

  • 相关阅读:
    jquery index与eq
    尝试一下
    document
    2017-03-28 java script DOM操作
    2017-03-25 CSS 样式
    CSS 样式表分类
    CSS 样式表
    HTML 框架
    表格
    HTML常用标记
  • 原文地址:https://www.cnblogs.com/chentianwei/p/9173759.html
Copyright © 2011-2022 走看看