Skip to content

Commit

Permalink
Add Implicit Block Expectation guideline
Browse files Browse the repository at this point in the history
Implicit syntax is discouraged to use by RSpec Core team and the
majority of voters.

There were no good arguments for using the syntax except for brevity and
avoiding repetition, but there are better options to achieve the same
goal, e.g. by extracting the lengthy block to methods (instead of
putting it inside the lambda).

Fixes #76

https://www.reddit.com/r/ruby/comments/cejl3q/call_for_discussion_rspec_implicit_block/
https://blog.rubystyle.guide/rspec/2019/07/17/rspec-implicit-block-syntax.html
#76
  • Loading branch information
pirj committed Jul 23, 2019
1 parent 4e42fb6 commit 484de61
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.adoc
Expand Up @@ -1007,6 +1007,23 @@ describe SomeClass do
end
----

[#implicit-block-expectations]
=== Implicit Block Expectations

Avoid using implicit block expectations.

[source,ruby]
----
# bad
subject { -> { do_something } }
it { is_expected.to change(something).to(new_value) }
# good
it 'changes something to a new value' do
expect { do_something }.to change(something).to(new_value)
end
----

== Naming

=== Context Descriptions
Expand Down

0 comments on commit 484de61

Please sign in to comment.