Everyday Rails - 2日目
P.32まで。特に難しいところもない。
わざと冗長に書いて、そこから簡潔にするという勉強方法の第一歩目、なので、面倒ではあった。
require 'rails_helper' describe Contact, type: :model do it "is valid with a firstname, lastname and email" do contact = Contact.new( firstname: 'Aaron', lastname: 'Sumner', email: 'tester@example.com' ) expect(contact).to be_valid end it "is invalid without a firstname" do contact = Contact.new(firstname: nil) contact.valid? expect(contact.errors[:firstname]).to include("can't be blank") end it "is invalid without a lastname" do contact = Contact.new(lastname: nil) contact.valid? expect(contact.errors[:lastname]).to include("can't be blank") end it "is invalid without an email address" do contact = Contact.new(email: nil) contact.valid? expect(contact.errors[:email]).to include("can't be blank") end it "is invalid with a duplicate email address" do Contact.create( firstname: 'Joe', lastname: 'Tester', email: 'tester@example.com' ) contact = Contact.create( firstname: 'Jane', lastname: 'Tester', email: 'tester@example.com' ) contact.valid? expect(contact.errors[:email]).to include("has already been taken") end it "returns a contact's full name as a string" do contact = Contact.new( firstname: 'John', lastname: 'Doe', email: 'johndoe@example.com' ) expect(contact.name).to eq "John Doe" end describe "filter last name by letters" do before do @smith = Contact.create( firstname: 'John', lastname: 'Smith', email: 'jsmith@example.com' ) @jones = Contact.create( firstname: 'Tim', lastname: 'Jones', email: 'tjones@example.com' ) @johnson = Contact.create( firstname: 'John', lastname: 'Johnson', email: 'jjohnson@example.com' ) end context "matching letters" do it "returns a sorted array of results that match" do expect(Contact.by_letter("J")).to eq [@johnson, @jones] end end context "non-matching letters" do it "omits results that do not match" do expect(Contact.by_letter("J")).not_to include @smith end end end end
今日の感想
Nitrous.IO、補完も効きそうだったが、その他のショートカットキーを知りたいな。
エディタ部分にそんな求めてはだめだとは思うけど、保存時に空白削除する機能か、もしくは空白文字を可視化して欲しいかも。
行末に余計な空白があるのが嫌なので。
しかし、ほんとすごい、Nitrous.IO。
勉強会など、初めての人のとっかかりとして、とても良いと思う。
個人的な印象として、Rubyは(エディタなど含め)開発環境構築が悩ましいと思ってる。
WindowsやWindows、Windowsの場合。
まずVirtualBox入れて、Vagrantで、とか、薦めにくかった。
Nitrous.IOなら、アカウント作って、さぁはじめよか、ってできるので。
いいね!