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

Fix Style/BlockDelimiters #1224

Merged
merged 7 commits into from
Jan 17, 2018
Merged

Fix Style/BlockDelimiters #1224

merged 7 commits into from
Jan 17, 2018

Conversation

mxygem
Copy link
Member

@mxygem mxygem commented Oct 28, 2017

Details

  • Rubocop prefers the use of {...} for single line blocks and do..end for multi-line blocks.

Motivation and Context

Working to help solve issue 1021!

How Has This Been Tested?

bundle exec rake 👍

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Rubocop style fixes

Copy link
Contributor

@luke-hill luke-hill left a comment

Choose a reason for hiding this comment

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

Couple of syntatical observations

@@ -25,15 +25,16 @@ def initialize(config)
config.on_event :test_run_finished, &method(:on_test_run_finished)
@reportdir = ensure_dir(config.out_stream, 'junit')
@config = config
@features_data = Hash.new { |h,k| h[k] = {
@features_data = Hash.new do |h,k| h[k] = {
Copy link
Contributor

Choose a reason for hiding this comment

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

whilst not in this cop, probably worth doing |h, k| just whilst you're here. Also line 35 can go to new syntax if you're inclined

Copy link
Member Author

@mxygem mxygem Jan 8, 2018

Choose a reason for hiding this comment

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

All set on this. :)

@@ -49,9 +49,9 @@
end

it 'does not raise an error' do
expect {
expect do
Copy link
Contributor

Choose a reason for hiding this comment

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

possible 1 liner?

Copy link
Member Author

Choose a reason for hiding this comment

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

Got it!

@@ -550,8 +550,8 @@ module Formatter
FEATURE

define_steps do
Given(/^there are bananas$/) { data = 'YWJj'
embed data, 'mime-type;base64' }
Given(/^there are bananas$/) do data = 'YWJj'
Copy link
Contributor

Choose a reason for hiding this comment

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

Like below, Given end typically are your wrappers, so I'd have them distinct. Move end:554 to 555?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a weird one- don't know how that happened! Nice catch!

Copy link
Member Author

Choose a reason for hiding this comment

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

For some weird reason the json_spec file seems very fragile and without that extra line under my change, some of the tests following that one fail.

@@ -36,8 +36,8 @@ module Rake
context 'when running without bundler' do
let(:bundler) { false }

subject { Task::ForkedCucumberRunner.new(
libs, binary, cucumber_opts, bundler, feature_files) }
subject do Task::ForkedCucumberRunner.new(
Copy link
Contributor

Choose a reason for hiding this comment

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

do and end are the starting arguments and distinct like above. I'll leave the rest out.

Copy link
Member Author

Choose a reason for hiding this comment

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

All set on this one

@mxygem
Copy link
Member Author

mxygem commented Jan 7, 2018

Will work to fix conflicts today if I can! Also, @luke-hill Thanks for the feedback, I'll also work on your changes when I get to this PR. :)

Given(/^there are bananas$/) { data = 'YWJj'
embed data, 'mime-type;base64' }
Given(/^there are bananas$/) { embed('YWJj', 'mime-type;base64') }

Copy link
Contributor

Choose a reason for hiding this comment

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

Rogue line

Copy link
Member Author

Choose a reason for hiding this comment

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

@luke-hill This line has to be here otherwise random tests after this one fail. Seems to be a really fragile file. :( We can work on fixing that in another issue.

subject { Task::ForkedCucumberRunner.new(
libs, binary, cucumber_opts, bundler, feature_files) }
subject do Task::ForkedCucumberRunner.new(
libs, binary, cucumber_opts, bundler, feature_files) end
Copy link
Contributor

Choose a reason for hiding this comment

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

think the end here should be newlined?

Copy link
Member Author

Choose a reason for hiding this comment

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

I can try new lining it, but given my comment on json_spec, it may break things. Technically, it should just be a one-line request, but I think it's on two due to line-length. :grumble:

Copy link
Member Author

Choose a reason for hiding this comment

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

Nevermind, things are fine after changing.

@formatter.feature_name('Feature', '')
}).not_to raise_error
end).not_to raise_error
Copy link
Contributor

Choose a reason for hiding this comment

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

One way to get this to read a little easier is to try keeping the "stabby lambda" and having it on 1 line:

expect(->{ @formatter.feature_name('Feature', '') }).not_to raise_error

Copy link
Member Author

Choose a reason for hiding this comment

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

All set here!

Interceptor::Pipe.wrap(:nonsense)
}.to raise_error(ArgumentError)
end.to raise_error(ArgumentError)
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps this also reads easy on 1 line?

expect { Interceptor::Pipe.wrap(:nonsense) }.to raise_error(ArgumentError)

Copy link
Member Author

Choose a reason for hiding this comment

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

All set here!

Interceptor::Pipe.unwrap!(:nonsense)
}.to raise_error(ArgumentError)
end.to raise_error(ArgumentError)
Copy link
Contributor

Choose a reason for hiding this comment

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

And, this too. You see what I'm trying to achieve, I hope.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I totally do. The project looks like it may need a larger rspec update to bring it up to speed stylistically. Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

All set here!

run_defined_feature
}).to raise_error(Junit::UnNamedFeatureError)
end).to raise_error(Junit::UnNamedFeatureError)
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, this would also read easier to me as a single-line

expect(->{ run_defined_feature }).to raise_error(Junit::UnNamedFeatureError)

@olleolleolle
Copy link
Contributor

Oh, blast. So many instances of the same thing.

Where I'm trying to go is: The two forms of anonymous methods in Ruby can stylistically be used in two distinct forms: as inline, or as multiline block.

  • stabby lambda: use it inline ->(arg){}
  • regular lambda: use it with a do block: lambda do |arg| multi-line content here... end

@luke-hill
Copy link
Contributor

Yeh thats a good point ☝️ Wasn't sure how you've been tackling these whether manually or through some rubocop -a calls. But I think the above is invoked through -a

@mxygem
Copy link
Member Author

mxygem commented Jan 16, 2018

Thanks, you two! I'll get these handled. :)

@@ -88,17 +88,17 @@ module MultilineArgument
end

it 'should pass silently if a mapped column does not exist in non-strict mode' do
expect {
expect do
Copy link
Member Author

Choose a reason for hiding this comment

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

Leaving these as they're multi-line

@mxygem
Copy link
Member Author

mxygem commented Jan 17, 2018

@olleolleolle Are we good to go here? :D

@olleolleolle
Copy link
Contributor

I'm going to merge this, now! 👍

@olleolleolle olleolleolle merged commit 8a109fc into master Jan 17, 2018
@olleolleolle olleolleolle deleted the 1021-BlockDelimiters branch January 17, 2018 17:08
@mxygem
Copy link
Member Author

mxygem commented Jan 17, 2018

Woot! Thanks!

@lock
Copy link

lock bot commented Jan 17, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants