spec/acceptance_spec.rb in surrogate-0.1.0 vs spec/acceptance_spec.rb in surrogate-0.2.0

- old
+ new

@@ -34,11 +34,11 @@ end end # don't affect the real user class - user_class = Mock::User.reprise + user_class = Mock::User.clone # ===== set a default ===== user_class.will_find :user1 user_class.find(1).should == :user1 @@ -51,11 +51,11 @@ user_class.find(33).should == :user3 # third override user_class.find(44).should be_a_kind_of Mock::User # back to default block # might also be nice to provide a way to raise an error # tracking invocations - user_class = Mock::User.reprise + user_class = Mock::User.clone user_class.should_not have_been_told_to :find user_class.find 12 user_class.find 12 user_class.find 23 user_class.should have_been_told_to(:find).times(3) @@ -99,9 +99,16 @@ user.phone_numbers.should be_empty user.add_phone_number '123', '456-7890' user.should have_been_told_to(:add_phone_number).with('123', '456-7890') # user.phone_numbers.should == [['123', '456-7890']] # <-- should we use a hook, or default block to make this happen? + + # ===== raise errors ===== + + # pass the error as the return value, it will be raised when method is invoked + error = StandardError.new("some message") + user.will_add_phone_number error + expect { user.add_phone_number }.to raise_error StandardError, "some message" # ===== Substitutability ===== # real user is not a suitable substitute if missing methods that mock user has user_class.should_not substitute_for Class.new