rspec/rspec-expectations — pull request #644 by tomstuart (2014-09-05 11:45:12+00:00)
Title: Add shorthand `chain` syntax for custom matchers

The `chain` block in fluent matchers almost always just assigns its argument to an instance variable:

```ruby
RSpec::Matchers.define :be_bigger_than do |first|
match do |actual|
(actual > first) && (actual < @second)
end

chain :and_smaller_than do |second|
@second = second
end
end
```

Requiring a block is kind of overkill in this common case, and I get tired of reimplementing the exact same thing in every fluent matcher I define.

This pull request allows you to instead write:

```ruby
RSpec::Matchers.define :be_bigger_than do |first|
match do |actual|
(actual > first) && (actual < second)
end

chain :and_smaller_than, :second
end
```

Namely:

* you can just say `:second` instead of `do |second| @second = second end`; and
* as a bonus, since the DSL now knows a meaningful name for that remembered value, you can refer to it (e.g. in `match`) by saying `second` instead of `@second`.

I think this is an improvement. WDYT?