λλ λͺ¨λ μΌλ ¨μ λ©μλλ₯Ό ꡬννλ μ€λ¦¬ μ ν ν΄λμ€ λͺ¨μμ κ°μ§κ³ μμ΅λλ€.
λλ μ΄λ¬ν λ°©λ²μ μ€λͺ
νλ 곡μ μμ κ·Έλ£Ήμ λ§λ€ μ μμ΅λλ€.
shared_examples_for "a duck type" do
it { should respond_to(:method1) }
end
describe Class1 do
it_should_behave_like "a duck type"
end
describe Class2 do
it_should_behave_like "a duck type"
end
μ μν©μμλ Class1#method1
ꡬννμ§λ§ Class2#method1
κ° λ³΄λ₯ μ€μ
λλ€.
μ λ λ€μκ³Ό κ°μ΄ λ§ν μ μλ λ₯λ ₯μ μν©λλ€.
describe Class2 do
it_should_behave_like "a duck type", :pending
end
pending
λ₯Ό 곡μ μμ μ μ μ©ν μ μμ§λ§ it_should_behave_like
μλ μ μ©ν μ μμ΅λλ€. μ΄κ²μ μΌλΆ ν΄λμ€ κ΅¬νμ΄ μλ£λκ³ λ€λ₯Έ ν΄λμ€ κ΅¬νμ΄ λ³΄λ₯ μ€μΈ μ€λ¦¬ μ ν λͺ¨μμΌλ‘ μμ
ν λ μ°¨μ μ±
μ
λλ€.
κ°μ μμ²:
1) it_should_behave_like
λν΄ :pending
μμ±μ νμ±νν©λλ€.
2) it_should_behave_like
λν΄ :skip
μμ±μ νμ±νν©λλ€.
3) xit_should_behave_like
it_should_behave_like
μ λ¬λ μΈμλ λ€λ₯Έ λͺ©μ μ κ°μ§κ³ μμ΅λλ€. 곡μ λ μμ κ·Έλ£Ή λΈλ‘μ μ보λ©λλ€.
https://relishapp.com/rspec/rspec-core/v/3-0/docs/example-groups/shared-examples#passing -parameters-to-a-shared-example-group
μΈμλ₯Ό λ©νλ°μ΄ν°λ‘ μ·¨κΈνλ κ²λ νΌλμ€λ¬μΈ κ²μ λλ€. νμ§λ§ μνλ λμμ μ»μ μ μμ΅λλ€.
shared_examples_for "a duck type" do |*metadata|
context "describe this group", *metadata do
# put the specs in here.
end
end
λλ μΆκ° 컨ν
μ€νΈμμ μ¬μμ λννμ§ μμΌλ €λ©΄ before
νν¬λ‘ pending
λλ skip
λ₯Ό μ§μν μ μμ΅λλ€.
shared_examples_for "a duck type" do |*flags|
before { pending } if flags.include?(:pending)
# specs go here
end
μ, λλ¨ν κ°μ¬ν©λλ€. μλ²½νκ² μλν κ²μ λλ€.
λ€λ₯Έ μ¬λμ΄ Googleμ ν΅ν΄ μ΄ λ¬Έμ λ₯Ό λ°κ²¬νλ©΄ λ€μκ³Ό κ°μ΄ νΈμΆ μ¬μ΄νΈμμ μ¬μ©ν μ μλ λ λ€λ₯Έ νΈλ¦μ΄ μμ΅λλ€. λ©νλ°μ΄ν° λλ νλκ·Έ μΈμλ₯Ό μ¬μ©νκΈ° μν΄ κ³΅μ μμ μ μλ₯Ό μμ ν νμκ° μμ΅λλ€.
it_behaves_like 'some shared example' do
before { pending }
end
λλ λ¬Έμ κ° λ€μ μ΄λ €μΌ νκ³ λ€μ μ€ νλκ° μνλμ΄μΌ νλ€κ³ μκ°ν©λλ€.
pending('Reason for pending') do
it_behaves_like '...'
context do
...
end
end
@andyl
μλνκ³ μΆλ€λ©΄ λ¬Έμλ₯Ό κ°μ νκΈ° μν΄ PRμ μλ½νκ² λμ΄ κΈ°μ©λλ€. νμ§λ§ μ΄ λμμ λ³κ²½νκΈ° μν΄ APIλ₯Ό νμ₯ν΄μΌ νλ€κ³ μκ°νμ§ μμ΅λλ€.
κ°μ₯ μ μ©ν λκΈ
λ€λ₯Έ μ¬λμ΄ Googleμ ν΅ν΄ μ΄ λ¬Έμ λ₯Ό λ°κ²¬νλ©΄ λ€μκ³Ό κ°μ΄ νΈμΆ μ¬μ΄νΈμμ μ¬μ©ν μ μλ λ λ€λ₯Έ νΈλ¦μ΄ μμ΅λλ€. λ©νλ°μ΄ν° λλ νλκ·Έ μΈμλ₯Ό μ¬μ©νκΈ° μν΄ κ³΅μ μμ μ μλ₯Ό μμ ν νμκ° μμ΅λλ€.