동일한 컨트롤러에서 다양한 동작을 테스트해야하는 다음과 같은 테스트가 있습니다. 이걸 어떻게 말릴 수 있니? 아래 주석에서 테스트 할 액션에 따라 테스트가 다른 메소드와 액션을 호출해야한다는 것을 알 수 있습니다. 당신은 예제 루프의 어떤 종류를 사용할 수,같은 컨트롤러에서 다른 동작에 의해 공유되는 RSpec 테스트를 마르는 방법
shared_examples_for "preparing for edit partial" do
let(:action){ get :new }
it "creates a new staff vacation" do
StaffVacation.should_receive(:new)
action
end
it "assigns @first_day_of_week" do
action
assigns(:first_day_of_week).should == 1
end
end
context 'GET new' do
it_should_behave_like 'preparing for edit partial' do
let(:action){ get :new }
end
end
context 'GET edit' do
it_should_behave_like 'preparing for edit partial' do
let(:action){ get :edit }
end
end
context 'POST create' do
it_should_behave_like 'preparing for edit partial' do
let(:action){ post :create }
end
end
을 또는 :
['get :new', 'get :edit', 'post :create'].each do |action|
context action do
it "creates a new staff vacation" do
StaffVacation.should_receive(:new)
eval(action)
end
it "assigns @first_day_of_week" do
eval(action)
assigns(:first_day_of_week).should == 1
end
end
end