メソッドをテストするために、2番目のテストでエラーundefined local variable or method 'params'
Minitest:どのように私は私のコードでメソッドをテストしようとしている
メソッドをテストするための正しい方法は何を返していますか?またはmain.rb
の設定方法を変更する必要がありますか?
コード:
require 'sinatra'
require 'sinatra/reloader'
def get_products_of_all_ints_except_at_index()
@array = [1, 7, 3, 4]
@total = 1
@index = params[:index].to_i
@array.delete_at(@index)
@array.each do |i|
@total *= i
end
end
get '/' do
get_products_of_all_ints_except_at_index
erb :home
end
テスト:
ENV['RACK_ENV'] = 'test'
require 'minitest/autorun'
require 'rack/test'
require_relative 'main.rb'
include Rack::Test::Methods
def app
Sinatra::Application
end
describe 'app' do
it 'should return something' do
get '/'
assert_equal(200, last_response.status)
end
it 'should return correct result' do
get_products_of_all_ints_except_at_index
assert_equal(24, @total)
end
end
これは助けるべきである:http://www.sinatrarb.com/testing.html すべてモック要求メソッドが同じ引数署名有する: GET '/パス'、paramsは= {}、rack_env = {} – SickLickWill