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
'hi'λ₯Ό μΈμν©λλ€.
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
μ§κΈμμ΄ λ¬Έμ λ₯Ό ν΄κ²°νκ³ λ΄ μͺ½μμ 무μμ΄ μλͺ»λμλμ§ μ‘°μ¬νκ² μ΅λλ€. μλ΅ ν΄ μ£Όμ μ κ°μ¬ν©λλ€. λ΄κ° μμ λ΄λ©΄ λ€μλ³΄κ³ νκ² μ΅λλ€.
κ΅¬μ± λΈλ‘ λ΄λΆμ 컨ν μ€νΈλ₯Ό ν¬ν¨νλ©΄ λ¬Έμ κ° λ°μνλ€κ³ μκ°ν©λλ€.
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
@tubaxenorκ° μ€ν¨ν μλ₯Ό μ 곡νκΈ° λλ¬Έμ @pirj λλμ΄ λ¬Έμ λ₯Ό μ¬κ°νμ΅λλ€.
볡μ μλ₯Ό λ€μ΄ μ£Όμ
μ κ°μ¬ν©λλ€.
λλ κ·Έκ²μ΄ ν¬ν¨ λͺ
λ Ήμ΄λΌκ³ μκ°ν©λλ€. lib/rspec/core/configuration.rb:1513
λΉ λ₯Έ λλ²κ·Έ μ§μ .
λ¨Όμ νμ₯νκ³ μ΄νμ ν¬ν¨νλ κ²μ΄ μ’μ΅λλ€. λͺ¨λμ΄ κ³΅μ 컨ν μ€νΈμ μ μ λ κ²μ νμλ‘ ν λ μ’μ μλ₯Ό μκ°ν μ μμ΅λκΉ?
1513 λ° 1514 νμ λ°κΎΈμ΄ μλνκ³ μΌλΆ μ¬μ / κΈ°λ₯μ΄ μ€ν¨νλμ§ νμΈν μ μμ΅λλ€.
λ¬Έμ λ₯Ό μ‘°μ¬μ€λ½κ² λ€λ£¨κ³ μΆμ΅λκΉ?