A platform for community discussion. Free, open, simple.
Refactor tests to complete assertions within a single `it` block.
Guo Xiang Tan2b783997fa5d
diff --git a/spec/services/username_changer_spec.rb b/spec/services/username_changer_spec.rbindex f981faa91e7..87e5da2b0c9 100644--- a/spec/services/username_changer_spec.rb+++ b/spec/services/username_changer_spec.rb@@ -11,21 +11,13 @@ describe UsernameChanger docontext 'success' dolet(:new_username) { "#{user.username}1234" }- before do+ it 'should change the username' do@result = UsernameChanger.change(user, new_username)- end- it 'returns true' doexpect(@result).to eq(true)- end- it 'should change the username' douser.reloadexpect(user.username).to eq(new_username)- end-- it 'should change the username_lower' do- user.reloadexpect(user.username_lower).to eq(new_username.downcase)endend@@ -35,21 +27,12 @@ describe UsernameChanger dolet(:username_before_change) { user.username }let(:username_lower_before_change) { user.username_lower }- before do+ it 'should not change the username' do@result = UsernameChanger.change(user, wrong_username)- end-- it 'returns false' doexpect(@result).to eq(false)- end- it 'should not change the username' douser.reloadexpect(user.username).to eq(username_before_change)- end-- it 'should not change the username_lower' do- user.reloadexpect(user.username_lower).to eq(username_lower_before_change)endend@@ -57,18 +40,16 @@ describe UsernameChanger dodescribe 'change the case of my username' dolet!(:myself) { Fabricate(:user, username: 'hansolo') }- it 'should return true' do- expect(UsernameChanger.change(myself, "HanSolo")).to eq(true)- end-it 'should change the username' do- UsernameChanger.change(myself, "HanSolo")+ expect do+ expect(UsernameChanger.change(myself, "HanSolo", myself)).to eq(true)+ end.to change { UserHistory.count }.by(1)+expect(myself.reload.username).to eq('HanSolo')- end- it "logs the action" do- expect { UsernameChanger.change(myself, "HanSolo", myself) }.to change { UserHistory.count }.by(1)- expect { UsernameChanger.change(myself, "HanSolo", myself) }.to change { UserHistory.count }.by(0) # make sure it does not log a dupe+ expect do+ UsernameChanger.change(myself, "HanSolo", myself)+ end.to change { UserHistory.count }.by(0) # make sure it does not log a dupeendend