Skip to content

Commit

Permalink
Move enforced styles to top in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed May 30, 2022
1 parent 54ee974 commit c8246f6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
46 changes: 23 additions & 23 deletions docs/modules/ROOT/pages/cops_rspec.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1528,17 +1528,6 @@ This cop can be configured using the `EnforcedStyle` option.

=== Examples

==== `EnforcedStyle: block`

[source,ruby]
----
# bad
expect { run }.to change(Foo, :bar)
# good
expect { run }.to change { Foo.bar }
----

==== `EnforcedStyle: method_call` (default)

[source,ruby]
Expand All @@ -1555,6 +1544,17 @@ expect { run }.to change { Foo.bar(:count) }
expect { run }.to change { user.reload.name }
----

==== `EnforcedStyle: block`

[source,ruby]
----
# bad
expect { run }.to change(Foo, :bar)
# good
expect { run }.to change { Foo.bar }
----

=== Configurable attributes

|===
Expand Down Expand Up @@ -3810,34 +3810,34 @@ This cop can be configured using the `EnforcedStyle` option

=== Examples

==== `EnforcedStyle: block`
==== `EnforcedStyle: and_return` (default)

[source,ruby]
----
# bad
allow(Foo).to receive(:bar).and_return("baz")
expect(Foo).to receive(:bar).and_return("baz")
# good
allow(Foo).to receive(:bar) { "baz" }
expect(Foo).to receive(:bar) { "baz" }
# good
allow(Foo).to receive(:bar).and_return("baz")
expect(Foo).to receive(:bar).and_return("baz")
# also good as the returned value is dynamic
allow(Foo).to receive(:bar).and_return(bar.baz)
allow(Foo).to receive(:bar) { bar.baz }
----

==== `EnforcedStyle: and_return` (default)
==== `EnforcedStyle: block`

[source,ruby]
----
# bad
allow(Foo).to receive(:bar) { "baz" }
expect(Foo).to receive(:bar) { "baz" }
# good
allow(Foo).to receive(:bar).and_return("baz")
expect(Foo).to receive(:bar).and_return("baz")
# good
allow(Foo).to receive(:bar) { "baz" }
expect(Foo).to receive(:bar) { "baz" }
# also good as the returned value is dynamic
allow(Foo).to receive(:bar) { bar.baz }
allow(Foo).to receive(:bar).and_return(bar.baz)
----

=== Configurable attributes
Expand Down
14 changes: 7 additions & 7 deletions lib/rubocop/cop/rspec/expect_change.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ module RSpec
#
# This cop can be configured using the `EnforcedStyle` option.
#
# @example `EnforcedStyle: block`
# # bad
# expect { run }.to change(Foo, :bar)
#
# # good
# expect { run }.to change { Foo.bar }
#
# @example `EnforcedStyle: method_call` (default)
# # bad
# expect { run }.to change { Foo.bar }
Expand All @@ -29,6 +22,13 @@ module RSpec
# expect { run }.to change { Foo.bar(:count) }
# expect { run }.to change { user.reload.name }
#
# @example `EnforcedStyle: block`
# # bad
# expect { run }.to change(Foo, :bar)
#
# # good
# expect { run }.to change { Foo.bar }
#
class ExpectChange < Base
extend AutoCorrector
include ConfigurableEnforcedStyle
Expand Down
22 changes: 11 additions & 11 deletions lib/rubocop/cop/rspec/return_from_stub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@ module RSpec
#
# This cop can be configured using the `EnforcedStyle` option
#
# @example `EnforcedStyle: block`
# # bad
# allow(Foo).to receive(:bar).and_return("baz")
# expect(Foo).to receive(:bar).and_return("baz")
#
# # good
# allow(Foo).to receive(:bar) { "baz" }
# expect(Foo).to receive(:bar) { "baz" }
# # also good as the returned value is dynamic
# allow(Foo).to receive(:bar).and_return(bar.baz)
#
# @example `EnforcedStyle: and_return` (default)
# # bad
# allow(Foo).to receive(:bar) { "baz" }
Expand All @@ -33,6 +22,17 @@ module RSpec
# # also good as the returned value is dynamic
# allow(Foo).to receive(:bar) { bar.baz }
#
# @example `EnforcedStyle: block`
# # bad
# allow(Foo).to receive(:bar).and_return("baz")
# expect(Foo).to receive(:bar).and_return("baz")
#
# # good
# allow(Foo).to receive(:bar) { "baz" }
# expect(Foo).to receive(:bar) { "baz" }
# # also good as the returned value is dynamic
# allow(Foo).to receive(:bar).and_return(bar.baz)
#
class ReturnFromStub < Base
extend AutoCorrector
include ConfigurableEnforcedStyle
Expand Down

0 comments on commit c8246f6

Please sign in to comment.