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,请求测试和功能测试,集成测试都差不多。 

  • 相关阅读:
    uvm_misc——杂货铺(miscellaneous)
    23种设计模式及其应用场景
    Hadoop TextInputFormat源码分析
    java字符串替换函数高效实现
    hadoop HA 之 QJM
    中文分词词性对照表
    计算两个字符串编辑距离
    java 图片处理
    zookeeper数据迁移
    正则表达式
  • 原文地址:https://www.cnblogs.com/chentianwei/p/9173759.html
Copyright © 2011-2022 走看看