在共享上下文中调用时,未定义通过config.extend(...)
注入的方法。
module Foo
def something
puts 'hi'
end
end
RSpec.configure do |config|
config.extend(Foo)
end
RSpec.shared_context 'shared' do
something
end
打印“嗨”
something
未定义
您能否提供更多有关如何使用该共享上下文的上下文? 我无法重现此行为:
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
我暂时将其关闭,然后调查到底出了什么问题。 感谢您的回复。 当我弄清楚时会报告。
我认为问题是在configure块中包含include上下文时发生的:
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行,看看是否有某些规格/功能失败。
您要认真解决问题吗?