From cad0ca2bffb4305760dbc6702386957f6d85cafd Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Wed, 21 Mar 2012 18:28:55 +0800 Subject: [PATCH] Rspec. --- rspec.md | 44 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/rspec.md b/rspec.md index 17e0285b9..d99cb1ce0 100644 --- a/rspec.md +++ b/rspec.md @@ -57,51 +57,33 @@ title: RSpec ### Expectations + # Can be .should or .should_not + + # Numeric target.should be < 6 target.should == 5 + target.should equal value target.should be_between(1, 10) - target.should_not == 'Samantha' - - target.should be - target.should_not be + target.should be_close value, tolerance + target.should be value target.should satisfy {|arg| ...} - target.should_not satisfy {|arg| ...} - - target.should equal - target.should not_equal - - target.should be_close , - target.should_not be_close , - target.should predicate [optional args] - target.should be_predicate [optional args] - target.should_not predicate [optional args] - target.should_not be_predicate [optional args] - - target.should match - target.should_not match + target.should match regexp target.should be_an_instance_of - target.should_not be_an_instance_of - target.should be_a_kind_of - target.should_not be_a_kind_of target.should respond_to - target.should_not respond_to - lambda {a_call}.should raise_error - lambda {a_call}.should raise_error( [, message]) - lambda {a_call}.should_not raise_error - lambda {a_call}.should_not raise_error( [, message]) - lambda {a_call}.should change(instance, method).from(number).to(number) + # Control flow + proc.should raise_error + proc.should raise_error( [, message]) proc.should throw - proc.should_not throw + # Enumerables/arrays target.should include - target.should_not include target.should have().things target.should have_at_least().things @@ -109,6 +91,10 @@ title: RSpec target.should have().errors_on(:field) + # Change + proc.should change(instance, method).from(number).to(number) + + # proc.should <=> expect(&proc).to expect { thing.approve! }.to change(thing, :status). from(Status::AWAITING_APPROVAL). to(Status::APPROVED)