Rspec-core: السياق المشترك لا يعمل مع الطرق الموسعة

تم إنشاؤها على ١٦ ديسمبر ٢٠١٩  ·  5تعليقات  ·  مصدر: rspec/rspec-core

موضوع القضية

لم يتم تعريف الأساليب التي تم حقنها عبر config.extend(...) عند استدعائها ضمن السياقات المشتركة.

بيئتك

  • إصدار روبي: 2.6
  • إصدار rspec-core: 3.9.0

خطوات التكاثر

module Foo
  def something
    puts 'hi'
  end
end

RSpec.configure do |config|
  config.extend(Foo)
end

RSpec.shared_context 'shared' do
  something
end

سلوك متوقع

طباعة "مرحبا"

السلوك الفعلي

something غير محدد

Bug

ال 5 كومينتر

هل يمكنك تقديم سياق أكثر قليلاً لكيفية استخدام هذا السياق المشترك؟ لا يمكنني إعادة إنتاج هذا السلوك:

module Foo
  def something
    puts 'hi'
  end
end

RSpec.configure do |config|
  config.extend Foo
end

RSpec.shared_context 'shared' do
  something
end

RSpec.describe do
  include_context 'shared'

  it { }
end

النواتج:

$ rspec spec/a_spec.rb
hi
Run options: exclude {:ruby=>#<Proc:./spec/spec_helper.rb:99>}

Randomized with seed 10987


  example at ./spec/a_spec.rb:18

Finished in 0.00185 seconds (files took 1.19 seconds to load)
1 example, 0 failures

Randomized with seed 10987

سأغلق هذا الآن وسأحقق في ما هو الخطأ من جانبي بعد ذلك. شكرا للإستجابة. سوف يقدم تقريرا عندما اكتشف ذلك.

أعتقد أن المشكلة تحدث عند تضمين السياق داخل كتلة التكوين:

module Foo
  def something
    puts 'hi'
  end
end

RSpec.configure do |config|
  config.extend Foo
end

RSpec.shared_context 'shared' do
  something
end

RSpec.configure do |config|
  config.include_context 'shared', foo: :enabled
end

RSpec.describe "Foo", foo: :enabled do
  it { }
end

النواتج:

$ rspec spec/foo_spec.rb
An error occurred while loading ./spec/foo_spec.rb.
Failure/Error: something

NameError:
  undefined local variable or method `something' for RSpec::ExampleGroups::Foo:Class

No examples found.

Finished in 0.00017 seconds (files took 1.35 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples

pirj لقد أعدت فتح المشكلة منذ أن قدم tubaxenor المثال الفاشل.

شكرا لمثال التكاثر.
أظن أنه أمر التضمين. نقاط التصحيح السريع عند lib/rspec/core/configuration.rb:1513 .

من المنطقي التمديد أولاً ، ثم تضمينه بعد ذلك. هل يمكنك التفكير في مثال جيد عندما تحتاج الوحدة إلى شيء محدد في السياق المشترك؟

يمكنك محاولة تبديل السطور 1513 و 1514 ومعرفة ما إذا كانت بعض المواصفات / الميزات تفشل.

هل تريد معالجة المشكلة بعناية؟

هل كانت هذه الصفحة مفيدة؟
0 / 5 - 0 التقييمات