【问题标题】:I need help in building this Rails application我需要帮助来构建这个 Rails 应用程序
【发布时间】:2020-05-17 05:37:23
【问题描述】:

这个错误一直困扰着我

Recipes App
  displays 'Recipes for chocolate' when visiting the root (FAILED - 1)
  displays 'Recipes for chocolate' when visiting recipes/index (FAILED - 2)
  displays page for alternate search term (bread) (FAILED - 3)
  displays utf-8 chars in the title correctly (FAILED - 4)
  examine page content (view) after visiting recipes/index
    displays table header row with 3 columns (FAILED - 5)
    displays table element that has a row with 3 columns (FAILED - 6)
    column 1 should have the thumbnail inside img tag inside a link tag (FAILED - 7)
    title should be inside a second column inside a link tag (FAILED - 8)

Failures:

  1) Recipes App displays 'Recipes for chocolate' when visiting the root
     Failure/Error: visit '/'

     OpenSSL::SSL::SSLError:
       SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate)
     # ./spec/recipes_app_spec.rb:5:in `block (2 levels) in <top (required)>'

  2) Recipes App displays 'Recipes for chocolate' when visiting recipes/index
     Failure/Error: visit '/recipes/index'

     OpenSSL::SSL::SSLError:
       SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate)
     # ./spec/recipes_app_spec.rb:10:in `block (2 levels) in <top (required)>'

  3) Recipes App displays page for alternate search term (bread)
     Failure/Error: visit "recipes/index?search=bread"

     OpenSSL::SSL::SSLError:
       SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate)
     # ./spec/recipes_app_spec.rb:15:in `block (2 levels) in <top (required)>'

  4) Recipes App displays utf-8 chars in the title correctly
     Failure/Error: visit "/recipes/index?search=amarula"

     OpenSSL::SSL::SSLError:
       SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate)
     # ./spec/recipes_app_spec.rb:20:in `block (2 levels) in <top (required)>'

  5) Recipes App examine page content (view) after visiting recipes/index displays table header row 
with 3 columns
     Failure/Error: before { visit '/recipes/index' }

     OpenSSL::SSL::SSLError:
       SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate)
     # ./spec/recipes_app_spec.rb:25:in `block (3 levels) in <top (required)>'

  6) Recipes App examine page content (view) after visiting recipes/index displays table element that has a row with 3 columns
     Failure/Error: before { visit '/recipes/index' }

     OpenSSL::SSL::SSLError:
       SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate)
     # ./spec/recipes_app_spec.rb:25:in `block (3 levels) in <top (required)>'

  7) Recipes App examine page content (view) after visiting recipes/index column 1 should have the thumbnail inside img tag inside a link tag
     Failure/Error: before { visit '/recipes/index' }

     OpenSSL::SSL::SSLError:
       SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate)
     # ./spec/recipes_app_spec.rb:25:in `block (3 levels) in <top (required)>'

  8) Recipes App examine page content (view) after visiting recipes/index title should be inside a second column inside a link tag
     Failure/Error: before { visit '/recipes/index' }

     OpenSSL::SSL::SSLError:
       SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate)
     # ./spec/recipes_app_spec.rb:25:in `block (3 levels) in <top (required)>'

Finished in 10.74 seconds (files took 1.55 seconds to load)
8 examples, 8 failures

Failed examples:

rspec ./spec/recipes_app_spec.rb:4 # Recipes App displays 'Recipes for chocolate' when visiting the 
root
rspec ./spec/recipes_app_spec.rb:9 # Recipes App displays 'Recipes for chocolate' when visiting recipes/index
rspec ./spec/recipes_app_spec.rb:14 # Recipes App displays page for alternate search term (bread)   
rspec ./spec/recipes_app_spec.rb:19 # Recipes App displays utf-8 chars in the title correctly       
rspec ./spec/recipes_app_spec.rb:27 # Recipes App examine page content (view) after visiting recipes/index displays table header row with 3 columns
rspec ./spec/recipes_app_spec.rb:34 # Recipes App examine page content (view) after visiting recipes/index displays table element that has a row with 3 columns
rspec ./spec/recipes_app_spec.rb:38 # Recipes App examine page content (view) after visiting recipes/index column 1 should have the thumbnail inside img tag inside a link tag
rspec ./spec/recipes_app_spec.rb:42 # Recipes App examine page content (view) after visiting recipes/index title should be inside a second column inside a link tag

我已经厌倦了,我想放弃这个过时的课程。

this is the source code

该应用程序在 rails s 命令中运行良好,我对此很有信心,只需要添加一个清理代码,我可以做到,但我不知道有什么问题该死的 rspec 或 OpenSSL 可能。我正在使用 Ruby 2.6.6p146 ,并且已将所有 gem 更新到最新、稳定和兼容的版本。

我什至尝试了 Railsinstaller 中的 cacert.pem ,然后尝试了环境变量(之前有 Ruby 2.3.x)方法,然后删除了 Railsinstaller 并在里面安装了新的 Ruby 2.6.x 和 'default_options.update(verify: false) em>recipe.rb' 方法。 没有任何效果。

This is my code below , and only files inside app and config have been changed , just drag and drop

【问题讨论】:

  • 规范是否尝试连接到外部服务?
  • 我没有检查你的代码,但是这些错误通常是因为浏览器无法安全地连接到外部 API
  • 有一种方法可以禁用 SSL 验证,这是您不应该在生产环境中执行的操作,但在您的测试环境中可能可以执行此操作。你研究过吗?
  • 我是 ruby​​ 的初学者。我不知道你们都在说什么。我不确定身份验证和其他东西,但如果它现在有效,我会非常高兴。
  • 理解阿什维思。 Rkarla 的回答对我来说看起来不错。希望这对你有用。在 Wikipedia 上查找 SSL 的内容仍然很好,无论您的 Ruby 级别如何,都很好了解

标签: ruby-on-rails ruby rspec openssl


【解决方案1】:

如果你为test 环境这样做应该没问题

# Add to config/application.rb
if Rails.env.test?
  OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
end

注意: 我不会这样做 production 环境

【讨论】:

  • 我认为这是针对较新的 Rails 版本,最好是 5 或 6。Rails 4 有这个问题,尤其是 Railsinstaller。
【解决方案2】:

下载 cacert.pem,并添加 SSL 路径。它工作正常。

https://gist.github.com/fnichol/867550

此外,如果可能,请避免使用 Railsinstaller,而使用 Rubyinstaller。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-02
    • 1970-01-01
    相关资源
    最近更新 更多