Я пишу эти спецификации, тестируя различные параметры, которые поступают на контроллер. Существуют некоторые типовые варианты, которые я обнаруживаю, чтобы установить пол, и на основе этого я обновляю пользователя как мужчина или женщина, но я вижу, что его взгляд очень повторяющийся.Как реорганизовать, упростить этот код rspec
Поскольку параметр действительно происходит после каждого из них, я не вижу, как я могу это упростить. Любая идея, как я могу упростить этот код?
describe "GET #create" do
it { get :create; expect(response).to have_http_status(:success) }
context "Signup Step #1" do
before(:each) do
@user = build(:user)
end
context "Male" do
context "HOMBRE" do
before { get :create, full_message: "hombre", user_name: @user.name }
it { expect(User.last.gender).to eq(:male) }
it { expect(response.body).to have_text("returned text okay") }
it { expect(User.last.messages.count).to eq(3) }
end
context "HOMVRE" do
before { get :create, full_message: "homvre", user_name: @user.name }
it { expect(User.last.gender).to eq(:male) }
it { expect(response.body).to have_text("returned text okay") }
it { expect(User.last.messages.count).to eq(3) }
end
end
context "Female" do
context "MUJER" do
before { get :create, full_message: "mujer", user_name: @user.name }
it { expect(User.last.gender).to eq(:female) }
it { expect(response.body).to have_text("returned text okay") }
it { expect(User.last.messages.count).to eq(3) }
end
context "MUGER" do
before { get :create, full_message: "muger", user_name: @user.name }
it { expect(User.last.gender).to eq(:female) }
it { expect(response.body).to have_text("returned text okay") }
it { expect(User.last.messages.count).to eq(3) }
end
end
end
end