我有一个包含以下内容的gemfile:
# frozen_string_literal: true
source "https://rubygems.org"
gem 'cucumber'
gem 'minitest', '~> 5.10', '>= 5.10.3'
gem 'minitest-focus'
gem 'minitest-reporters', '~> 1.1.9'
gem 'rspec'
...
用于加载并需要宝石的黄瓜.env文件:
require 'bundler'
Bundler.require
带有以下内容的Ruby文件:
require 'minitest/autorun'
require_relative './../../../../RubyProjects/mksta-common/common'
class VerifyApi < MiniTest::Test
include Common
def initialize(has_authorization)
@has_authorization = has_authorization
end
def test_id_correct
assert_equal(20, 20)
end
end
我在尝试执行断言时收到此错误:
未定义的方法`+'代表nil:NilClass
在Assertions.rb中:
def assert_equal exp, act, msg = nil
msg = message(msg, E) { diff exp, act }
result = assert exp == act, msg
if exp.nil? then
if Minitest::VERSION =~ /^6/ then
refute_nil exp, "Use assert_nil if expecting nil."
else
where = Minitest.filter_backtrace(caller).first
where = where.split(/:in /, 2).first # clean up noise
warn "DEPRECATED: Use assert_nil if expecting nil from #{where}. This will fail in Minitest 6."
end
end
result
end
def assert test, msg = nil
self.assertions += 1
unless test then
msg ||= "Expected #{mu_pp test} to be truthy."
msg = msg.call if Proc === msg
raise Minitest::Assertion, msg
end
true
end
错误发生在:“self.assertions + = 1”,所以我不确定“断言”的设置在哪里..
我想知道我的要求流程是否不正确,或者我是否缺少要求。或许Cucumber / Rspec正在阻碍?任何帮助将不胜感激。
答案 0 :(得分:1)
好吧,问题是当您初始化VerifyApi时,您没有初始化MiniTest :: Test。因此,self.assertions为零。 为了解决这个问题,您只需要在初始化函数中再添加一行
super(name)
当然,您需要在函数中添加一个参数。