์๋ ,
์ ๋ GNU Guix์ฉ์ผ๋ก ๋ช ๊ฐ์ง rubygem์ ํจํค์งํ์ผ๋ฉฐ ๊ฐ๋ ํ๊ณ ์ถ์ ํ ๊ฐ์ง๋ ํน์ ์์ ๋ฅผ ๋นํ์ฑํํ๋ ๊ฒ์
๋๋ค. rspec --example
ํ๋๊ทธ์ ๋ฐ๋๋ผ๊ณ ์๊ฐํฉ๋๋ค. ์ด๊ฒ์ ์๋ฅผ ๋ค์ด ํน์ ํ
์คํธ๊ฐ ์๋ ค์ง ์คํจ์ผ ์ ์๋ ๊ฒฝ์ฐ์ ์ ์ฉํฉ๋๋ค. ์๋ํ๋ ๋น๋ ์์คํ
์ '๊ฒ์ฌ' ๋จ๊ณ๋ฅผ ์คํํ ๋(๋ชจ๋ ํ
์คํธ๊ฐ ํต๊ณผํ์์ ๋ํ๋ด๊ธฐ ์ํด) 0 ์ข
๋ฃ ์ํ๋ฅผ ์๊ตฌํ๊ธฐ ๋๋ฌธ์
๋๋ค.
ํ ์คํธ ํ์ผ์ ํจ์นํ๋ ๊ฒ๊ณผ ๊ฐ์ ํด๊ฒฐ ๋ฐฉ๋ฒ์ด ์กด์ฌํ์ง๋ง rspec์ ์ฐ๋ฆฌ๋ฅผ ๋์ ํด ๋ฌ๋ผ๊ณ ์์ฒญํ ์ ์๋ค๋ฉด ์ถ์ด ๋ ์ฌ์์ง ๊ฒ์ ๋๋ค. ์ด ์์ ์ ์ด๋ฏธ ์ํํ ์ ์๋ ๋ฐฉ๋ฒ์ด ์์ต๋๊น? ์๋๋ฉด ์ด ๋ฌธ์ ๊ฐ ๊ธฐ๋ฅ ์์ฒญ์ ๋๊น?
๊ฐ์ฌ ํด์,
๋ฒค
๋ฉํ๋ฐ์ดํฐ ๋ฐ --tag
์: https://relishapp.com/rspec/rspec-core/v/3-4/docs/command-line/tag-option )๋ฅผ ํตํด ํ๋ก๊ทธ๋๋ฐ ๋ฐฉ์์ผ๋ก ์์ ๋ฅผ ํํฐ๋งํ ์ ์์ต๋๋ค. ๋ฉํ๋ฐ์ดํฐ(์: https://relishapp.com/rspec/rspec-core/v/3-4/docs/filtering/inclusion-filters ๋ฐ https://relishapp.com/rspec/rspec-core/v/3์ ํตํด ์กฐ๊ฑด๋ถ๋ก ํ๋ก๊ทธ๋๋ฐ ๋ฐฉ์)
์๋ง๋ ๋๋ ๋๋ฆฌ์ง๋ง ๊ทธ ๋งํฌ๊ฐ ์ด๋ป๊ฒ ๋์์ด๋๋์ง ๋ณผ ์ ์์ต๋๋ค. ์๋ง๋ ์์ ๊ฐ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๋ฐ ๋์์ด ๋ ๊ฒ์ ๋๋ค. ์๋ฅผ ๋ค์ด ์ด ์ฌ์์ด ์๋ ๊ฒฝ์ฐ:
$ cat ~/t/a.spec
require 'rspec'
class My
def self.answer
4
end
end
RSpec.describe My, "#answer" do
context 'good and bad' do
it 'gives the right answer' do
expect(My.answer).to eq 4
end
it 'gives the wrong answer' do
expect(My.answer).to eq -1
end
end
end
๊ทธ๋ ๋ค๋ฉด ๋ค์์ ๋ฌ์ฑํ๋ ๊ฒ์ ์ด๋ป๊ฒ ์คํํฉ๋๊น?
$ rspec ~/t/a.spec --exclude-example wrong
์ฌ์ ํ์ผ ์์ฒด๋ฅผ ์์ ํ์ง ์๋ ๋ฐฉ๋ฒ์ ์ฐพ๊ณ ์์ต๋๋ค.
๊ฐ์ฌ ํด์.
RSpec.describe "My#answer" do
context 'good and bad' do
it 'gives the right answer', type: :right do
expect(My.answer).to eq 4
end
it 'gives the wrong answer', type: :wrong do
expect(My.answer).to eq -1
end
end
end
$ rspec ~/t/a.spec --tag @right
๋๋ $ rspec ~/t/a.spec --tag ~@wrong
type: wrong
. ์ฌ์์ ์์ ํ์ง ์๊ณ ๋ ์ ์ฌํ ๊ฒ์ ๋ฌ์ฑํ ์ ์์ผ๋ฉฐ ์ด ๋ฌธ์ ๋ฅผ ๊ธฐ๋ฅ ์์ฒญ์ผ๋ก ๋ง๋๋ ๊ฒ์ด ๋ถ๊ฐ๋ฅํ๋ค๋ ๋ต๋ณ์ ๋ฃ์ต๋๊น?
--exclude-example
๋ฅผ ์ถ๊ฐํ๋ ๊ฒ์ด ํฉ๋ฆฌ์ ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
--exclude-example
๋ฅผ ์ถ๊ฐํ๋ ๊ฒ์ด ํฉ๋ฆฌ์ ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค.