Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some rubocop warnings in the specs #129

Merged
merged 9 commits into from
Mar 11, 2016

Conversation

vheuken
Copy link
Collaborator

@vheuken vheuken commented Mar 11, 2016

Started with 357 Rubocop offenses. Now we're down to 162.

I want to make sure this passes Hound-CI. Still need to do yotuube_api_spec, vkontakte_spec, and daily_motion_spec. If it passes Hound-CI, I'll merge it in and do the rest in another PR.

vheuken pushed a commit that referenced this pull request Mar 11, 2016
Fixed some rubocop warnings in the specs
@vheuken vheuken merged commit 552ed03 into thibaudgg:master Mar 11, 2016
expect(provider.embed_code(iframe_attributes: { foo: 'bar' })).to eq '<iframe src="//foo.com" frameborder="0" foo="bar"></iframe>'
it 'supports url_attributes option' do
embed_str = '<iframe src="//foo.com" frameborder="0" foo="bar"></iframe>'
expected = expect(provider.embed_code(iframe_attributes: { foo: 'bar' }))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not write it like that with a variable, but rather:

expect(provider.embed_code(iframe_attributes: { foo: 'bar' }))
  .to eq '<iframe src="//foo.com" frameborder="0" foo="bar"></iframe>'

same for all rewritten specs like that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair. I wasn't totally sold on it, either. Just seemed like the best way to do it at the time. I'll go back and clean those up this weekend. Should be pretty simple since I named them all expected

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit of an issue: doing what you suggested gives:

C: Place the . on the previous line, together with the method call receiver.
        .to raise_error(NotImplementedError, error_msg)
        ^

Formatting it like so:

      expect { VideoInfo::Provider.new(url) }.to
        raise_error(NotImplementedError, error_msg)

Gives C: Inconsistent indentation detected.

The only way to format it in a way Rubocop likes is:

      expect { VideoInfo::Provider.new(url) }.to
      raise_error(NotImplementedError, error_msg)

....which I have a problem with since it is unclear that it is a continuation of the previous line.

Also, with the way I did it, we end up saving code in some places, like here:

    it 'should apply width and height attributes properly' do
      dimensions = { width: 800, height: 600 }
      expected = expect(subject.embed_code(iframe_attributes: dimensions))
      expected.to match(/width="800"/)
      expected.to match(/height="600"/)
    end

Whereas before, there were two expect function calls on the exact same data.

Obviously, we could go modify the rubocop config, but personally I'd rather not mess with that too much since I think what we're using (which is the Hound-CI default) is a solid standard.

Unless you have any other ideas, I'd propose on keeping it the way it is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have time, feel free to experiment with it and see if you can come up with a nicer solution. For now, though, I think I'm going to spend my time on the other tasks on the docket.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my work we use the following config:

Style/DotPosition:
  Description: Checks the position of the dot in multi-line method calls.
  StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
  Enabled: true
  EnforcedStyle: leading
  SupportedStyles:
  - leading
  - trailing

I think it worths updating our config as well.

Regarding the 2nd point, I prefer:

    it 'should apply width and height attributes properly' do
      dimensions = { width: 800, height: 600 }
      embed_code = subject.embed_code(iframe_attributes: dimensions)
      expect(embed_code).to match(/width="800"/)
      expect(embed_code).to match(/height="600"/)
    end

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I'll modify the config accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants