Ruby 在使用Sinatra+;小型试验

Ruby 在使用Sinatra+;小型试验,ruby,sinatra,minitest,Ruby,Sinatra,Minitest,我的配置如下: Rakefile source 'https://rubygems.org' gem 'sinatra' gem 'thin' gem 'rack-test' Gemfile source 'https://rubygems.org' gem 'sinatra' gem 'thin' gem 'rack-test' spec\u helper.rb ENV['RACK_ENV'] = 'test' require 'minitest/autorun' require '

我的配置如下:

Rakefile

source 'https://rubygems.org'

gem 'sinatra'
gem 'thin'
gem 'rack-test'
Gemfile

source 'https://rubygems.org'

gem 'sinatra'
gem 'thin'
gem 'rack-test'
spec\u helper.rb

ENV['RACK_ENV'] = 'test'

require 'minitest/autorun'
require 'rack/test'
require_relative '../app'

include Rack::Test::Methods

def app
  MyApp
end
require_relative 'spec_helper'

describe 'Hello World' do

  it 'should have hello world' do
    get '/'
    last_response.must_be :ok?
    # I want to do something like below
    last_response.title must_match /home page/i
  end
end
应用程序规范rb

ENV['RACK_ENV'] = 'test'

require 'minitest/autorun'
require 'rack/test'
require_relative '../app'

include Rack::Test::Methods

def app
  MyApp
end
require_relative 'spec_helper'

describe 'Hello World' do

  it 'should have hello world' do
    get '/'
    last_response.must_be :ok?
    # I want to do something like below
    last_response.title must_match /home page/i
  end
end

如何使用MiniTest和Sinatra测试视图的页面标题。

您不能仅使用
MiniTest
检查此问题

要实现这一点,您应该查看

Capybara通过模拟真实用户的行为来帮助您测试web应用程序 将与你的应用程序交互

设置完成后,使用匹配器测试呈现页面的标题

使用Capybara,您可以测试页面的各个方面,如内容/文本、是否有特定链接、特定按钮、文本字段、电子邮件字段等。
您可以模拟填写表单并单击按钮提交表单的行为。简单地说,它的行为就像一个真正的用户一样,通过模拟用户在给定页面上可以执行的操作,以及用户在给定页面上可以看到的内容

@ArupRakshit你能接受答案来解决这个问题吗?