1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
5 describe ThrowSymbol, "(constructed with no Symbol)" do
6 before(:each) { @matcher = ThrowSymbol.new }
8 it "should match if any Symbol is thrown" do
9 @matcher.matches?(lambda{ throw :sym }).should be_true
11 it "should not match if no Symbol is thrown" do
12 @matcher.matches?(lambda{ }).should be_false
14 it "should provide a failure message" do
15 @matcher.matches?(lambda{})
16 @matcher.failure_message.should == "expected a Symbol but nothing was thrown"
18 it "should provide a negative failure message" do
19 @matcher.matches?(lambda{ throw :sym})
20 @matcher.negative_failure_message.should == "expected no Symbol, got :sym"
24 describe ThrowSymbol, "(constructed with a Symbol)" do
25 before(:each) { @matcher = ThrowSymbol.new(:sym) }
27 it "should match if correct Symbol is thrown" do
28 @matcher.matches?(lambda{ throw :sym }).should be_true
30 it "should not match if no Symbol is thrown" do
31 @matcher.matches?(lambda{ }).should be_false
33 it "should not match if correct Symbol is thrown" do
34 @matcher.matches?(lambda{ throw :other_sym }).should be_false
35 @matcher.failure_message.should == "expected :sym, got :other_sym"
37 it "should provide a failure message when no Symbol is thrown" do
38 @matcher.matches?(lambda{})
39 @matcher.failure_message.should == "expected :sym but nothing was thrown"
41 it "should provide a failure message when wrong Symbol is thrown" do
42 @matcher.matches?(lambda{ throw :other_sym })
43 @matcher.failure_message.should == "expected :sym, got :other_sym"
45 it "should provide a negative failure message" do
46 @matcher.matches?(lambda{ throw :sym })
47 @matcher.negative_failure_message.should == "expected :sym not to be thrown"
49 it "should only match NameErrors raised by uncaught throws" do
50 @matcher.matches?(lambda{ sym }).should be_false