簡體   English   中英

minitest:未定義的方法`get'

[英]minitest: undefined method `get'

我需要用minitest來測試我的控制器。 我試過了:

describe 'CommentsController' do
  it "should get index" do
    get :index
    assert_response :success
  end
end

class CommentsControllerTest < MiniTest::Unit::TestCase
  def test_should_get_index
    get :index
    assert_response :success
  end
end

但我有“未定義的方法`get'”錯誤

您應該按照文檔中列出的步驟添加minitest-rails gem。 那么你的測試應該是這樣的:

require "minitest_helper"

describe CommentsController do
  it "should get index" do
    get :index
    assert_response :success
  end
end

或者,看起來像這樣:

require "minitest_helper"

class CommentsControllerTest < MiniTest::Rails::ActionController::TestCase
  test "should get index" do
    get :index
    assert_response :success
  end
end

Rails Minitest 未定義方法 `greater_than_or_equal_to' for # <shoulda::matchers< div><div id="text_translate"><p> 我想在 Minitest 中使用 ShouldaMatchers gem 來檢查簡單的 model 驗證:</p><pre> class Portfolio &lt; ApplicationRecord validates:share_ratio, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 100 } end</pre><p> 為此,我有一個 Minitest:</p><pre> require 'test_helper' class PortfolioTest &lt; ActiveSupport::TestCase context 'validations' do should validate_numericality_of(:share_ratio).greater_than_or_equal_to(0) should validate_numericality_of(:share_ratio).is_less_than_or_equal_to(100) end end</pre><p> 但我收到一個錯誤:</p><blockquote><p> class:PortfolioTest':#Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher:0x00007fba91da3ce0 (NoMethodError) 的未定義方法“greater_than_or_equal_to”</p></blockquote><pre> #Gemfile: gem 'shoulda', '~&gt; 4.0' gem 'shoulda-matchers', '~&gt; 4.0'</pre><p> 我嘗試更改 model 內部的驗證:</p><pre> validates_numericality_of:share_ratio, greater_than_or_equal_to: 0, less_than_or_equal_to: 100</pre><p> 但是錯誤是一樣的。 </p></div></shoulda::matchers<>

[英]Rails Minitest undefined method `greater_than_or_equal_to' for #<Shoulda::Matchers

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 Minitest中未定義的方法“ get” Minitest-NoMethodError:未定義的方法`get&#39; 使用minitest未定義方法“有效”測試設計模型 NoMethodError:minitest 和 mocha 的未定義方法“模擬” Rails Minitest:ActiveStorage NoMethodError:未定義的方法“下載” minitest gem出錯:NoMethodError:NoMethodError:nil的未定義方法`env&#39;:NilClass * 類Minitest :: Unit的未定義方法_run_suites(NameError) MiniTest中的undefined方法`link_to_remote&#39;用於application_helper測試 Rails Minitest ActionView :: Template :: Error:nil:NilClas的未定義方法 Rails Minitest 未定義方法 `greater_than_or_equal_to' for # <shoulda::matchers< div><div id="text_translate"><p> 我想在 Minitest 中使用 ShouldaMatchers gem 來檢查簡單的 model 驗證:</p><pre> class Portfolio &lt; ApplicationRecord validates:share_ratio, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 100 } end</pre><p> 為此,我有一個 Minitest:</p><pre> require 'test_helper' class PortfolioTest &lt; ActiveSupport::TestCase context 'validations' do should validate_numericality_of(:share_ratio).greater_than_or_equal_to(0) should validate_numericality_of(:share_ratio).is_less_than_or_equal_to(100) end end</pre><p> 但我收到一個錯誤:</p><blockquote><p> class:PortfolioTest':#Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher:0x00007fba91da3ce0 (NoMethodError) 的未定義方法“greater_than_or_equal_to”</p></blockquote><pre> #Gemfile: gem 'shoulda', '~&gt; 4.0' gem 'shoulda-matchers', '~&gt; 4.0'</pre><p> 我嘗試更改 model 內部的驗證:</p><pre> validates_numericality_of:share_ratio, greater_than_or_equal_to: 0, less_than_or_equal_to: 100</pre><p> 但是錯誤是一樣的。 </p></div></shoulda::matchers<>
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM