Real Vim ninjas count every keystroke - do you?

Pick a challenge, fire up Vim, and show us what you got.

Changelog, Rules & FAQ, updates: @vimgolf, RSS.

Your VimGolf key: please sign in

$ gem install vimgolf
$ vimgolf setup
$ vimgolf put 5aa7e13aa19abd00c800000b

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

The best way to learn is to practice. Below, you will find some of the solutions other golfers have entered. To unlock higher ranked solutions, submit your own entry which does as well or better than the solutions you can currently see - climb the ladder!

Check out these helpful resources to improve your Vim skills... Game on.

Unlock 5 remaining solutions by signing in and submitting your own entry
#6 Smylers / @Smylers2 - Score: 75 - 03/13/18 @ 20:49
:set sw=2 et<CR>/,<CR>qanlr<CR>q@an2@@>>3@@>>@@n@@nn@@>>@@n@@/\.\w\+(<CR>i<CR><Esc>nn.3n.nn.ZZ

0 comments


Created by: @GuirecCorbel

6 active golfers, 13 entries

Leaderboard (lowest score wins):
54
#1 - せいほう / @FICSQF

04/11/2020 at 11:38AM

54
#2 - Peppa Pig / @PeppaPi95550250

07/01/2024 at 01:58AM

56
#3 - Malcolm Sharpe / @blueblimpms

08/10/2019 at 03:26PM

74
#4 - Saki Gw / @Sakigw

05/02/2018 at 09:45AM

74
#5 - nickGPT / @nickandbro

08/27/2024 at 05:14AM

75
#6 - Smylers / @Smylers2

03/13/2018 at 08:49PM