我使用的是minitest 5.8.4和rspec-rails 3.5.1。我们目前有一个使用minitest的测试套件,但我会慢慢迁移到rspec。
我目前有很多测试,它们的结构如下:
class UserTest < ActiveSupport::TestCase
describe "a_method" do
it "should return the results" do
assert_a_thing
end
end
end一旦我在Gemfile中包含了rspec-rails,似乎describe方法就会被RSpec全局重载/采用,当我运行rake test时,它就会跳过所有这些测试。
test 'foo' {it 'works' {}}结构中的测试不会被跳过。
我如何才能轻松地让我的新RSpec测试和使用describe的现有迷你测试和平共存呢?
发布于 2016-07-22 23:59:45
我想这是因为rspec's monkey patching。在你的spec_helper中禁用猴子补丁。
RSpec.configure do |c|
c.disable_monkey_patching!
end然后,您需要在您的规格中包含以下内容
RSpec.describe "whatever" do
# any describe, scenario, it blocks here don't need the RSpec. prefix
end发布于 2021-06-29 05:47:44
在j-dexx's answer上扩展,一旦你删除了describe的RSpec版本,你就可以用另一个猴子补丁添加回最小的版本。我在this commit中为《厨师最小的处理程序-食谱》做过类似的事情。我的是基于minitest/spec在4.7.3中的外观,但我非常确定它在新的迷你版本中也是类似的。
RSpec.configure { |c| c.disable_monkey_patching! }
[RSpec::Core::DSL.top_level, Module].each do |klass|
klass.class_exec do
# copied from minitest/spec
# https://github.com/seattlerb/minitest/blob/v5.14.4/lib/minitest/spec.rb#L75-L90
def describe desc, *additional_desc, &block # :doc:
stack = Minitest::Spec.describe_stack
name = [stack.last, desc, *additional_desc].compact.join("::")
sclas = stack.last || if Class === self && kind_of?(Minitest::Spec::DSL) then
self
else
Minitest::Spec.spec_type desc, *additional_desc
end
cls = sclas.create name, desc
stack.push cls
cls.class_eval(&block)
stack.pop
cls
end
end
endhttps://stackoverflow.com/questions/38530663
复制相似问题