$ git pull -f $ git clone https://github.com/chitsaou/test-workshop.git Then run $ bundle install --local This workshop is for beginners. If you know how to test Rails apps, this workshop is not for you.
describe "#slug" do let(:post) { Post.create(:title => "The answer to everything & the university = 42") } ! subject { post.slug } ! it "generates proper slug" do expect(subject).to eq("the-answer-to-everything-the-university-42") end end end
do subject { post "/posts/1/comments", :comment => comment_params } ! let(:comment_params) { {:author => "John Appleseed", :content => "Good article. I like it." } } ! context "a post that is published" do before { the_post.publish! } ! it "creates a new comment" do expect { subject }.to change { the_post.comments.count }.by(1) ennnnd request tests always tagged as request describe is usually written as HTTP request syntax subject is defined as "executing a http request" matching against database changes (will write to DB)
do let(:comment) { Fabricate(:comment) do post { Fabricate(:post, :title => "Awesome Article") } end } ! before { AdminNotificaitonMailer.new_comment(comment).deliver }
headers" do expect(mail.subject).to eq("[Blog] Awesome Article got a new comment.") expect(mail.to).to eq(["[email protected]"]) expect(mail.from).to eq(["[email protected]"]) end ! it "renders the body" do expect(mail.body.encoded).to match("Awesome Article got a new comment.") end end We can use 'subject' but it will be confused with 'subject of mail'.
not create a new comment" do expect { subject rescue nil # ignore any exception }.not_to change { the_post.comments.count } end end declare a shared example
create a new comment" do expect { subject rescue nil # ignore any exception }.not_to change { the_post.comments.count } end include it in a context or description