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 by @blueblimpms:

Unlock 3 remaining solutions by signing in and submitting your own entry
Created by: @GuirecCorbel

4 active golfers, 10 entries

Solutions by @blueblimpms:
56
#2 - Malcolm Sharpe / @blueblimpms

08/10/2019 at 03:26PM

57
#>2 - Malcolm Sharpe / @blueblimpms

08/10/2019 at 03:19PM

59
#>2 - Malcolm Sharpe / @blueblimpms

08/10/2019 at 03:13PM