1 describe "テスト1" do
23 it "テスト1-1"
45 it "テスト1-2"
67 end
8910 describe "テスト2" do
1112 it "テスト1-1" ←"テスト1"で作ったテストと同じ物を実行したい
1314 end
1516 describe "テスト3" do
1718 it "テスト3-1"
1920 it "テスト1" ←"テスト1"をそのまま実行したい
2122 end
describe MessageFilter, 'with argument "foo"' do
subject { MessageFilter.new('foo') }
it { is_expected.to be_detect('hello from foo') }
it { is_expected.not_to be_detect('hello, world') }
end
describe MessageFilter, 'with argument "foo","bar"' do
subject { MessageFilter.new('foo', 'bar') }
it { is_expected.to be_detect('hello from bar') }
it { is_expected.to be_detect('hello from foo') }
it { is_expected.not_to be_detect('hello, world') }
end
では
it { is_expected.to be_detect('hello from foo') }
it { is_expected.not_to be_detect('hello, world') }
が重複しています(というかコピペしただけです)。
これを
shared_examples 'MessageFilter with argument "foo"' do
it { is_expected.to be_detect('hello from foo') }
it { is_expected.not_to be_detect('hello, world!') }
end
describe MessageFilter, 'with argument "foo"' do
subject { MessageFilter.new('foo') }
it_behaves_like 'MessageFilter with argument "foo"'
end
describe MessageFilter, 'with argument "foo","bar"' do
subject { MessageFilter.new('foo', 'bar') }
it { is_expected.to be_detect('hello from bar') }
it_behaves_like 'MessageFilter with argument "foo"'
end
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。