Workit

Workit/ActionArgs

Enabled by default Safe Supports autocorrection Version Added Version Changed

Disabled

Yes

No

-

-

Check for controller action must be using action_args.

Examples

# bad
class FooController
  def index
    # ...
  end
end

# good
class FooController
  def index(foo:)
    # ...
  end

  def not_action
    # ...
  end
end

Configurable attributes

Name Default value Configurable values

Include

controllers/**/*

Array

ControllerMethods

index, show, create, update, cancel, destroy

Array

Workit/ComitteeAssertSchemaConfirm

Enabled by default Safe Supports autocorrection Version Added Version Changed

Disabled

Yes

Yes

-

-

Check for not pass expected response status code to check it against the corresponding schema explicitly.

This cop is deprecated.

Workit/CommitteeExpectedResponseStatusCode

Enabled by default Safe Supports autocorrection Version Added Version Changed

Disabled

Yes

Yes

-

-

Check if the status code is specified as an argument to the method of the Committee where the expected response status code is required.

Examples

# bad
it 'something' do
  subject
  expect(response).to have_http_status 400
  assert_schema_conform
end

# good
it 'something' do
  subject
  assert_schema_conform(400)
end

Workit/NoopRescue

Enabled by default Safe Supports autocorrection Version Added Version Changed

Disabled

Yes

No

-

-

Check for suppress or ignore checked exception.

Examples

# bad
foo rescue nil

# bad
def foo
  do_something
rescue StandardError => e
  # no op
end

# good
foo rescue do_something

# good
def foo
  do_something
rescue StandardError => e
  do_something
end

Workit/RSpecCapybaraMatchStyle

Enabled by default Safe Supports autocorrection Version Added Version Changed

Disabled

Yes

Yes

-

-

Checks for usage of deprecated style methods.

Examples

when using assert_style

# bad
page.find(:css, '#first').assert_style(display: 'block')

# good
page.find(:css, '#first').assert_matches_style(display: 'block')

when using has_style?

# bad
expect(page.find(:css, 'first')
  .has_style?(display: 'block')).to be true

# good
expect(page.find(:css, 'first')
  .matches_style?(display: 'block')).to be true

when using have_style

# bad
expect(page).to have_style(display: 'block')

# good
expect(page).to match_style(display: 'block')

Workit/RSpecCapybaraPredicateMatcher

Enabled by default Safe Supports autocorrection Version Added Version Changed

Disabled

Yes

Yes

-

-

Prefer using predicate matcher over using predicate method directly.

Capybara defines magic matchers for predicate methods. This cop recommends to use the predicate matcher instead of using predicate method directly.

Examples

Strict: true, EnforcedStyle: inflected (default)

# bad
expect(foo.matches_css?(bar: 'baz')).to be_truthy
expect(foo.matches_selector?(bar: 'baz')).to be_truthy
expect(foo.matches_style?(bar: 'baz')).to be_truthy
expect(foo.matches_xpath?(bar: 'baz')).to be_truthy

# good
expect(foo).to match_css(bar: 'baz')
expect(foo).to match_selector(bar: 'baz')
expect(foo).to match_style(bar: 'baz')
expect(foo).to match_xpath(bar: 'baz')

# also good - It checks "true" strictly.
expect(foo.matches_style?(bar: 'baz')).to be(true)

Strict: false, EnforcedStyle: inflected

# bad
expect(foo.matches_style?(bar: 'baz')).to be_truthy
expect(foo.matches_style?(bar: 'baz')).to be(true)

# good
expect(foo).to match_style(bar: 'baz')

Strict: true, EnforcedStyle: explicit

# bad
expect(foo).to match_style(bar: 'baz')

# good - the above code is rewritten to it by this cop
expect(foo.matches_style?(bar: 'baz')).to be(true)

Strict: false, EnforcedStyle: explicit

# bad
expect(foo).to match_style(bar: 'baz')

# good - the above code is rewritten to it by this cop
expect(foo.matches_style?(bar: 'baz')).to be_truthy

Configurable attributes

Name Default value Configurable values

Strict

true

Boolean

EnforcedStyle

inflected

inflected, explicit

AllowedExplicitMatchers

[]

Array

Workit/RSpecMinitestAssertions

Enabled by default Safe Supports autocorrection Version Added Version Changed

Disabled

Yes

Yes

-

-

Check if using Minitest matchers.

Examples

# bad
assert_equal(a, b)
assert_equal a, b, "must be equal"
refute_equal(a, b)

# good
expect(a).to eq(b)
expect(a).to(eq(b), "must be equal")
expect(a).not_to eq(b)

Workit/RSpecRedundantHttpStatus

Enabled by default Safe Supports autocorrection Version Added Version Changed

Disabled

Yes

Yes

-

-

Check for validation of redundant response HTTP status codes.

Examples

# bad
it 'something' do
  subject
  expect(response).to have_http_status 400
  assert_schema_conform(400)
end

# good
it 'something' do
  subject
  assert_schema_conform(400)
end

Workit/RestrictOnSend

Enabled by default Safe Supports autocorrection Version Added Version Changed

Disabled

Yes

No

-

-

Check for RESTRICT_ON_SEND is defined if on_send or after_send are defined.

Examples

# bad
class FooCop
  def on_send(node)
    # ...
  end
end

# good
class FooCop
  RESTRICT_ON_SEND = %i[bad_method].freeze
  def on_send(node)
    # ...
  end
end