rspec/rspec-expectations — Issue #104: chain in a matcher keeps instance variables on other asserts
Author: lunks
Created: 2012-01-06 18:43:20+00:00
State: open

I've got a matcher for enumerations using enumerate it like this:

```ruby
module ActiveRecordMatchers

RSpec::Matchers.define :have_enumeration_for do |enum|

chain :with do |custom_class|
@custom_class = custom_class
end

match do |subject|
if @custom_class
@enum_class = @custom_class
else
@enum_class = enum.to_s.camelize.constantize
end
subject.class.enumerations[enum.to_sym].should == @enum_class
end

failure_message_for_should do |subject|
"#{subject.class} should have an enumeration on #{enum}. Enumerations: #{subject.class.enumerations.inspect}"
end

description do |enum|
"have an enum for #{enum}"
end
end
end
```

On 2.8.0.rc1 and before, this work like intended:

```ruby
it { should have_enumeration_for(:capacity).with(ChipCapacity) } # @enum_class is ChipCapacity
it { should have_enumeration_for(:state) } #@enum_class is State
```

After 2.8.0.rc1, the behavior has changed:

```ruby
it { should have_enumeration_for(:capacity).with(ChipCapacity) } # @enum_class is ChipCapacity
it { should have_enumeration_for(:state) } #@enum_class is ChipCapacity
```

Is this a bug? Is this intended?