Why is this rspec 'expect to raise_error' failing, when the message returned is 'ActiveRecord::RecordInvalid'
<p>The following rspec test is failing, and yet the message provided alongside the failing tests appears to be the expected result.</p>

<pre><code>describe '#validate_maximum_pending_actions_not_been_reached' do
  let(:action) { build :action, status: 'pending' }
  before :each do
    10.times do
      create :action, status: 'pending'
    end
  end
  it 'does not save the 11th action' do
    expect(action.save).to raise_error #(ActiveRecord::RecordInvalid,'Validation failed: maximum number of pending actions already reached')
  end
end


Failure/Error: let(:action) { build :action, status: 'pending' }
  ActiveRecord::RecordInvalid:
    Validation failed: maximum number of pending actions already reached
</code></pre>

<p>I have tried being less specific by omitting the error message, and simply expecting that the test will <code>raise_error</code>. The test still fails, but gives the description above which suggest that an error is indeed being raised.</p>

<p>What am I doing wrong?</p>

<p>The method being tested is as follows: </p>

<pre><code>validate :validate_maximum_pending_actions_not_been_reached
def validate_maximum_pending_actions_not_been_reached
  errors[:base] &lt;&lt; "maximum number of pending actions already reached" unless Action.where(status: 'pending').size &lt;= 10
end
</code></pre>