하는 방법을 테스트하기 위해,하지만 두 번째 테스트가 오류 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