【发布时间】:2016-02-12 05:26:19
【问题描述】:
我正在做一些模块化的 Sinatra 应用程序并使用 rspec 和 Capybara 进行测试。问题是我在尝试访问页面时总是收到“未找到”错误 404。当我使用命令“bundle exec rackup”并转到相同的 url 但在浏览器中一切正常。这是我的规格:
require "spec_helper"
require_relative '../../routes/user_routes'
set :environment, :test
RSpec.describe RubyPlay, type: :feature do
include Rack::Test::Methods
def app
RubyPlay # this defines the active application for this test
end
before { visit '/' }
it "should allow accessing the home page" do
p page.html # prints Not found
p page.status_code # 404
expect(page).to have_content 'Ruby Play'
end
end
捆绑 exec rspec:
RubyPlay should allow accessing the home page
Failure/Error: expect(page).to have_content 'Ruby Play'
expected to find text "Ruby Play" in "Not Found"
我从未在 Sinatra 中做过测试,也不知道可能出了什么问题... :)
【问题讨论】:
标签: ruby rspec sinatra capybara http-status-code-404