Add fouc helpers

This commit is contained in:
Rico Sta. Cruz 2015-03-26 16:41:23 +08:00
parent 906eab0a59
commit b4da084e72
4 changed files with 48 additions and 39 deletions

View File

@ -1,5 +1,5 @@
<!doctype html> <!doctype html>
<html lang='en' class='{{ page.html_class }}'> <html lang='en' class='no-js {{ page.html_class }}'>
<head> <head>
{% include meta.html %} {% include meta.html %}
<link href="http://ricostacruz.com/til/assets/style.css?t={{ site.time | date: "%Y%m%d%H%M%S" }}" rel="stylesheet" /> <link href="http://ricostacruz.com/til/assets/style.css?t={{ site.time | date: "%Y%m%d%H%M%S" }}" rel="stylesheet" />

View File

@ -89,3 +89,6 @@
<meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'> <meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1.0' name='viewport'> <meta content='width=device-width, initial-scale=1.0' name='viewport'>
<link href='{{ base }}/assets/favicon.png' rel='shortcut icon'> <link href='{{ base }}/assets/favicon.png' rel='shortcut icon'>
{%comment%}<!-- fouc -->{%endcomment%}
<script>(function(H){H.className=H.className.replace(/\bno-js\b/,'js')})(document.documentElement)</script>

View File

@ -139,8 +139,8 @@ Validation
validates :name, length: { minimum: 2 } validates :name, length: { minimum: 2 }
validates :bio, length: { maximum: 500 } validates :bio, length: { maximum: 500 }
validates :password, length: { in => 6..20 } validates :password, length: { in: => 6..20 }
validates :number, length: { is => 6 } validates :number, length: { is: => 6 }
validates :gender, inclusion: %w(male female) validates :gender, inclusion: %w(male female)
validates :gender, inclusion: { in: %w(male female) } validates :gender, inclusion: { in: %w(male female) }
@ -148,6 +148,9 @@ Validation
validates :points, numericality: true validates :points, numericality: true
validates :played, numericality: { only_integer: 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 # Validate the associated records to ensure they're valid as well
has_many :books has_many :books

View File

@ -51,60 +51,63 @@ layout: default
it "should do this" do it "should do this" do
pending "some other thing" pending "some other thing"
subject.name = 'x' expect(subject.name).to eq 'x'
subject.name.should == 'x'
end end
end end
end end
### Expectations ### Expectations
# Can be: ```rb
# target.should target.should eq 1
# target.should_not target.should_not eq 1
# expect(target).to expect(target).to eq 1
expect(target).not_to eq 1
```
# Numeric ```rb
be < 6 # Numeric
== 5 be < 6
equal value == 5
be_between(1, 10) equal value
be_close value, tolerance be_between(1, 10)
be_close value, tolerance
be value be value
satisfy {|arg| ...} satisfy {|arg| ...}
predicate [optional args] predicate [optional args]
match regexp match regexp
be_an_instance_of <class> be_an_instance_of <class>
be_a_kind_of <class> be_a_kind_of <class>
respond_to <symbol> respond_to <symbol>
# Control flow # Control flow
raise_error raise_error
raise_error(<exception> [, message]) raise_error(<exception> [, message])
throw <symbol> throw <symbol>
# Enumerables/arrays # Enumerables/arrays
include <object> include <object>
have(<number>).things have(<number>).things
have_at_least(<number>).things have_at_least(<number>).things
have_at_most(<number>).things have_at_most(<number>).things
have(<number>).errors_on(:field) have(<number>).errors_on(:field)
# Change # Change
change(instance, method).from(number).to(number) change(instance, method).from(number).to(number)
# proc.should <=> expect(&proc).to # proc.should <=> expect(&proc).to
expect { thing.approve! }.to change(thing, :status). expect { thing.approve! }.to change(thing, :status).
from(Status::AWAITING_APPROVAL). from(Status::AWAITING_APPROVAL).
to(Status::APPROVED) to(Status::APPROVED)
expect { thing.destroy }.to change(Thing, :count).by(-1) expect { thing.destroy }.to change(Thing, :count).by(-1)
```
### Mocking - basic ### Mocking - basic