[rspec-devel] [ rspec-Patches-14255 ] Fixed examples in mock_spec.rb and shared_behaviour_spec.rb

noreply at rubyforge.org noreply at rubyforge.org
Tue Oct 2 02:46:18 EDT 2007


Patches item #14255, was opened at 2007-09-26 17:11
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=14255&group_id=797

Category: mock module
Group: None
>Status: Closed
>Resolution: Accepted
Priority: 3
Submitted By: Antti Tarvainen (tarvaina)
Assigned to: Nobody (None)
Summary: Fixed examples in mock_spec.rb and shared_behaviour_spec.rb

Initial Comment:
A recurring pattern in rspec internal examples is this:

it "should fail with a meaningful error message" do
  begin
    @object.failing_operation
  rescue PanicExceptionError => e
    e.message.should == "Something went wrong!"
  end
end


The problem with this pattern is that it gives a false positive when @object.failing_operation doesn't raise a PanicExceptionError.


This patch fixes these examples by using the raise_error matcher. The above example thus becomes:

it "should fail with a meaningful error message" do
  lambda {
    @object.failing_operation
  }.should raise_error(PanicExceptionError, "Something went wrong!")
end


These changes revealed one false positive in mock_spec.rb. I marked the example pending and added another example that demonstrates the current behavior.


----------------------------------------------------------------------

>Comment By: David Chelimsky (dchelimsky)
Date: 2007-10-02 06:46

Message:
Applied to r2682.

I think the pending example should pass and the other one should error out when calling the non-expected method. Looking into that now.

----------------------------------------------------------------------

Comment By: Antti Tarvainen (tarvaina)
Date: 2007-09-26 17:11

Message:
Here's the actual patch file.

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=14255&group_id=797


More information about the rspec-devel mailing list