Splits long lines in more readable ones
Those tests have too long lines. We have to split the to have more readable ones. This is based on a real project with Ruby and RSpec.
Start file
require 'spec_helper' describe ContentsController, type: :controller do before :each do set_request_on_domain :domain_test sign_in users(:admin) end describe '#update_categories' do let(:content) { contents(:adsl_cancel_question).set(intervention: nil) } it 'is success' do put :update_categories, id: content.id, category_ids: [categories(:mobile).id, categories(:technical).id], thread_id: content_threads(:adsl_cancel).id expect(response).to be_success expect(response.body).to be_blank end it 'is success if mandatory categories are not specified' do expect { put :update_categories, id: content.id, category_ids: [], thread_id: content_threads(:adsl_cancel).id }.to_not change { content } expect(response).to be_success end it 'updates categories' do expect { put :update_categories, id: content.id, category_ids: [categories(:mobile).id, categories(:technical).id], thread_id: content_threads(:adsl_cancel).id }.to change { content.reload.categories.to_a.sort }.from(array_including([categories(:internet), categories(:sales)])).to(array_including([categories(:technical), categories(:mobile)])) end it 'sets categories' do expect { put :update_categories, id: contents(:new_smartphone).id, category_ids: [categories(:mobile).id, categories(:technical).id], thread_id: content_threads(:new_smartphone).id }.to change { contents(:new_smartphone).reload.categories.to_a.sort }.from([]).to([categories(:technical), categories(:mobile)]) end end end
End file
require 'spec_helper' describe ContentsController, type: :controller do before :each do set_request_on_domain :domain_test sign_in users(:admin) end describe '#update_categories' do let(:content) { contents(:adsl_cancel_question).set(intervention: nil) } it 'is success' do put :update_categories, id: content.id, category_ids: [categories(:mobile).id, categories(:technical).id], thread_id: content_threads(:adsl_cancel).id expect(response).to be_success expect(response.body).to be_blank end it 'is success if mandatory categories are not specified' do expect { put :update_categories, id: content.id, category_ids: [], thread_id: content_threads(:adsl_cancel).id }.to_not change { content } expect(response).to be_success end it 'updates categories' do expect { put :update_categories, id: content.id, category_ids: [categories(:mobile).id, categories(:technical).id], thread_id: content_threads(:adsl_cancel).id }.to change { content.reload.categories.to_a.sort } .from(array_including([categories(:internet), categories(:sales)])) .to(array_including([categories(:technical), categories(:mobile)])) end it 'sets categories' do expect { put :update_categories, id: contents(:new_smartphone).id, category_ids: [categories(:mobile).id, categories(:technical).id], thread_id: content_threads(:new_smartphone).id }.to change { contents(:new_smartphone).reload.categories.to_a.sort } .from([]) .to([categories(:technical), categories(:mobile)]) end end end
View Diff
13c13,16 < put :update_categories, id: content.id, category_ids: [categories(:mobile).id, categories(:technical).id], thread_id: content_threads(:adsl_cancel).id --- > put :update_categories, > id: content.id, > category_ids: [categories(:mobile).id, categories(:technical).id], > thread_id: content_threads(:adsl_cancel).id 20c23,26 < put :update_categories, id: content.id, category_ids: [], thread_id: content_threads(:adsl_cancel).id --- > put :update_categories, > id: content.id, > category_ids: [], > thread_id: content_threads(:adsl_cancel).id 27,28c33,39 < put :update_categories, id: content.id, category_ids: [categories(:mobile).id, categories(:technical).id], thread_id: content_threads(:adsl_cancel).id < }.to change { content.reload.categories.to_a.sort }.from(array_including([categories(:internet), categories(:sales)])).to(array_including([categories(:technical), categories(:mobile)])) --- > put :update_categories, > id: content.id, > category_ids: [categories(:mobile).id, categories(:technical).id], > thread_id: content_threads(:adsl_cancel).id > }.to change { content.reload.categories.to_a.sort } > .from(array_including([categories(:internet), categories(:sales)])) > .to(array_including([categories(:technical), categories(:mobile)])) 33,34c44,50 < put :update_categories, id: contents(:new_smartphone).id, category_ids: [categories(:mobile).id, categories(:technical).id], thread_id: content_threads(:new_smartphone).id < }.to change { contents(:new_smartphone).reload.categories.to_a.sort }.from([]).to([categories(:technical), categories(:mobile)]) --- > put :update_categories, > id: contents(:new_smartphone).id, > category_ids: [categories(:mobile).id, categories(:technical).id], > thread_id: content_threads(:new_smartphone).id > }.to change { contents(:new_smartphone).reload.categories.to_a.sort } > .from([]) > .to([categories(:technical), categories(:mobile)])
Solutions by @FICSQF:
Unlock 5 remaining solutions by signing in and submitting your own entry