Rails minitest无法到达控制器

时间:2019-06-14 21:29:13

标签: ruby-on-rails ruby-on-rails-5 minitest

我以前用测试构建过应用程序,但是由于某种原因,我的测试似乎无法到达控制器。遇到请求访问API服务器时,该应用程序运行正常。

与[这个问题(Rspec not reaching controller)不同,过滤器之前没有。

controllers / testing_controller.rb:

class TestingController < ActionController::API

  def testing
    puts "Success. Reached the Testing Controller."
    # The above line is never echoed in the console as it should when reached.
    render json: { body: "Success. Reached the Testing Controller." } and return
  end
end

tests / controllers / testing_controller_test.rb:

class TestingControllerTest < ActionDispatch::IntegrationTest

  def setup
    # Required for another app I built and tested.
    host! "localhost:3000"
  end

  test "should pass echo string" do
    post testing_url, params: {}
    response_parsed = JSON.parse(response.body)
    # JSON parsing error encountered at line above.
    puts response_parsed.inspect  # Returns nil if I remove the JSON parsing above.
  end
end

config / routes.rb:

Rails.application.routes.draw do
  post "testing", to: "testing#testing", as: "testing"
end

不确定这是否与路由有关...但是正如我所提到的,它仍然可以在测试之外使用。这些也是相同的类,但是也许我使用了错误的测试类?

0 个答案:

没有答案