From b4da084e7249eefb614aea2a7db9d4eeae35778f Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Thu, 26 Mar 2015 16:41:23 +0800 Subject: [PATCH] Add fouc helpers --- _includes/head.html | 2 +- _includes/meta.html | 3 ++ rails-models.md | 7 +++-- rspec.md | 75 +++++++++++++++++++++++---------------------- 4 files changed, 48 insertions(+), 39 deletions(-) diff --git a/_includes/head.html b/_includes/head.html index 2fa66a6e0..5d69a3402 100644 --- a/_includes/head.html +++ b/_includes/head.html @@ -1,5 +1,5 @@ - + {% include meta.html %} diff --git a/_includes/meta.html b/_includes/meta.html index b63d01385..27143d059 100644 --- a/_includes/meta.html +++ b/_includes/meta.html @@ -89,3 +89,6 @@ + +{%comment%}{%endcomment%} + diff --git a/rails-models.md b/rails-models.md index 870311ecd..793f26980 100644 --- a/rails-models.md +++ b/rails-models.md @@ -139,8 +139,8 @@ Validation validates :name, length: { minimum: 2 } validates :bio, length: { maximum: 500 } - validates :password, length: { in => 6..20 } - validates :number, length: { is => 6 } + validates :password, length: { in: => 6..20 } + validates :number, length: { is: => 6 } validates :gender, inclusion: %w(male female) validates :gender, inclusion: { in: %w(male female) } @@ -148,6 +148,9 @@ Validation validates :points, numericality: true validates :played, numericality: { only_integer: true } + # ... greater_than, greater_than_or_equal_to, + # ... less_than, less_than_or_equal_to + # ... odd, even, equal_to # Validate the associated records to ensure they're valid as well has_many :books diff --git a/rspec.md b/rspec.md index 6534b3778..8b126c8e6 100644 --- a/rspec.md +++ b/rspec.md @@ -51,60 +51,63 @@ layout: default it "should do this" do pending "some other thing" - subject.name = 'x' - subject.name.should == 'x' + expect(subject.name).to eq 'x' end end end ### Expectations - # Can be: - # target.should - # target.should_not - # expect(target).to +```rb +target.should eq 1 +target.should_not eq 1 +expect(target).to eq 1 +expect(target).not_to eq 1 +``` - # Numeric - be < 6 - == 5 - equal value - be_between(1, 10) - be_close value, tolerance +```rb +# Numeric +be < 6 +== 5 +equal value +be_between(1, 10) +be_close value, tolerance - be value - satisfy {|arg| ...} - predicate [optional args] - match regexp +be value +satisfy {|arg| ...} +predicate [optional args] +match regexp - be_an_instance_of - be_a_kind_of +be_an_instance_of +be_a_kind_of - respond_to +respond_to - # Control flow - raise_error - raise_error( [, message]) +# Control flow +raise_error +raise_error( [, message]) - throw +throw - # Enumerables/arrays - include +# Enumerables/arrays +include - have().things - have_at_least().things - have_at_most().things +have().things +have_at_least().things +have_at_most().things - have().errors_on(:field) +have().errors_on(:field) - # Change - change(instance, method).from(number).to(number) +# Change +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) +# proc.should <=> expect(&proc).to +expect { thing.approve! }.to change(thing, :status). + from(Status::AWAITING_APPROVAL). + to(Status::APPROVED) - expect { thing.destroy }.to change(Thing, :count).by(-1) +expect { thing.destroy }.to change(Thing, :count).by(-1) +``` ### Mocking - basic